PROTOTYPE TA. SEMESTER 3 ” ANTRIAN PARKIR ”
contoh kodenya
# include <iostream.h>
# include <conio.h>
# include <fstream.h>
# include <string.h>
struct Node
{
char plat[250];
char type[250];
char hari[250];
char data[120];
char jam [150];
char ptgs[200];
struct Node * link;
};
class antrian {
public:
antrian();
void kolom();
void menu();
void guswan( char *, char *, char*, char *, char*, char*);
void masukan();
void hapus();
void kolom_list();
void cetak();
private:
Node * p, * first, * last, * q;
char x[10];
};
CONTOH PROGRAM STACK
#include <cstdlib>
#include <iostream>
using namespace std;
class Stack{
public:
Stack(){
jum = 5;//jumlah array
last = 0;
}
void push(int data){
if(jum > last){
a[last] = data;
last = last + 1;
}
}
int pop(){
if(last > 0){
int temp = a[last - 1];
a[last - 1] = 0;
last = last - 1;
return temp;
}
}
//untuk mencetak
void print(){
for(int i = 0; i < last; i++){
cout << a[i] << " ";
}
}
//untuk mendeklarasikan
private:
int a[5];
int jum;
int last;
};
int main(int argc, char *argv[])
{
Stack x;
x.push(2);//untuk memasukkan data(2)
x.push(4);
x.push(11);
x.push(5);
x.push(7);
x.push(9);
x.push(30);
x.print();
cout<<endl;
x.pop();//untuk mengeluarkan data(2)sehingga dibuang tidak ditampilkan
x.print();
cout<<endl;
x.pop();
x.print();
cout<<endl;
x.pop();
x.print();
cout<<endl;
x.pop();
x.pop();
x.pop();
x.print();
cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
0 komentar:
Posting Komentar