12th Computer Science BCA CBSE JAC

Class and Object in C++ Programming Best concept

Class and Object in C++
Written by AIPS

There are different ways to make a program using class and object in C++. In this, we will learn how to use class object program in very easy way. We can make a program using class in four ways like.

  • One member function in the class definition
  • One member function outside the class definition
  • Multiple member functions inside the class definition
  • Multiple member functions outside the class definition

Q. Write a program to find sum of two numbers using class.

#include<iostream.h>
#include<conio.h>
class nips
{		
public:
int a,b,c;
void show()
{
a=10;
b=5;
c=a+b;
cout<<"Sum="<<c;
}
};

void main()
{
clrscr();
nips n1;
n1.show();
getch();
}

Output

Sum=15

About the author

AIPS

Leave a Comment