Created
May 11, 2018 06:23
-
-
Save muzafakar/6c7b165f70dcc2e7d21bb4053391d760 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Shape{ //base class || class abstract | |
protected: | |
int width; | |
int heigh; | |
public: | |
Shape(int heigh, int width){ //constructor | |
this->width = width; | |
this->heigh = heigh; | |
} | |
virtual int area() = 0; //pure virtual function | |
}; | |
class Triangle : public Shape{ //derived class | |
private: | |
int alas; | |
public: | |
Triangle(int heigh, int alas):Shape(heigh, 0){ //member initializer | |
this->alas = alas; | |
this->heigh = heigh; | |
} | |
//override | |
int area(){ | |
cout << "ini class tr" << endl; | |
return (alas * heigh) / 2; | |
} | |
}; | |
class Kerucut : public Shape{ | |
private: | |
int r; | |
public: | |
Kerucut(int heigh, int r):Shape(heigh, 0){ | |
this->r = r; | |
this->heigh = heigh; | |
} | |
//override | |
int area(){ | |
cout << "ini class kr" << endl; | |
return heigh * r /2; | |
} | |
}; | |
int main(){ | |
Shape *tr = new Triangle(3, 8); | |
cout << tr->area(); | |
delete tr; | |
} |
Author
muzafakar
commented
May 11, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment