#include <iostream.h> #include <conio.h> class Perkalian { friend ostream& operator<<(ostream&, const Perkalian&); friend istream& operator>>(istream&, Perkalian&); public: Perkalian(); void hitung_perkaliannya(){ hasil = (a * b); } private: int a,b; int hasil; }; Perkalian::Perkalian() { cout << "Program mengalikan 2 integer\n"; cout << "Selamat berkarya\n"; } istream& operator>>(istream& in, Perkalian& masukan) { cout << "Masukkan nilai a : "; in >> masukan.a; cout << "Masukkan nilai b : "; in >> masukan.b; return in; } ostream& operator<<(ostream& out, const Perkalian& keluaran) { out << "Nilai a : " << keluaran.a << endl; out << "Nilai b : " << keluaran.b << endl; out << "Hasil kali integer di atas : " << keluaran.hasil << endl; return out; } main() { Perkalian X; cin >> X; X.hitung_perkaliannya(); cout << X; getch(); return 0; }
Search Engine Submission - AddMe
0 Response for the "Program Mengalikan 2 bilangan Interger Menggunakan overloading"
Post a Comment