Advertisement Remove all ads

Implement a Class Average. Include a Constructor in It Which Will Accept Value of Three Variables from User. Include Two More Functions in It, One Functions Calculates Average and Other Prints It. - Computer Science 1

Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads

Implement a class average. Include a constructor in it which will accept value of three variables from user. Include two more functions in it, one functions calculates average and other prints it.

Advertisement Remove all ads

Solution

# include 
class average
{
   float a, b, c, avg;
   public : average(); //constructor
   void calculate();
   void print();
};

average::average()
{
  cout<<“Enter numbers”;
  cin>> a >> b >> c;
}

void average::calculate()
{
  avg = (a + b + c)/3;
}

void average::print()
{
  cout <<" The average of 3 nos is:" <<avg;
}

void main()
{
  average obj;
  obj calculate();
  obj print();
}
Concept: C++ Programming
  Is there an error in this question or solution?

APPEARS IN

Advertisement Remove all ads
Share
Notifications

View all notifications


      Forgot password?
View in app×