Answer to Question #23649 in C++ for peeri akash

Question #23649
write a programme having a class named average whose job is to find average of 5 numbers entered by user.for storing those numbers use an array create two objects and call the member functions of the average class using those two objects individually
1
Expert's answer
2013-02-05T09:13:27-0500
#include <iostream>
using namespace std;
class average{
public:

double av;
int p;
//functions
average(){av=0;p=0;}
void addNumber(double num){
av=(p*av+num)/(p+1);
p++;
}
};

int main()
{
double num;
average a;
for (int i=0;i<5;i++){
cout<<"Enter numer: ";
cin>>num;
a.addNumber(num);
}
cout<<"avarege : "<<a.av<<endl;
system("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS