C program to find area of rectangle, C/C++ Programming

Aim: To implement a program to find area of rectangle, surface area of box and volume of box using virtual functions.

Code:                      

class rect

{

            double l,b;

            public:

                        virtual void getdata();

                        virtual void area();

};

void rect::getdata()

{

            cout<<"Enter the length and breadth of rectangle:\n";

            cin>>l>>b;

}

void rect::area()

{

            cout<<"Area of rectangle = "<

}

class box:public rect

{

            double l,b,h;

            public:

                        void getdata();

                        void area();

                        void volume();

};

void box::getdata()

{

            cout<<"\nEnter the length, breadth and height of the box:\n";

            cin>>l>>b>>h;

}

void box::area()

{

            cout<<"Surface area of the box = "<<2*(l*b+b*h+l*h)<<" sq. units\n";

}

void box::volume()

{

            cout<<"Volume of the box = "<

}

void main()

{

            rect r,*ptr;

            box b;

            clrscr();

            ptr=&r;

            ptr->getdata();

            ptr->area();

            ptr=&b;

            ptr->getdata();

            ptr->area();

            ((box *)ptr)->volume();

            getch();

}

 

Output:

Enter the length and breadth of rectangle:

10

15

Area of rectangle = 150 sq. units

 

Enter the length, breadth and height of the box:

5

12

6

Surface area of the box = 324 sq. units

Volume of the box = 360 cu. units

Posted Date: 9/29/2012 4:15:01 AM | Location : United States







Related Discussions:- C program to find area of rectangle, Assignment Help, Ask Question on C program to find area of rectangle, Get Answer, Expert's Help, C program to find area of rectangle Discussions

Write discussion on C program to find area of rectangle
Your posts are moderated
Related Questions
C program to check display days and month main() {           int months, days;           clrscr();           printf("ENTER DAYS: ");           scanf("%d", &days);

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send


#quesdifferentiate betweenrelocatable and self relocating program with exampletion..

how to make the coding

A: Depends. Might be "zero" Objects which are thrown must have a publicly accessible copy-constructor. The compiler is permitted to generate code which copies the thrown object

Define the Recursion Function in C? In C, it is potential for the function to call themselves a function is describing 'recursive' if a statement within the body of a function

In the final project assignment you are asked to develop an OOP C++ class hierarchy for derivative pricing, using the binomial tree and Black-Scholes option pricing methods. You wi

Temperature Conversions. Problems 28 through30generate temperature-conversion tables. Use the following equations that give relationships between temperatures in degrees Fahrenheit

I Want a answer for solving the big M method in the topic of simplex method...