Write an interactive C++ program that prompts the user for ten (10) real numbers and calculate the sum, average, and prints the result. Hint: you may use an array to store the data.
Program requirements:
- The program must contain a class in which all the required private and public identifiers and the following functions must be defined.
- The program must contain three or more functions using parameters. These functions should read the data, calculate the sum, find the average, and print the results.
C++
#include "stdafx.h"
#include <iostream>
using namespace std;
// class with identifiers and functions
class real
{
private:
double n[10],s; // declarations
int i;
double avg;
public:
real()
{
s=0;
}
void read()
{
cout<<"Please Enter 10 Numbers"<<endl;
for (i=0;i<10;i++)
{
cout<<"You have Entered Number:";
cin>>n;
}
};
void print()
{
for (i=0;i<10;i++)
s=s+n;
avg=s/10;
cout<<"The Sum ="<<s<<endl;
cout<<"The Average ="<<avg<<endl;
}
};
int main()
{
real a;
a.read();
a.print();
system("PAUSE");
return 0;
}