Operloading Pangkat

#include <iostream>
#include <string>

using namespace std;

class pangkat{
friend ostream& operator<<(ostream&, pangkat&);
friend istream& operator>>(istream&, pangkat&);
public:
pangkat(){};
void hasil();
private:
float x,c;
int y,i;
};
istream& operator>>(istream& mlebu,pangkat& ketik){
cout<<“Masukkan Angka= “;
mlebu>>ketik.x;
cout<<“\nMasukkan Pangkat= “;
mlebu>>ketik.y;
return mlebu;
}
ostream& operator<<(ostream& metu,pangkat& cetak){
cout<<“hasil dari “<<cetak.x<<” pangkat “<<cetak.y<<” = “<<cetak.c;
cout<<endl;
return metu;
}

void pangkat::hasil(){
c=1;
for(i=1;i<=y;i++){
c=c*x;
cout<<c<<endl;
}
cout<<endl;
}

int main()
{
pangkat b;
cin>>b;
b.hasil();
cout<<b;
system(“pause”);
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