Skip to content

Instantly share code, notes, and snippets.

@muzafakar
Created May 11, 2018 06:23
Show Gist options
  • Save muzafakar/6c7b165f70dcc2e7d21bb4053391d760 to your computer and use it in GitHub Desktop.
Save muzafakar/6c7b165f70dcc2e7d21bb4053391d760 to your computer and use it in GitHub Desktop.
#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;
}
@muzafakar
Copy link
Author

muzafakar commented May 11, 2018

berbagiIlmu = new ShodaqohJariahGenerator(ikhlas);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment