You are on page 1of 3

Nama : Galang Dwiwana Thabrani

NIM : 1227050048

Kelas : G- Pratikum Algoritma Pemrograman

Diagram class

Class Shape

- -string color

+getcolor() ; string

Class Rectangle

-int width

-int height

+ Rectangle(string color , 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

You might also like