Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
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
class box:public rect
double l,b,h;
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
void main()
rect r,*ptr;
box b;
clrscr();
ptr=&r;
ptr->getdata();
ptr->area();
ptr=&b;
((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
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
Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b
Rules of Inheritance: Private members are not inherited; the members can be accessed only within its class. It cannot be used through the object. Protected members are
Write the statements which are used to connect PHP with MySQL? Statements which can be used to connect PHP with MySQL is: $conn = mysql_connect('localhost'); echo $co
Add words in Dictionary: void Dictionary::add( Object& objectToAdd ) { if( !objectToAdd.isAssociation() ) ClassLib_error( __ENOTASSOC ); else
Webcam Driver static library or DLL required for Windows I want a .dll or .lib file using which i will take a snapshot from the webcam and it can't turn on the webcam LED while
Hello I''m new to programming, and I''m making now my 1st program. My question is how to put substr in textbox that question mark should be at the end of sentence? And 2nd question
Verifone pos offline mod vx670 Project Description: I want a programmer who will build custom application for Offline VX670 to collect and save info+pin 1) Press the am
Friend for Overloading Operators Sometimes friend functions cannot be avoided. For example with the operator overloading. Consider the following class that have data members to
Consider a group of n robots, numbered R2D1 through R2Dn, and m tasks, numbered 1 through m. Tasks can be different and robots are specialized, hence a given robot can only perform
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!
whatsapp: +91-977-207-8620
Phone: +91-977-207-8620
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd