praktikum s.data rabu 09.00

nama: wiji hidayati
nim:09018300

bagian class:

class Bilangan{
friend ostream& operator<<(ostream&,const Bilangan&);
friend istream& operator>>(istream&, Bilangan&);

bagian konstuktor:

void Bilangan::banding_int(const Bilangan& x,const Bilangan& y)
{
if(x.a > y.a) cout << x.a << “::x lebih dari” << y.a <<“::y”;
else cout << x.a << “::x lebih kecil dari “<< y.a << “::y”;
}

Bilangan& Bilangan::operator=(const Bilangan& x){
a=x.a;
b=x.b;
return *this;
}

bagian method:

int main() {
Bilangan s, t(-2,3.14),d;
cout<<“Nilai awal s\n”<< s;
cout<<“Nilai awal t dari deklarasi\n”<<t;
s=t;
cout<<“Setelah s di-assign t\n”;
cout<<“Nilai s\n” << s;
cout<<“Masukkan nilai-nilai objeck d”;
cin>>d;
cout<<“Setelah d+ t=> \n”<<d+t;
cout<<“Nilai d dinegatifkan\n” << -d;

bagian data member:

private:
int a;
float b;
};

bagian operator overlaoding baik sebagia friend maupun sebagai anggota kelas:

ostream& operator<<(ostream& out, const Bilangan& x){
out << “Bagian integer:” << x.a << endl;
out << “Bagian float:” << x.b << endl;
return out;
}
istream& operator>>(istream& in, Bilangan& x){
cout<<“\nMasukkan bagian integer:”;
in>>x.a;
return in;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s