C++ Program
to Find the Sum and Average of three numbers
C++
program to find the sum and average of three numbers is today we are going to
develop. We will design it in such way that it will ask the user to enter three
numbers. User will enter the numbers and program will calculate the sum of
these numbers and then later on it will display the average of these numbers.
So let’s start the journey.
Logic
The
basic logic is used we will create a class Test, declare three variables in
this class a, b, and c. then we will take the values from the user in the in()
function. Then we will calculate and display the sum and average of these three
numbers and display it on the screen using the out() function.
After
doing that, We will create an object of Test class in main function and using
this object call the in and out functions.
Finally
control will be transferred to the system using return 0; statement. That’s it.
Code
//
20 August 2019
//program
to find the sum and average of three numbers
#include<iostream>
using
namespace std;
class
Test{
private:
int a,b,c;
public:
void in()
{
cout<<"
Enter Three Numbers "<<endl;
cin>>a>>b>>c;
}
void out()
{
cout<<"
Sum = "<<a+b+c<<endl;
cout<<"
Average = "<<(a+b+c)/3;
}
};
int
main()
{
Test t;
t.in();
t.out();
return 0;
}
Output
Below
we have taken a screenshot of the first run of this code, it’s look fine.
Note : For obtaining the right output. Download and
Install the Dev C++ IDE and run this code on that, using it on other compiler
might require some changes to be made.
Thanks to be on this page. We are hoping you
are all fine with the code but if you are not fine, kindly ask us using our
contact us page or comment form we will be more excited about your cade than
you.
Post a Comment
Feel Free to Comment Us