Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <iostream>

using namespace std;

//Defining class Student


class Student
{
public:
void show()
{
cout<<"Hello I'm Student\n";
}
};

//Defining class Teacher


class Teacher
{
public:
void display()
{
cout<<"Hey I'm Teacher\n";
}
};

int main()
{

//Object of the class Student created


Student st;
st.show();

//Object of the class Teacher created


Teacher tc;
tc.display();

}
//This is c++ code which demonstrate multiple classess and objects for calculating area of circle and
triangle

#include <iostream>

using namespace std;

//Defining class for triangle


class triangle
{
float base,height,trianglearea;

public:

void gethightbase()
{
cout<<"Please enter the base and hight=>"<<endl;
cin>>base>>height;
}
void showtrianglearea()
{
trianglearea=0.5*base*height;

cout<<"Area of triangle is=> "<<trianglearea<<endl;


}
};

//defining class for circle


class circle
{
float r,circlearea;

public:

void getredious()
{
cout<<"Please enter the radious value =>"<<endl;
cin>>r;
}
void showcirclearea()
{
circlearea=3.14*r*r;

cout<<"Area of circle is=> "<<circlearea<<endl;


}
};

int main()
{

triangle t1;
t1.gethightbase();
t1.showtrianglearea();

circle c1;
c1.getredious();
c1.showcirclearea();

You might also like