Created
March 18, 2019 04:05
-
-
Save andrinur13/428b4163ffd6829a8223c26a4903cc3a to your computer and use it in GitHub Desktop.
postest alpro
This file contains 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> | |
using namespace std; | |
class Tambah { | |
private: | |
float a, b, x, y, hasil; | |
public: | |
friend ostream & operator << (ostream &out, const Tambah &t); | |
friend istream & operator >> (istream &in, Tambah &t); | |
}; | |
ostream & operator << (ostream &out, const Tambah &t) | |
{ | |
out << t.y << "e" << t.x << endl; | |
return out; | |
} | |
istream & operator >> (istream &in, Tambah &t) | |
{ | |
cout << "Masukkan angka pertama : "; | |
in >> t.a; | |
cout << "Masukkan angka kedua : "; | |
in >> t.b; | |
t.hasil = t.a + t.b; | |
if(t.hasil >= 1000) { | |
t.x = 3; | |
t.y = t.hasil / 1000; | |
} else if(t.hasil > 100) { | |
t.x = 2; | |
t.y = t.hasil / 100; | |
} else if(t.hasil > 10) { | |
t.x = 1; | |
t.y = t.hasil / 10; | |
} else if(t.hasil > 1) { | |
t.x = 0; | |
t.y = t.hasil / 1; | |
} | |
return in; | |
} | |
int main() | |
{ | |
Tambah t; | |
cin >> t; | |
cout << "Hasil : "; | |
cout << t; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment