Computer Science, asked by crystal9504, 8 months ago

Print the average of three numbers entered by the user by creating a class named 'Average'having a function to calculate and print the average without creating any object of theAverage class.

Answers

Answered by sourasghotekar123
0

The code below creates a class named 'Average' with a function to calculate and print the average without creating any objects of the 'Average' class-

#include <iostream>

using namespace std;

class Average{

   public:

   static float calcAverate(float x, float y, float z){

       return (x + y + z) / 3;

   }

};

int main(){

   cout<<"Enter three numbers: ";

   float x, y,z;

   cin>>x;

   cin>>y;

   cin>>z;

   cout<<"The average is: "<<Average::calcAverate(x,y,z)<<endl;

   return 0;

}

#SPJ2

Answered by anusha195sl
0

Answer:

The correct answer is finding the Average Class.

Explanation:

Given that:

Print the average of three numbers entered by the user by creating a class named 'Average' having a function.

To find:

calculate and print the average without creating any object of the Average class =?

#include <iostream>

using namespace std;

class Average{

  public:

  static float calcAverage(float x, float y, float z){

      return (x + y + z) / 3;

  }

};

int main(){

  cout<<"Enter three numbers: ";

  float x, y,z;

  cin>>x;

  cin>>y;

  cin>>z;

  cout<<"The average is: "<<Average::calcAverage(x,y,z)<<endl;

  return 0;

}

Output:

Enter three Numbers: 123

#SPJ3

Similar questions