-
C++ - HELP on CLASS!!!
Hi all, I have a problem for my C++ program. Here is my the program everything is fine in the program but I need to implement average(), sum() , min() and max. It need to have the output like this. I no how the sum(), average() works but i'm having hard time figure out the Void addnumber(doulbe)part. Can some1 help please?
Average: 12.2997
Sum: 49.1989
Minimum: 10
Maximum: 14.9
//This is the program
#include <iostream>
using namespace std;
class Statistics
{
private:
double numbers[50];
int index;
public:
Statistics() : index(0)
{}
void addNumber(double);
double average();
double sum();
double max();
double min();
};
int main()
{
Statistics s;
s.addNumber(10.0);
s.addNumber(10.8989);
s.addNumber(13.4);
s.addNumber(14.9);
cout << "Average: " << s.average() << endl;
cout << "Sum: " << s.sum() << endl;
cout << "Minimum: " << s.min() << endl;
cout << "Maximum: " << s.max() << endl;
return(0);
}
-
You just store the numbers in the array
Code:
void addNumber ( double d ) {
numbers[index++] = d;
}