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.
#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;
}
Comments
Thanks so much
Leave a comment