Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Program No.

Aim:- Write a Program in C++ to demonstrate class and object.


Program:-
#include<iostream.h>
#include<conio.h>
class rectangle
{
private:
int length,breadth;
public:
void area()
{
int a=length*breadth;
cout<<"area is "<< a << endl;
}
void perimeter()
{
int p=2*(length+breadth);
cout<<"perimeter is "<<p;
}
void setdimension(int m,int n)
{
length = m;

SHRI VASANTRAO NAIK MAHAVIDHYALAYA, DHARNI Page 1


Program No. 1

breadth = n;
}
};
void main()
{
clrscr();
rectangle a,b;
a.setdimension(4,7);
b.setdimension(3,3);
a.area();
b.perimeter();
getch();
}
---------------------------------------Output-----------------------------------
area is 28
perimeter is 12

SHRI VASANTRAO NAIK MAHAVIDHYALAYA, DHARNI Page 2

You might also like