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
Program is to define a class as student: Program is to define a class as student and display the records specific depending upon the number class student { private:
Problem #1: plugging the memory leak. When you employ the "normal" new operator, for example Foo* p = new Foo(), the compiler generates some special code to manage the case while t
Describe Processing an array? The Single operations which involve complete arrays are not permitted in C language. therefore if a and b are similar arrays (for example same dim
Question: (a) Write down the class 'ListNode' to contain the following:- (i) variable data of type Object (ii) variable next of type ListNode (iii)
Aim: To implement a program to convert time in 24 hour format to 12 hour format. Code: #include #include #include class time24 {
Class Templates In addition to function templates, C++ also supports the method of class templates. By definition, a class template is a class definition that explains a fam
Define Bitwise Left Shift and Right Shift Operators: >? The bitwise shift operators shift their first operand right (>>) or left ( // Illustration of the bitwise right shi
C Program to check FACTORIAL main() { int i,j,m,fact,sum=0; clrscr(); printf("ENTER THE NO.: "); scanf("%d",&m);
can you help with the assignment, I don''t want to upload the assignment but want somebody to work with, do you do that?
Write a C++ program according to the following specifications 1. Display a brief description of the program. 2. Ask the user to specify the type of loading (end load, intermediate
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