C++ Programming Blog

 
 
 

Image

#include <iostream.h>
#include <conio.h>

class shape
{
 protected:
       double x,y;
  public:
       virtual void get_data()=0;
       virtual void display_area()=0;
};

class triangle : public shape
{
   public:
    void get_data(void)
    {
       cout<<\"\\n\\n=====Data Entry for Triangle=====\\n\\n\";
       cout<<\"Enter base and height respectively : \";
       cin>>x>>y;
    }
    void display_area(void)
    {
       cout<<\"\\n\\n=====Area of Triangle=====\\n\\n\";
       double aot;
       aot = 0.5 * x * y;
       cout<<\"Area of Triangle is \"<<aot;
    }
};

class rectangle : public shape
{
   public:
    void get_data(void)
    {
       cout<<\"\\n\\n=====Data Entry for Rectangle=====\\n\\n\";
       cout<<\"Enter length of two sides  : \";
       cin>>x>>y;
    }
    void display_area(void)
    {
       cout<<\"\\n\\n=====Area of rectangle=====\\n\\n\";
       double aor;
       aor = x * y;
       cout<<\"Area of Rectangle is \"<<aor;
    }
};


void main()
{
clrscr();
triangle tri;
rectangle rect;
shape *list[2];
list[0]=&tri;
list[1]=&rect;

int choice;
while(1)
{
clrscr();
  cout<<\"\\n=====MEASURES OF DIFFERENT SHAPE=====\\n\";
  cout<<\"\\nChoose your choice\\n\";
  cout<<\"1) Area of Triangle\\n\";
  cout<<\"2) Area of Rectangle\\n\";
  cout<<\"3) Exit\\n\";
  cout<<\"Enter your choice:-\";
  cin>>choice;
  switch(choice)
  {
     case 1 : list[0]->get_data();
          list[0]->display_area();
          getch();
          break;
     case 2 : list[1]->get_data();
          list[1]->display_area();
          getch();
          break;
     case 3 : goto end;
     default: cout<<\"\\n\\nInvalid choice\\nTry again\\n\";
          getch();
  }
}
end:
}

    Related Post:
  1. Program to draw an Elliptical Arc using Trigonometric Method

  2. Program to illustrate an example of Polymorphism

  3. To parse a string using Recursive-Descent parser

  4. Program to estimate the Integral value of the function at the given points from the given data using Romberg Method

  5. Program to estimate the Integral value of the function at the given points from the given data using Simpsons 1/3 Rule

  6. Program to perform array operations like append, insert, delete, edit, display and search and element

  7. Program that reads a number and displays it with its digits in reverse order using do-while loop

  8. Program for Fahrenheit to Celcius using Class

  9. Program to estimate the Integral value of a given function using Gussian Quadrature Rule

  10. Program to illustrate the Bubble Sort

  11. Program to estimate the Integral value of the function at the given points from the given data using Trapezoidal Rule

  12. Program of simple windows & buttons

  13. Library System

  14. Program to illustrate the use of friend classes

  15. Program to estimate the value of Fourth Derivative of the function at the given points from the given data using Central Difference Formula of order 4

  16. Program for electricity board charges calculation

  17. Program that prints all the even numbers b/w 0 to 50 ( using while, do-while and for loop )

  18. Program that displays result of students by compact if-else notation

  19. Program that differentiate b/w the variables of the storage class Auto and Static along with global variables

  20. Program for converting string to class object

 
 
Didn't find what you were looking for? Find more on Program that calculates area of triangle and rectangle using inheritance