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
Described multiple inheritance(virtual inheritance)? And explain its advantages and disadvantages? A: It is the procedure in which a child can be derived from more than one pare
what is a variable
Define Array of Structures? An Array of Structures is an assortment of the same data types which are declared as structures. It is useful to store large and different number of
Problem : Compiler Design - Limit the methods Rahul is a newbie to the programming and while learning the programming language he came to know the following rules: ·
Damjibhai and Shamjibhai are two jeweler friends. They decide to play a simple game. The game comprises of removing the jewels for polishing, turn by turn. Once a jewel is removed
Selection sort - C program: Write a program to define a selection sort. void main() { clrscr(); int a[100],ch,n; cout cin>>n; for (int i=0;i
Question 1 Describe the theory behind class templates and function templates along with relevant programming examples Question 2 With the help of suitable programming example
write a program to find area of curve y=f(x) between x and x=b,integrate between the limits a and b using c #include float start_point, /* GL
#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. The area under a curve between two points can
d) a "static destructor" is a static member function of the class which accepts one argument - a pointer to the object of that class to be cracked. It is probably utilized along wi
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: +1-415-670-9521
Phone: +1-415-670-9521
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd