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.


Expert's answer

#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();
	
}

LATEST TUTORIALS
APPROVED BY CLIENTS