What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

Share Our Page Contents

C++ Lab Codings

Technicalsymposium.com-Receive Latest Updates through Facebook-Like us Below

C++ Program for virtual function to find area perimeter of the rectangle.

#include<iostream.h>
#include<conio.h>
class Rectangle
{
public :
float length,breadth;
Rectangle(){}
Rectangle(float t,float t1)
{
length=t;
breadth=t1;
}
void get()
{
cout<<"\n\n\t\tEnter the Length of the Rectangle :";
cin>>length;
cout<<"\n\n\t\tEnter the Breadth of the Rectangle : ";
cin>>breadth;
}
virtual void calculate()
{ /* fn. to calculate perimeter*/
float p=2.0;
float k=length+breadth;
p=p*k;
cout<<"\n\n\tPERIMETER OF THE RECTANGLE : "<<p;
}
};
class Area : public Rectangle
{
public:
void calculate()
{
/*fn. to return area of the rectangle*/
cout<<"\n\n\tAREA OF THE RECTANGLE : "<<length*breadth;
}
};
void main()
{
clrscr();
cout<<"\n\n\tPROGRAM TO CALCULATE AREA & PERIMETER OF THE RECTANGLE\n\n";
Area area;//derived
Rectangle *ptr;//base
ptr=&area;
ptr->get();
ptr->calculate();
Rectangle rect(ptr->length,ptr->breadth);
ptr=▭
ptr->calculate();
getch();
}



















Free Projects
Java Projects
Engineering Projects
Science Projects
C/C++/.NET/Oracle Projects
Free Semester Study Materials
Engineering Lecture Notes
IIT Lecture Notes
MIT Lecture Notes
Free Engineering E-Books


















Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com