Professional Documents
Culture Documents
Galang Dwiwana Thabrani - Tugas Prak - Alpro
Galang Dwiwana Thabrani - Tugas Prak - Alpro
NIM : 1227050048
Diagram class
Class Shape
- -string color
+getcolor() ; string
Class Rectangle
-int width
-int height
+getArea();double
Syntax :
#include <iostream>
#include <string>
using namespace std;
class Shape{
private:
string color;
public:
void setColor(string color){
this->color=color;
}
string getColor(){
return color;
}
};
class Rectangle : public Shape{
private:
int width;
int height;
public:
// Konstruktor
Rectangle(string color , int width, int height) {
setColor(color);
this ->width= width;
this ->height = height;
}
double getArea(){
return width*height;
}
};
int main(){
Rectangle hoho("green", 81 , 3);
cout<<"color : "<<hoho.getColor()<<endl;
cout<<"area : "<<hoho.getArea()<<endl;
return 0;
}
Output