Algoritma :
Deskripsi
a,b : integer
hasil : integer
Deklarasi
hasil <= a * b
write(hasil)
Berikut programnya :
#include <iostream>
#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<<"Masukan nilai a : ";
in>>masukan.a;
cout<<"Masukan 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;
}
Explanation:
Program over the program to find the product of two integers. Which uses variables a, b and results. The program will perform the multiplication with a predetermined formula. With input from the keyboard and produce output that has been made according to the program.
Program over the program to find the product of two integers. Which uses variables a, b and results. The program will perform the multiplication with a predetermined formula. With input from the keyboard and produce output that has been made according to the program.
0 komentar:
Posting Komentar