Last active
April 21, 2018 10:16
-
-
Save derohimat/edd7c632b3a6e4f8fc9b0f665fc399ab to your computer and use it in GitHub Desktop.
Operator C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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