Professional Documents
Culture Documents
Program no:01
#include <iostream>
#include <string>
class myinfo
private:
int names;
int fathername;
public:
int marks=90;
char grade='A';
};
int main()
myinfo Ash;
Ash.marks;
Ash.grade;
cout<<"MY grade"<<Ash.grade<<endl;
cout<<"MY marks"<<Ash.marks<<endl;
return 0;
:Output:
Program no:02
#include<iostream>
class Room
public:
double height;
double breath;
double length;
double calculatearea()
double calculatevolume()
};
int main()
Room room1;
room1.length = 98;
room1.breath = 67;
room1.height = 23;
cout<<"Area of a room"<<room1.calculatearea()<<endl;
cout<<"Area of a room"<<room1.calculatevolume()<<endl;
return 0;
:output:
PUBLIC,PRIVATE AND PROTECTED
#include <iostream>
class base
private:
int x;
protected:
int y;
public:
int z;
base() //constructor to initialize data members
x = 1;
y = 2;
z = 3;
};
public:
void showdata()
};
int main()
a.showdata();
return 0;
} //end of program
Output
Program no:02
#include <iostream>
using namespace std;
class A
{
private:
int a, b;
public:
void getdata(int x, int y)
{
a = x;
b = y;
}
void showdata()
{
cout << "The sum of two private integer data members are =
" << a + b << endl;
cout << "The product of two private integer data members
are = " << a * b << endl;
}
};
int main()
{
A obj;
obj.getdata(4, 5);
obj.showdata();
return (0);
}
Output