Sunday 26 July 2015

  • Sunday, July 26, 2015

C++ programming code

#include <iostream>
 
using namespace std;
 
int main()
{
   int a, b, c;
 
   cout << "Enter two numbers to add\n";
   cin >> a >> b;
 
   c = a + b;
   cout <<"Sum of entered numbers = " << c << endl;
 
   return 0;
}

C++ addition program using class

#include <iostream>
 
using namespace std;
 
class Mathematics {
  int x, y;
 
public:
  void input() {
    cout << "Input two inetegers\n";
    cin >> x >> y;
  }
 
  void add() {
    cout << "Result = " << x + y;
  }
 
};
 
int main()
{
   Mathematics m; // Creating object of class
 
   m.input();
   m.add();
 
   return 0;
}
We create Mathematics class with two functions input() and add(). First function is used to get two integers and add() performs addition and display the result. Similarly you can add more functions such as subtract, multiply, divide etc.
Related Posts Plugin for WordPress, Blogger...

Vacancy

RBI has announced the recruitment for 134 GRADE B OFFICERS.
 The examination will be in two phases.
 The detailed advertisement will be published on 5th October.

Popular Posts