Source Code :
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<conio2.h>
struct mobil{
char platnomor[30];
char pemilik[30];
char merk_mobil[30];
struct mobil *next;
};
struct queue{
mobil *head;
int count;
mobil *tail;
};
int isFull(queue *queue);
int isEmpty(queue *queue);
void mobil_masuk(queue *queue);
void cetak(queue *queue);
void mobilout(queue *queue);
void kosongkan(queue *queue);
void mobil2an(queue *queue);
void mobil2an_out(queue *queue);
int main(){
queue queue;
queue.count=0;
queue.head=NULL;
queue.tail=NULL;
char pilih;
int isfull,isempty;
do{system("cls");
printf("\t\t\t\tPROGRAM SIMULASI PARKIR\n\n");
printf("\n[1].cek antrian(full/tidak)");
printf("\n[2].cek antrian(kosong/tidak)");
printf("\n[3].kosongkan parkiran");
printf("\n[4].mobil masuk");
printf("\n[5].mobil keluar");
printf("\n[6].lihat mobil urutan terdepan");
printf("\n[7].lihat semua mobil");
printf("\n[8].exit\n");
printf("\npilihan: "); scanf("%c",&pilih); fflush(stdin);
if(pilih=='1'){isfull=isFull(&queue);
if(isfull==1){printf("\n parkiran penuh\n");getch();}
else {printf("\ntidak penuh\n"); getch();}
}
else if(pilih=='2'){isempty=isEmpty(&queue);
if(isempty==1){printf("\nparkiran kosong\n");getch();}
else {printf("\ntidak kosong\n"); getch();}
}
else if(pilih=='3'){kosongkan(&queue);}
else if(pilih=='4'){mobil_masuk(&queue);}
else if(pilih=='5'){mobilout(&queue); mobil2an_out(&queue);}
else if(pilih=='6'){ }
else if(pilih=='7'){ cetak(&queue);}
}while(pilih!='8');
}
int isFull(queue *queue){
if(queue->count==5) return 1;
else return 0;
}
int isEmpty(queue *queue){
if(queue->count==0) return 1;
else return 0;
}
void mobil_masuk(queue *queue){
mobil *pNew; int batas;
pNew=(mobil*)malloc(sizeof(mobil));
if(pNew!=NULL){
if(queue->count==5) {printf("parkiran full"); getch();}
else{
pNew->next=NULL;
printf("\nmasukkan nama pemilik: "); scanf("%[^\n]",&pNew->pemilik);fflush(stdin);
printf("\nmasukkan plat nomor : "); scanf("%[^\n]",&pNew->platnomor);fflush(stdin);
printf("\nmasukkan merk mobil : "); scanf("%[^\n]",&pNew->merk_mobil);fflush(stdin);
if(queue->count==0){
queue->head=pNew;
}
else{
queue->tail->next=pNew;
}
queue->tail=pNew;
queue->count=(queue->count)+1;
}
}
}
void mobilout(queue *queue){
mobil *dltPtr;
char platout[15];
dltPtr = queue->head;
if(queue->count == 1){
queue->head = queue->tail =NULL;
}
else {
queue->head=queue->head->next;
}
queue->count--;
free(dltPtr);
}
void cetak(queue *queue){
mobil *pWalker;
int i=1;
pWalker=queue->head;
if(queue->count==0){printf("\nparkiran kosong");getch();}
else{ system("cls");
mobil2an(queue);
gotoxy(1,7);
while(pWalker!=NULL){
printf("mobil ke-%d : %s atas nama %s\n",i,pWalker->platnomor,pWalker->pemilik);
pWalker=pWalker->next; i++;
}
getch();
}
}
void kosongkan(queue *queue){
while(queue->head!=NULL){
mobilout(queue);
}
}
//animasi mobil2an
void mobil2an(queue *queue){
int jml;
jml=queue->count;
int a;int z=65; int y;
int n;
printf(" IN ");gotoxy(68,1);printf(" OUT ");
gotoxy(1,6); printf("--------------------------------------------------------------------------------");
for(n=0;n<jml;n++){ //pengulangan untuk jumlah mobil
for(a=1;a<=z;a++){//pengulangan agar mobil terlihat bergerak
_sleep(30);
gotoxy(a+2,2);printf(" _______");
gotoxy(a,3);printf(" _| |_");
gotoxy(a,4);printf(" | |");
gotoxy(a,5);printf(" ---@-----@--");
}
z=z-15;
}
}
void mobil2an_out(queue *queue){
int jml;
jml=queue->count+1;
int a;int z=65; int y;
int n;
gotoxy(1,13);printf(" IN ");gotoxy(68,13);printf(" OUT ");
gotoxy(1,20); printf("--------------------------------------------------------------------------------");
for(n=0;n<jml;n++){ //pengulangan untuk jumlah mobil
for(a=1;a<=z;a++){//pengulangan agar mobil terlihat bergerak
gotoxy(a+2,16);printf(" _______");
gotoxy(a,17);printf(" _| |_");
gotoxy(a,18);printf(" | |");
gotoxy(a,19);printf(" ---@-----@--");
}
z=z-15;
}
getch();
for(n=0;n<=1;n++){//pengulangan ketika 1 paling depan keluar
if (jml==1){
gotoxy(a+2,16);printf(" ");
gotoxy(a,17);printf(" ");
gotoxy(a,18);printf(" ");
gotoxy(a,19);printf(" ");
}
else{
y=50; z=65;
for(n=0;n<jml-1;n++){
for(a=y;a<=z;a++){
_sleep(30);
gotoxy(a+2,16);printf(" _______");
gotoxy(a,17);printf(" _| |_");
gotoxy(a,18);printf(" | |");
gotoxy(a,19);printf(" ---@-----@--");
}
y=y-15; z=z-15;
}
}
}
getch();
}
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<conio2.h>
struct mobil{
char platnomor[30];
char pemilik[30];
char merk_mobil[30];
struct mobil *next;
};
struct queue{
mobil *head;
int count;
mobil *tail;
};
int isFull(queue *queue);
int isEmpty(queue *queue);
void mobil_masuk(queue *queue);
void cetak(queue *queue);
void mobilout(queue *queue);
void kosongkan(queue *queue);
void mobil2an(queue *queue);
void mobil2an_out(queue *queue);
int main(){
queue queue;
queue.count=0;
queue.head=NULL;
queue.tail=NULL;
char pilih;
int isfull,isempty;
do{system("cls");
printf("\t\t\t\tPROGRAM SIMULASI PARKIR\n\n");
printf("\n[1].cek antrian(full/tidak)");
printf("\n[2].cek antrian(kosong/tidak)");
printf("\n[3].kosongkan parkiran");
printf("\n[4].mobil masuk");
printf("\n[5].mobil keluar");
printf("\n[6].lihat mobil urutan terdepan");
printf("\n[7].lihat semua mobil");
printf("\n[8].exit\n");
printf("\npilihan: "); scanf("%c",&pilih); fflush(stdin);
if(pilih=='1'){isfull=isFull(&queue);
if(isfull==1){printf("\n parkiran penuh\n");getch();}
else {printf("\ntidak penuh\n"); getch();}
}
else if(pilih=='2'){isempty=isEmpty(&queue);
if(isempty==1){printf("\nparkiran kosong\n");getch();}
else {printf("\ntidak kosong\n"); getch();}
}
else if(pilih=='3'){kosongkan(&queue);}
else if(pilih=='4'){mobil_masuk(&queue);}
else if(pilih=='5'){mobilout(&queue); mobil2an_out(&queue);}
else if(pilih=='6'){ }
else if(pilih=='7'){ cetak(&queue);}
}while(pilih!='8');
}
int isFull(queue *queue){
if(queue->count==5) return 1;
else return 0;
}
int isEmpty(queue *queue){
if(queue->count==0) return 1;
else return 0;
}
void mobil_masuk(queue *queue){
mobil *pNew; int batas;
pNew=(mobil*)malloc(sizeof(mobil));
if(pNew!=NULL){
if(queue->count==5) {printf("parkiran full"); getch();}
else{
pNew->next=NULL;
printf("\nmasukkan nama pemilik: "); scanf("%[^\n]",&pNew->pemilik);fflush(stdin);
printf("\nmasukkan plat nomor : "); scanf("%[^\n]",&pNew->platnomor);fflush(stdin);
printf("\nmasukkan merk mobil : "); scanf("%[^\n]",&pNew->merk_mobil);fflush(stdin);
if(queue->count==0){
queue->head=pNew;
}
else{
queue->tail->next=pNew;
}
queue->tail=pNew;
queue->count=(queue->count)+1;
}
}
}
void mobilout(queue *queue){
mobil *dltPtr;
char platout[15];
dltPtr = queue->head;
if(queue->count == 1){
queue->head = queue->tail =NULL;
}
else {
queue->head=queue->head->next;
}
queue->count--;
free(dltPtr);
}
void cetak(queue *queue){
mobil *pWalker;
int i=1;
pWalker=queue->head;
if(queue->count==0){printf("\nparkiran kosong");getch();}
else{ system("cls");
mobil2an(queue);
gotoxy(1,7);
while(pWalker!=NULL){
printf("mobil ke-%d : %s atas nama %s\n",i,pWalker->platnomor,pWalker->pemilik);
pWalker=pWalker->next; i++;
}
getch();
}
}
void kosongkan(queue *queue){
while(queue->head!=NULL){
mobilout(queue);
}
}
//animasi mobil2an
void mobil2an(queue *queue){
int jml;
jml=queue->count;
int a;int z=65; int y;
int n;
printf(" IN ");gotoxy(68,1);printf(" OUT ");
gotoxy(1,6); printf("--------------------------------------------------------------------------------");
for(n=0;n<jml;n++){ //pengulangan untuk jumlah mobil
for(a=1;a<=z;a++){//pengulangan agar mobil terlihat bergerak
_sleep(30);
gotoxy(a+2,2);printf(" _______");
gotoxy(a,3);printf(" _| |_");
gotoxy(a,4);printf(" | |");
gotoxy(a,5);printf(" ---@-----@--");
}
z=z-15;
}
}
void mobil2an_out(queue *queue){
int jml;
jml=queue->count+1;
int a;int z=65; int y;
int n;
gotoxy(1,13);printf(" IN ");gotoxy(68,13);printf(" OUT ");
gotoxy(1,20); printf("--------------------------------------------------------------------------------");
for(n=0;n<jml;n++){ //pengulangan untuk jumlah mobil
for(a=1;a<=z;a++){//pengulangan agar mobil terlihat bergerak
gotoxy(a+2,16);printf(" _______");
gotoxy(a,17);printf(" _| |_");
gotoxy(a,18);printf(" | |");
gotoxy(a,19);printf(" ---@-----@--");
}
z=z-15;
}
getch();
for(n=0;n<=1;n++){//pengulangan ketika 1 paling depan keluar
if (jml==1){
gotoxy(a+2,16);printf(" ");
gotoxy(a,17);printf(" ");
gotoxy(a,18);printf(" ");
gotoxy(a,19);printf(" ");
}
else{
y=50; z=65;
for(n=0;n<jml-1;n++){
for(a=y;a<=z;a++){
_sleep(30);
gotoxy(a+2,16);printf(" _______");
gotoxy(a,17);printf(" _| |_");
gotoxy(a,18);printf(" | |");
gotoxy(a,19);printf(" ---@-----@--");
}
y=y-15; z=z-15;
}
}
}
getch();
}
Screenshot:
Semoga bermanfaat :)
programnya masih ada bugnya ya ?? soalnya pas aku compile kalo dan pas parkiran masih kosong, aku pilih mobil keluar, langsung ngebug, perlu kasih proteksi
ReplyDeleteiya,mksh komentarnya, bisa ditambah sndiri
ReplyDeleteyhanks gan...tak cba' dlu . .
ReplyDeleteconio2.h tu apa gan?
ReplyDelete