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

Assignment Help:

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


Related Discussions:- C program to find area of rectangle

Sort war - Sorting algorithms, If quicksort is so quick, why bother with an...

If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? For that matter, why are there so many sorting algorithms? Your mission (sho

Need solution for simple beginner level c program, search words from a pass...

search words from a passage and return snippets in html format..

Assignmet, I have a assignment deadline is 11.11.2015 can I get help

I have a assignment deadline is 11.11.2015 can I get help

#Padovan string, #A Padovan string P(n) for a natural number n is defined a...

#A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of

#c++, There is a pebble merchant. He sells the pebbles, that are used for s...

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

Define the self-referential structures, Define the Self-Referential Structu...

Define the Self-Referential Structures? It is occasionally desirable to include within a structure one member that is a pointer to the parent structure type. Generally in terms

Palindrome, A palindrome is a string that reads the same from both the ends...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Write a program to add co-ordinates of the plane, Write a program to add co...

Write a program to add co-ordinates of the plane The class having x and y co-ordinates. Create three objects. Use a constructor to pass one pair of co-ordinates and a funct

Required audio expert in c# - create audio engine, Project Description: ...

Project Description: We want an EXPERT CODER to help us create an 'audio engine' in C#. We want to be able to specify an input of a wave/MP3 file, and have the engine manipul

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd