Create a base class called 'SHAPE' having
-
two
data members of type double
-
member
function get-data( ) to initialize base class data members
-
pure virtual member function display-area( ) to
compute and display the area of
the geometrical
object.
Derive two
specific classes 'TRIANGLE' and 'RECTANGLE' from the base class. Using these
three classes design a program that will accept dimension of a triangle / rectangle
interactively and display the area.
#include<iostream.h>
#include<conio.h>
class shape
{
protected:double x, y;
public:void getdata(double
a, double b)
{
x=a;
y=b;
}
virtual void display_area()=0;
};
class triangle:public
shape
{
double triangle_area;
void display_area()
{
triangle_area=(1*x*y)/2;
cout<<"area
of triangle is:"<<triangle_area<<endl;
}
};
class rectangle:public
shape
{
double rectangle_area;
void display_area()
{
rectangle_area=x*y;
cout<<"area
of rectangle is:"<<rectangle_area;
}
};
int main()
{
clrscr(); shape *p; triangle t; rectangle r;
p=&t; p->getdata(10,30);
p->display_area(); p=&r; p->getdata(20,30); p->display_area(); getch();
return 0;
}
*******************************OUTPUT*******************************
area of triangle is:150
area of rectangle is:600
The innovative thinking of you in this blog. This blog makes me very useful to learn.
ReplyDeleteclinical sas training in chennai
clinical sas training
clinical sas Training in Velachery
SAS Training in Chennai
SAS Course in Chennai
Placement Training in Chennai
soft skills training in chennai
core java training in chennai
ReplyDeleteSuperb ! Your blog is incredible. I am impressed with it. Thanks for sharing this content under this topic.
Seo Training in Bangalore
Best Seo Training in Bangalore
Data Analytics Courses in Bangalore
Data Science Courses in Bangalore
Digital Marketing Courses in Bangalore
German Classes in Bangalore
Python Training in Bangalore
Selenium Training in Bangalore
Thanks for the interesting blog that you have implemented here. Very helpful and innovative. Waiting for your next upcoming article.
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
Good blog!!! It is more impressive... thanks for sharing with us...
ReplyDeleteDigital Marketing Training in Chennai | Certification | SEO Training Course | Digital Marketing Training in Bangalore | Certification | SEO Training Course | Digital Marketing Training in Hyderabad | Certification | SEO Training Course | Digital Marketing Training in Coimbatore | Certification | SEO Training Course | Digital Marketing Online Training | Certification | SEO Online Training Course