Thread: C++ - HELP on CLASS!!!

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    2

    Arrow 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);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You just store the numbers in the array

    Code:
    void addNumber ( double d ) {
        numbers[index++] = d;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 11:36 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM