Answer to Question #349745 in C++ for abraham

Question #349745

Write a program that calculates the area of a triangle.


Base class name=shape and variables are base,height(protected)


Derived class name=Triangle and member function that returns the formula of triangle.




1
Expert's answer
2022-06-10T09:24:49-0400
#include <iostream>
using namespace std;

class shape {
protected:
	int base, height;
};

class Triangle : shape {
public:
	Triangle(int base, int height){
	    this->base = base;
	    this->height = height;
	}
	int Area(){
		return (this->base*this->height)/2;
	}
};


int main() {
	Triangle abc(5, 10);
	cout << abc.Area();
	return 0;
}

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

Alabi Oluwasegun Abraham
10.06.22, 16:26

Thanks so much

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS