Home > TUGAS > Practicum S-DATA FIRST WEEK

Practicum S-DATA FIRST WEEK

In the first week practicum in a data structure UAD I got a job for debugging the program and this results :

Pada Praktikum minggu pertama di struktur data UAD saya mendapat tugas untuk debugging program dan inilah hasilnya :

#include <cstdlib>
#include <iostream>

using namespace std;

class Bilangan{
friend ostream& operator<<(ostream&, const Bilangan&);
friend istream& operator>>(istream&, Bilangan&);
public:
Bilangan(int a0=0,float b0=0.0):a(a0),b(b0){}
void banding_int(const Bilangan&,const Bilangan&);
Bilangan& operator=(const Bilangan&);
Bilangan operator+(const Bilangan&) const;
Bilangan operator-()const;
private:
int a;
float b;
};
ostream& operator<<(ostream& out, const Bilangan& x)
{ out<<“Bagian integer : “<<x.a<<endl;
out<<“Bagian float : “<<x.b<<endl;
return out;
}

void Bilangan::banding_int(const Bilangan& x, const Bilangan& y)
{
if (x.a>y.a)cout<<x.a<< “::x lebih besar 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;
}
istream& operator>>(istream& in, Bilangan& x)
{
cout<<“\nMasukkan bagian integer : “;
in>>x.a;
cout<<“Masukkan bagian float : “;
in>>x.b;
return in;
}

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

Bilangan Bilangan::operator-()const
{ Bilangan x;
x.a =-a;
x.b =-b;
return x;
}

int main(int argc, char *argv[])
{
Bilangan s, t(-2,3.14),d;
cout<<“Nilai awal s\n”<<s; //operator biner<<output
cout<<“Nilai awal t dari deklarasi\n”<<t;
s=t;         //operator biner=
cout<<“Setelah s di-assign t\n”;
cout<<“Nilai s\n”<<s;
cout<<“Masukkan nilai-nilai objek d”;
cin>>d;         //operator input
cout<<“Setelah d+ t => \n”<<d+t; // operator biner +
cout<<“Nilai d dinegatifkan\n”<<-d; //operator uner-

system(“PAUSE”);
return EXIT_SUCCESS;
}

==============================================================
==============================================================

answers on the training module data structure the first week practicum (page 2-3 in practicum module)

1. already executed
2. already executed
3. from the program above:

jawaban di latihan modul praktikum struktur data minggu pertama (halaman 2-3 di modul praktikum)

1. sudah dijalankan
2. sudah dijalankan
3. dari program di atas :

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Class A common form found at:
Bentuk umum Kelas terdapat Pada :

class Bilangan{
friend ostream& operator<<(ostream&, const Bilangan&);
friend istream& operator>>(istream&, Bilangan&);
public:
Bilangan(int a0=0,float b0=0.0):a(a0),b(b0){}
void banding_int(const Bilangan&,const Bilangan&);
Bilangan& operator=(const Bilangan&);
Bilangan operator+(const Bilangan&) const;
Bilangan operator-()const;
private:
int a;
float b;
};
ostream& operator<<(ostream& out, const Bilangan& x)
{ out<<“Bagian integer : “<<x.a<<endl;
out<<“Bagian float : “<<x.b<<endl;
return out;
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

A common form of constructor are as follows:
Bentuk umum Konstruktor terdapat pada :

Bilangan(int a0=0,float b0=0.0):a(a0),b(b0){}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Class A common form found at:
Bentuk umum Method terdapat pada :

public:
Bilangan(int a0=0,float b0=0.0):a(a0),b(b0){}
void banding_int(const Bilangan&,const Bilangan&);
Bilangan& operator=(const Bilangan&);
Bilangan operator+(const Bilangan&) const;
Bilangan operator-()const;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

A common form of Member Data:
Bentuk umum Data Member :

private:
int a;
float b;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The general form of overloading operator:
Bentuk umum OPERATOR OVERLOADING :

friend class:

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

members of the class:
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;
cout<<“Masukkan bagian float : “;
in>>x.b;
return in;
}

Thank you for stopping at my blog, criticism and so I need your advice.


Muhammad Lu’ai Arminanto

Terimakasih sudah mampir di blog saya , kritik dan saran anda sangatlah saya perlukan .

Muhammad Lu’ai Arminanto

Happy blogging

Categories: TUGAS
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: