This is tutorial for introduction to classes in c++. The program is given below that uses class to add two numbers. The program is extendable. Go enjoy the program. Lets begin……
Program to add two numbers using class in c++
//create a class
//declare int as private
//declare all functions as public
cout<<“Enter the two numbers”<<endl;
cout<<“Addition = “<<c;
//clear the screen.
//declare class add x
//call all functions
Enter the two numbers
Addition = 28
The program can be extended by using the concept in any program. Like for ex. you can create a same program for subtraction, multiplication,division,etc. Go ahead extend it……
- Remember this is a basic part of c++ which can be used in any program….
- Include ‘iostream.h’ and ‘conio.h’ files.
- Declare class.
- Add void main.
- Start program by first clearing the screen.
- Declare the x as your class name.
- Calculate the sum.
- Print the sum.
At the end
You learnt creating the C++ program for Introduction to classes in c++. So now enjoy the program.
Please comment on the post and share it.
And like it if you liked.