Write a cpp program to calculate addition of two numbers using class and object?

#include<iostream.h>
#include<conio.h>
class sum
{
 private:
  int a, b;
 public:
  void getData(int x, int y)
   { a=x; b=y; }
  void fun()
   {
    cout<<"Sum of two number is: "<<a+b;
   }
}
void main()
{
 clrscr();
 sum obj;
 obj.getData(2,3);
 obj.fun();
 getch();
}

Ourput:


Comments

Popular posts from this blog

Larch Soft Pvt. Ltd. - Best Website & Hosting Provider