RSS

Praktikum 9

22 Des

#include
#include
#define maks 5

using namespace std;

class Queue{
friend ostream& operator<<(ostream&, const Queue&);
public:
Queue();
int penuh(int);
int kosong(int);
void cetak();
void enqueue(char);
char dequeue();
private:
char A[maks];
int banyak;
};

ostream& operator<<(ostream& out, const Queue& s)
{
cout<<"\nIsi Queue sebanyak : " <<s.banyak<<" yaitu : ";
for(int i=0; i<s.banyak; i++)
out<<s.A[i]<<" ";
}

Queue::Queue()
{
banyak=0;
for(int i=0; i<maks; i++)
A[i]='0';
}

int Queue::penuh(int s)
{
return s==maks ? 1: 0;
}

int Queue::kosong(int s)
{
return s==0 ? 1:0;
}

void Queue::cetak()
{
cout<<"\nIsi Queue : ";
for(int i=0; i<banyak; i++)
cout<<A[i]<<" ";
}

void Queue::enqueue(char x)
{
cout<<"\n\nElemen : "<<x<<" masuk antrian";
if(penuh(banyak))cout<x)tempat++;
if(banyak != tempat)
for(int i=banyak; i>=tempat; i–)
A[i+1]=A[i];
A[tempat]=x;
banyak++;
}
}

char Queue::dequeue()
{
char temp=A[–banyak];
cout< “<<temp;
A[banyak]='0';
return temp;
}

int main(int argc, char *argv[])
{
Queue p;
p.enqueue('a');
cout<<p;
p.enqueue('b');
cout<<p;
p.enqueue('d');
cout<<p;
char a;
for (char c=1; c<2; c++) {
cout<<"\n\nInput antrian :" <>a;
p.enqueue (a);
cout<<p;
}
char q=p.dequeue ();
p.cetak();
cout<<"\n\nCetak pakai overloading:"<<p;

system("PAUSE");
return EXIT_SUCCESS;
}

 
Tinggalkan komentar

Ditulis oleh pada Desember 22, 2010 in praktikum

 

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

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

 
%d blogger menyukai ini: