Skip to content

Instantly share code, notes, and snippets.

@arisupriatna14
Created April 16, 2023 18:08
Show Gist options
  • Save arisupriatna14/80f83f41af5c1645040c8358a70688af to your computer and use it in GitHub Desktop.
Save arisupriatna14/80f83f41af5c1645040c8358a70688af to your computer and use it in GitHub Desktop.
#include <iostream>
class Shape {
protected:
double lebar;
double tinggi;
public:
Shape(double l, double t) {
lebar = l;
tinggi = t;
}
};
class Rectangle : public Shape {
public:
Rectangle(double l, double t) : Shape(l, t) {}
double hitungLuas() {
return lebar * tinggi;
}
};
int main() {
double lebar, tinggi;
std::cout << "Masukkan lebar rectangle: ";
std::cin >> lebar;
std::cout << "Masukkan tinggi rectangle: ";
std::cin >> tinggi;
Rectangle rect(lebar, tinggi);
std::cout << "Luas Rectangle adalah " << rect.hitungLuas() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment