Sunday, 22 July 2018

C++ Program Classes Simple Example

Basically These are the Simple Example of  Classes in C++ Program

EXAMPLE:1

#include<iostream>
#include<conio.h>
using namespace std;
class myclass
{
private:
int a,b,c;
public:
void myfun()

{

a=10;
b=20;
c=a+b;
cout<<"Result is:"<<c;
}
};
int main()
{
        myclass obj;
obj.myfun();
getch();
return 0;

}
OUTPUT:-

Result is:30

EXAMPLE:-2

#include<iostream>
#include<conio.h>
using namespace std;
class myclass
{
public:
void myfun(int a,int b)
{
int c;
c=a+b;
cout<<"Result is:"<<c;
}
};
int main()
{
myclass obj;
obj.myfun(100,50);
getch();
return 0;
}
OUTPUT:-

Result is:150

No comments:

Post a Comment

Thanks for comment