Skip to content

Instantly share code, notes, and snippets.

@andrinur13
Created March 18, 2019 04:05
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 andrinur13/428b4163ffd6829a8223c26a4903cc3a to your computer and use it in GitHub Desktop.
Save andrinur13/428b4163ffd6829a8223c26a4903cc3a to your computer and use it in GitHub Desktop.
postest alpro
#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