Monday, August 31, 2015

Addition of Five Numbers Using Class in C++

In this article I would like to share with you how to declare and use a class in C++. This program I called addition of three numbers using a class in C++. It will ask the user to enter five numbers and then it will compute and display the total sum of the three numbers.

If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

#include <iostream>

 using namespace std;

 class add {
     public:
     int a,b,c,d,e;

     int solve(int a,int b,int c, int d, int e)
      {
          return(a+b+c+d+e);
      }
 };


 main() {

      add values;

     cout << "\n\t Addition of Numbers ";
     cout << "\n\n";
     cout << "Enter five numbers : ";
     cin >> values.a >> values.b
         >> values.c >> values.d
         >> values.e;
     cout << "\n\n";
     cout << "The total sum "
          << values.solve(values.a,values.b,
                   values.c,values.d,
                   values.e) << ".";
     cout << "\n\n";
     system("pause");
 }






No comments:

Post a Comment