Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
struct data
{
char nama[50];
char plat[50];
struct data *next, *prev;
}*head1=NULL,*curr1,*head2=NULL, *curr2;
void push_to_garage(char name[], char x[])
{
curr1=(struct data*)malloc(sizeof(struct data));
strcpy(curr1->nama,name);
strcpy(curr1->plat,x);
curr1->next=NULL;
curr1->prev=NULL;
if(head1==NULL)
{
head1=curr1;
curr1->next=NULL;
}
else
{
head1->prev=curr1;
curr1->next=head1;
head1=curr1;
}
head1->prev=NULL;
}
void pop()
{
if(head1==NULL)
{
head1=curr1=NULL;
getchar();
}
if(head1->next==NULL)
{
free(head1);
head1=curr1=NULL;
}
else
{
curr1=head1;
head1=head1->next;
head1->prev=NULL;
free(curr1);
}
}
void push_to_park(char name[],char x[])
{
curr2=(struct data*)malloc(sizeof(struct data));
strcpy(curr2->nama,name);
strcpy(curr2->plat,x);
curr2->next=NULL;
curr2->prev=NULL;
if(head2==NULL)
{
head2=curr2;
curr2->next=NULL;
}
else
{
head2->prev=curr2;
curr2->next=head2;
head2=curr2;
}
printf("%s's car %s moved into the parking lot",head1->nama,head1->plat);
head2->prev=NULL;
}
void popall()
{
if(head2==NULL)
printf("There is no car in the parking lot...");
else
{
while(head2)
{
push_to_garage(head2->nama,head2->plat);
curr2=head2;
head2=head2->next;
free(curr2);
}
printf("All cars returned into the garage...");
}
}
char owner[50];
char no[50];
void input()
{
srand(time(NULL));
do{
printf("Enter owner name [5..15]: ");
scanf("%[^\n]",&owner); fflush(stdin);
}while(strlen(owner)<5||strlen(owner)>15);
no[0]='B'; //nomor plat
no[1]=' ';
no[2]=rand()%10+48;
no[3]=rand()%10+48;
no[4]=rand()%10+48;
no[5]=rand()%10+48;
no[6]=' ';
no[7]=rand()%26+65;
no[8]=rand()%26+65;
push_to_garage(owner,no);
printf("Car added to garage...");
getchar();
}
void cetak()
{
curr1=head1;
curr2=head2;
printf("-GARAGE-\n");
if(curr1==NULL) printf("There is no car in the garage...\n");
else
{
while(curr1)
{
printf("%-15s|%-15s\n",curr1->plat,curr1->nama);
curr1=curr1->next;
}
printf("=======================================\n");
spasi();
if(head1==NULL)
{
printf("There is no car in the garage...");
getchar();
}
else if(head1)
{
push_to_park(head1->nama,head1->plat);
pop();
getchar();
}
break;
case 3: spasi();
popall();
getchar();
break;
case 4:
spasi();
cetak();
break;
}
}while(opsi!=5);
spasi();
printf("Thank you ");
getchar();
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct data{
char nama[50];
int umur;
char dat[50];
struct data *next;
}*head,*tail,*curr;
}
}
else
{
printf("\nThere is no data in list\n");
}
}
void bersih(){
for(int i=0;i<20;i++){
printf("\n");
}
}
void main(){
int pilih;
char namatempat[50];
int umurtempat;
char dattempat[100];
do{
printf("welcome to HA Clinic\n");
printf("====================\n");
printf("1. Register new patient\n");
printf("2. Treat patient\n");
printf("3. view pantient list\n");
printf("4. Exit\n");
printf("Choose:");
scanf("%d",&pilih);
fflush(stdin);
switch(pilih){
case 1:
do{
printf("input patient name:");
scanf("%s",namatempat);
fflush(stdin);
}while(strlen(namatempat)<1||strlen(namatempat)>50);
do{
printf("input Age:");
scanf("%d",&umurtempat);
fflush(stdin);
}while(umurtempat<1||umurtempat>80);
printf("input detail:");
scanf("%s",dattempat);
fflush(stdin);
push(namatempat,umurtempat,dattempat);
printf("succes register new patient!\n");
getchar();
break;
case 2: pop();
break;
case 3: cetak();
break;
case 4: bersih();
printf("==============================================
============\n");
printf("open our Vision and Encourage ourself\n");
printf("==============================================
============\n");
}
}while(pilih!=4);