Answer to Question #247967 in C++ for Ravi

Question #247967

Modify the program no. 1 as follows:


Derive a class named as BOX from RECTANGLE class. Take necessary

data & member functions for this box class to calculate the volume of the

box. All the data members are initialized through the constructors. Show the

result by accessing the area method of circle and rectangle and the volume

method of box class through the objects of box class.


1
Expert's answer
2021-10-07T03:04:26-0400
#include<iostream>
using namespace std;
class  RECTANGLE{
	private:
		double wid, len;
	public:
		RECTANGLE(){
			
		}
		 RECTANGLE(double l, double w){
			len= l;
			wid = w;
		}
		void setData(double l, double w){
			len = l;
			wid = w;
		}
		double getWid(){
			return wid;
		}
		
		double getLen(){
			return len;
		}
		double area(){
		
		return getLen() * getWid();
		
		}
		
		
};


class BOX: RECTANGLE{
	private:
	double	depth;
	public:
		BOX(double l, double w, double d){
			setData(l,  w);
			depth = d;
		}
		
		void volume(){
		
		
			cout<<"Volume is: "<<area() * depth<<endl;
		}
	
};


int main(){
	




	double len = 5;
		double wid = 5;
			double d = 6.90;
	BOX box(len,wid,d);
	box.volume();
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS