Program to print sum of two numbers using class in C++.

Program to print sum of two numbers using class in C++.

 

 

In this Artical we learn how to Add two numbers by using class in c++.This is simple program and easy to understand.

 

 

Let’s open turbo c/c++ and write the following code.

 

 

Code:

 

 

#include<iostream.h>

#include<conio.h>

class bca

{

private :

long int a,b,c;

public:

void input();

void output();

};

void bca :: input()

{

cout<<”enter first number: “;

cin<<a;

cout<<”enter second number: “;

cin<<b;

c=a+b;

}

void bca :: output()

{

cout<<”sum:= “<<c;

}

void main()

{

clrscr();

bca s;

s.input();

s.output();

getch();

}

 

 

 

Now, Run the program and see output:

 

 

Output:

 

 

output

 

 

Happy coding.

 

 

Tags: , , , ,

Comments are closed.