#include<iostream.h>
#include<conio.h>
class shape
{
public:
virtual void read()=0;
virtual void show()=0;
};
class circle:public shape
{
private:
float r;
public:
void read()
{
cout<<"\n Enter Radius: ";
cin>>r;
}
void show()
{
cout<<"\n Area of Circle: "<<3.14*r*r;
}
};
class rectangle:public shape
{
private:
int b,l;
public:
void read()
{
cout<<"\n Enter Length: ";
cin>>l;
cout<<"\n Enter Bredth: ";
cin>>b;
}
void show()
{
cout<<"\n Area of Rectangle: "<<b*l;
}
};
class triangle:public shape
{
private:
int b,h;
public:
void read()
{
cout<<"\n Enter Base: ";
cin>>b;
cout<<"\n Enter Height: ";
cin>>h;
}
void show()
{
cout<<"\n Area of Triangle: "<<b*h*0.5;
}
};
void main()
{
clrscr();
shape *s[20];
int count=0,choice,i,menu();
choice=menu();
while(choice!=4)
{
switch(choice)
{
case 1:
s[count]=new circle;
s[count]->read();
count++;
break;
case 2:
s[count]=new rectangle;
s[count]->read();
count++;
break;
case 3:
s[count]=new triangle;
s[count]->read();
count++;
break;
default:
cout<<"\n Invalid Choice\n";
break;
}
choice=menu();
}
for(i=0;i<count;i++)
{
s[i]->show();
}
}
int menu()
{
int ch;
cout<<"\n 1: Circle";
cout<<"\n 2: Rectangle";
cout<<"\n 3: Triangle";
cout<<"\n 4: Exit";
cout<<"\n Enter The Choice: ";
cin>>ch;
return ch;
getch();
}
#include<conio.h>
class shape
{
public:
virtual void read()=0;
virtual void show()=0;
};
class circle:public shape
{
private:
float r;
public:
void read()
{
cout<<"\n Enter Radius: ";
cin>>r;
}
void show()
{
cout<<"\n Area of Circle: "<<3.14*r*r;
}
};
class rectangle:public shape
{
private:
int b,l;
public:
void read()
{
cout<<"\n Enter Length: ";
cin>>l;
cout<<"\n Enter Bredth: ";
cin>>b;
}
void show()
{
cout<<"\n Area of Rectangle: "<<b*l;
}
};
class triangle:public shape
{
private:
int b,h;
public:
void read()
{
cout<<"\n Enter Base: ";
cin>>b;
cout<<"\n Enter Height: ";
cin>>h;
}
void show()
{
cout<<"\n Area of Triangle: "<<b*h*0.5;
}
};
void main()
{
clrscr();
shape *s[20];
int count=0,choice,i,menu();
choice=menu();
while(choice!=4)
{
switch(choice)
{
case 1:
s[count]=new circle;
s[count]->read();
count++;
break;
case 2:
s[count]=new rectangle;
s[count]->read();
count++;
break;
case 3:
s[count]=new triangle;
s[count]->read();
count++;
break;
default:
cout<<"\n Invalid Choice\n";
break;
}
choice=menu();
}
for(i=0;i<count;i++)
{
s[i]->show();
}
}
int menu()
{
int ch;
cout<<"\n 1: Circle";
cout<<"\n 2: Rectangle";
cout<<"\n 3: Triangle";
cout<<"\n 4: Exit";
cout<<"\n Enter The Choice: ";
cin>>ch;
return ch;
getch();
}
No comments:
Post a Comment