#include<stdio.h>
#include<string.h>
char kendaraan[20][20];
int jam[20],menit[20],areakosong[20];
int a;
void sortwaktuasc(){
int i,j,temp;
char tempkend[20];
for(i=0;i<a;i++){
for(j=a-1;j>i;j--){
if(jam[j]<jam[j-1]){
temp=jam[j];
jam[j]=jam[j-1];
jam[j-1]=temp;
temp=menit[j];
menit[j]=menit[j-1];
menit[j-1]=temp;
strcpy(tempkend,kendaraan[j]);
strcpy(kendaraan[j],kendaraan[j-1]);
strcpy(kendaraan[j-1],tempkend);
temp=areakosong[j];
areakosong[j]=areakosong[j-1];
areakosong[j-1]=temp;
}
else if(jam[j]==jam[j-1]){
if(menit[j]<menit[j-1]){
temp=jam[j];
jam[j]=jam[j-1];
jam[j-1]=temp;
temp=menit[j];
menit[j]=menit[j-1];
menit[j-1]=temp;
strcpy(tempkend,kendaraan[j]);
strcpy(kendaraan[j],kendaraan[j-1]);
strcpy(kendaraan[j-1],tempkend);
temp=areakosong[j];
areakosong[j]=areakosong[j-1];
areakosong[j-1]=temp;
}
}
}
}
}
void sortnamadesc(){
int i,j,temp;
char tempkend[20];
for(i=0;i<a;i++){
for(j=a-1;j>i;j--){
if(strcmp(kendaraan[j],kendaraan[j-1])>0){
temp=jam[j];
jam[j]=jam[j-1];
jam[j-1]=temp;
temp=menit[j];
menit[j]=menit[j-1];
menit[j-1]=temp;
strcpy(tempkend,kendaraan[j]);
strcpy(kendaraan[j],kendaraan[j-1]);
strcpy(kendaraan[j-1],tempkend);
temp=areakosong[j];
areakosong[j]=areakosong[j-1];
areakosong[j-1]=temp;
}
}
}
}
void cetak(){
printf("\n\n\n\n\n\n\n\n\n");
printf("\t\t\t ----------------------------------- \n");
printf("\t\t\t| Aplikasi Parking Management |\n");
printf("\t\t\t| By: |\n");
printf("\t\t\t| Siti Qomariyah Ulfa |\n");
printf("\t\t\t| 1301062160 |\n");
printf("\t\t\t ----------------------------------- \n");
printf("\n\n\n\n ----=Parking Management=----\n");
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n");
printf(" No| Jenis_Kendaraan | Jam_masuk | Area_kosong\n");
printf("=============================================================\n");
for(int z=0;z<a;z++){
printf(" %d | %-20s | %4.2d.%-6.2d | %-3d\n",z+1,kendaraan[z],jam[z],menit[z],areakosong[z]);
}
printf("=============================================================\n");
}
void menu(){
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("Parking Management");
printf("\n============================\n");
printf("1.List kendaraan\n");
printf("2.Sort ascending berdasarkan jam masuk\n");
printf("3.Sort descending berdasarkan jenis kendaraan\n");
printf("4.Tambah kendaraan\n");
printf("5.Keluar\n\n");
printf("Masukan pilihan [1..5]: ");
}
int main(){
FILE *p;
int input,jm,mnt,flag;
char nm[25];
p=fopen("data.txt","r");
a=0;
while(fscanf(p,"%s %d.%d %d",kendaraan[a],&jam[a],&menit[a],&areakosong[a])!=EOF){
a++;
}
do{
menu();
scanf("%d",&input);
fflush(stdin);
switch(input){
case 1:
cetak();
printf("\nTekan Enter untuk melanjutkan..");
getchar();
break;
case 2:
sortwaktuasc();
printf("\n");
printf("Sorting berhasil^^..\n\n");
printf("Silahkan melihat List Film di Menu \'1\'\n\n");
printf("Tekan Enter untuk melanjutkan..");
getchar();
break;
case 3:
sortnamadesc();
printf("\n");
printf("Sorting berhasil^^..\n\n");
printf("Silahkan melihat List Film di Menu \'1\'\n\n");
printf("Tekan Enter untuk melanjutkan..");
getchar();
break;
case 4:
printf("\n");
do{
printf("Masukan jenis kendaraan yang baru [1..10 kar]: ");
scanf("%s",nm);
fflush(stdin);
}while(strlen(nm)<1||strlen(nm)>10);
do{
jm=100;
printf("Masukan jam [0..23] : ");
scanf("%d",&jm);
fflush(stdin);
}while(jm<0 || jm>23);
do{
mnt=100;
printf("Masukan menit [0..59] : ");
scanf("%d",&mnt);
fflush(stdin);
}while(mnt<0 || mnt>59);
strcpy(kendaraan[a],nm);
jam[a]=jm;
menit[a]=mnt;
areakosong[a]=100;
a++;
printf("\nBerhasil menambah kendaraan baru^^\n");
printf("\nTekan Enter untuk melanjutkan..");
getchar();
break;
}
}while(input!=5);
fclose(p);
p=fopen("data.txt","w");
for(int gg=0;gg<a;gg++){
if(gg==0){
fprintf(p,"%s %d.%d %d",kendaraan[gg],jam[gg],menit[gg],areakosong[gg]);
}
else{
fprintf(p,"\n%s %d.%d %d",kendaraan[gg],jam[gg],menit[gg],areakosong[gg]);
}
}
}
10/24/2011
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar