63 815
Assignments Done
99,5%
Successfully Done
In August 2018

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
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions