about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

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

Previous Post Next Post

Recents