Answer to Question #264434 in C++ for Sami

Question #264434

Question 1: Write a program that defines an outline class with a constructor that gives value to breadth and altitude. The define three sub-classes square, triangle, and rectangle, that calculate the area of an outline (). In the main, define three variables a square, a triangle and a rectangle and then call the outline () function in these three variables.


1
Expert's answer
2021-11-11T07:31:20-0500


#include<iostream>
using namespace std;
class outline {
	private: 
	
	public:
		double breadth, altitude;
		outline(){
			
		}
		
		outline(double b){
				breadth = b;
		}
		outline(double b, double a){
			breadth = b;
			altitude = a;
		}
		
		double getB(){
			return breadth;
		}
		
		double getA(){
			return altitude;
		}
		
		void set_data (double a, double b)
	{
		breadth = a;
		altitude = b;
	}
};


class square: public outline{
	public:
		
		
		double area(){
			return breadth * breadth;
		}
};


class triangle: public outline{
	public:
	
		double area(){
			return altitude  * breadth * 0.5;
		}
};




class rectangle: public outline{
	public:
		
		
		double area(){
			return altitude  * breadth;
		}
};




int main(){
	
	cout<<"Enter the breadth:\n";
	double b;
	cin>>b;
	cout<<"Enter the altitude:\n";
	double a;
	cin>>a;
	
	triangle t;
	t.set_data(b,a);
	
	rectangle r;
	r.set_data(b,a);
	square s;
	s.set_data(b,a);
	cout<<t.area()<<endl;
	cout<<r.area()<<endl;
	cout<<s.area()<<endl;
	
}

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

Sami
11.11.21, 14:54

Thanks a lot , helps a lot

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS