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
Various ways of initializing the Arrays. - The for loop initializes 10 elements with the value of their index. void main() { const in
#questiStarting with a blank solution, write a program to prompt the user for an employee number, hourly rate and hours worked. Compute and display the employee number, gross weekl
Program to find a Greatest String: C - Program: Write a program find largest string by c program. int main( int argc, char *argv[] ) { if( argc {
Define register with bit fields? We could define register simply with bit fields: struct DISK_REGISTER { unsigned ready:1; unsigned error_occured:1; unsigned disk_spinni
Where are longjmp and setjmp used in C++? -Setjmp and longjmp must not be used in C++. - Longjmp jumps out of the function without unwinding stack. This means that local obj
padovan string
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 concate
A string is said to be "Beautiful"€, if it contains only non repetitive alphabets
Lennie McPherson, proprietor of Lennie''''s Bail Bonds, needs to calculate the amount due for setting the bail. Lennie requires something of value as collateral, and his fee is 10%
write a static method with one integer parameter, x that returns the value of the polynomial 3x(2)- 7x + 2
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