The conversion from meters to centimeters and inches

#include <iostream.h>
#include <conio.h>
class Konversi {
friend ostream& operator<<(ostream&, const Konversi&);
friend istream& operator>>(istream&, Konversi&);
public:</div>
Konversi();
void konversi_ke_cm(){ cm = (m * 100); }
void konversi_ke_inci(){ inci = cm/2.54; }
private:
float m;
float cm, inci;
};
Konversi::Konversi() {
cout << “Program konversi m ke cm dan inci\n”;
cout << “Selamat berkarya\n”;
}
istream& operator>>(istream& in, Konversi& masukan) {
cout << “Masukkan nilai m : “;
in >> masukan.m;
masukan.konversi_ke_cm();
masukan.konversi_ke_inci();
return in;
}
ostream& operator<<(ostream& out, const Konversi& keluaran) {
out << “Nilai m : ” << keluaran.m << endl;
out << keluaran.m << ” m = ” << keluaran.cm << ” cm ” << endl;
out << keluaran.m << ” m = ” << keluaran.inci << ” inci ” << endl;
return out;
}
main() {
Konversi X;
cin >> X;
cout << X;
getch();
return 0;
}

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s