Skip to content

Instantly share code, notes, and snippets.

@derohimat
Last active April 21, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derohimat/edd7c632b3a6e4f8fc9b0f665fc399ab to your computer and use it in GitHub Desktop.
Save derohimat/edd7c632b3a6e4f8fc9b0f665fc399ab to your computer and use it in GitHub Desktop.
Operator C++
#include <iostream>
class Balok {
private:
int sisi;
public:
Balok() {
sisi = 0;
}
Balok(int s) {
sisi = s;
}
bool operator ==(const Balok& b2) {
if (this->sisi == b2.sisi) {
return false;
}
return true;
}
};
int main() {
Balok b1 = Balok(4);
Balok b2 = Balok(4);
Balok b3 = Balok(5);
Balok b4 = Balok(4);
Balok b5 = Balok(4);
Balok b6 = Balok(4);
Balok baloks [6] = {b1,b2,b3,b4,b5,b6};
bool success = false;
for (int i = 0; i < sizeof(baloks); i++) {
Balok item = baloks[i];
for (int j = 0; j < sizeof(baloks); j++) {
if (item == baloks[j]) {
success = true;
} else {
success = false;
break;
}
}
}
if (!success) {
std::cout << "Balok tidak bisa dibuat" << std::endl;
} else {
std::cout << "Balok bisa dibuat" << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment