Close
Close

Objects,classes and methods

   Achez

Using objects, classes and methods, write a program to calculate the average height of all the students of a class. The number of students and their heights are entered by the user


Answers

  •    jaskaran019

    #include using namespace std;

    class Average

    {

    public:

    int students;

    void input_students()

    {

    cout << "Enter the total number of students = ";

    cin >> students;

    }

    int* height=new int[students];

    void input_height()

    {

    for (int i = 0; i < students; i++)

    { cout << "Enter the height of " << i + 1 << " student "; cin >> height[i];

    }

    }

    void average_of_heights()

    {

    cout << "The average of the heights of the students is = " << (height[0] + height[1] + height[2] + height[3] + height[4] + height[5] + height[6] + height[7] + height[8] + height[9]) / 10 << endl;

    }

    };

    int main()

    {

    Average a1;

    a1.input_students();

    a1.input_height();

    a1.average_of_heights();

    return 0;

    }



Write your answer