Monday, October 29, 2007

Jawaban Unguided Kelas C

//file header.h
#include
#include
#include
#include

#define Max 5

typedef int address;
typedef int infotype;
typedef char string[20];
typedef struct
{
string strNama;
infotype umur;
}Anak;
typedef struct
{
Anak Element[Max];
address Head;
address Tail;
}Queue;

void createEmpty(Queue *Q);
int isEmpty(Queue Q);
int isFull(Queue Q);
int isOneElmt(Queue Q);
void Add(Queue *Q,Anak data);
void Del(Queue *Q);
void PrintQueue(Queue Q);


//file function.c
#include"header.h"

void createEmpty(Queue *Q)
{
(*Q).Head=(*Q).Tail=-1;
}

int isEmpty(Queue Q)
{
return(Q.Head==-1 && Q.Tail==-1);
}

int isFull(Queue Q)
{
return((Q.HeadQ.Tail && Q.Head-Q.Tail==1));
}

int isOneElmt(Queue Q)
{
return(Q.Head==Q.Tail && Q.Head!=-1);
}

void Add(Queue *Q,Anak data)
{
if(!isFull(*Q))
{
if(isEmpty(*Q))
{
(*Q).Head=(*Q).Tail=0;
(*Q).Element[(*Q).Head]=data;
}
else
{
if((*Q).Tail==Max-1)
(*Q).Tail=0;
else
(*Q).Tail++;
(*Q).Element[(*Q).Tail]=data;
}
}
else
printf ("Antrian penuh\n");
}

void Del(Queue *Q)
{
int bantu=(*Q).Head;
if(!isEmpty(*Q))
{
if(isOneElmt(*Q))
createEmpty(&(*Q));
else
{
if((*Q).Head==Max-1)
(*Q).Head=0;
else
(*Q).Head++;
}
printf("\nData yang dihapus");
printf("\nNama : %s",(*Q).Element[bantu].strNama);
printf("\nUmur : %d",(*Q).Element[bantu].umur);
}
}

void PrintQueue(Queue Q)
{
address i;
if(!isEmpty(Q))
{
if(Q.Head<=Q.Tail)
{
for(i=Q.Head;i<=Q.Tail;i++)
printf("%s/(%d tahun) ",Q.Element[i].strNama,Q.Element[i].umur);
}
else
{
for(i=Q.Head;i<=Max-1;i++)
printf("%s/(%d tahun) ",Q.Element[i].strNama,Q.Element[i].umur);
for(i=0;i<=Q.Tail;i++)
printf("%s/(%d tahun) ",Q.Element[i].strNama,Q.Element[i].umur);
}
}
else
printf("Queue kosong");
printf("\n");
}


//file main.c
#include"header.h"

main()
{
Queue Q[4];
Anak Data;
int i,iPilih,iHapus;
for(i = 0;i < 4;i++)
createEmpty(&Q[i]);
do
{
system("cls");
printf("MENU\n");
printf("1.Add Queue\n");
printf("2.Del Queue\n");
printf("3.Print Queue\n");
printf("0.Keluar\n");
printf("Pilihan: ");
scanf("%d",&iPilih);
switch(iPilih)
{
case 1:
fflush(stdin);
printf("Masukkan Nama = ");
gets(Data.strNama);
printf("Masukkan Umur = ");
scanf("%d",&Data.umur);
if(Data.umur >= 7 && Data.umur <= 15)
{
if(Data.umur == 7 || Data.umur == 8)
Add(&Q[0],Data);
else if(Data.umur == 9 || Data.umur == 10)
Add(&Q[1],Data);
else if(Data.umur == 11 || Data.umur == 12)
Add(&Q[2],Data);
else
Add(&Q[3],Data);
}
else
printf("Maaf lomba hanya untuk anak umur 7 tahun sampai 15 tahun\n");

for(i = 0;i < 4;i++)
{
printf("Loket %d: ",i+1);
PrintQueue(Q[i]);
}
getch();
break;
case 2:
printf("Masukkan loket yang antriannya ingin dihapus = ");
scanf("%d",&iHapus);
Del(&Q[iHapus-1]);
getch();
break;
case 3:
for(i = 0;i < 4;i++)
{
printf("Loket %d: ",i+1);
PrintQueue(Q[i]);
}
getch();
break;
}
}while(iPilih!=0);
}

5 comments:

Anonymous said...

A shared web hosting advantage or understood hosting repair or receive assemblage refers to a net hosting service where various websites reside on harmonious trap server connected to the Internet. Each situate "sits" on its own allotment, or section/place on the server, to regard it separate from other sites. This is on average the most stingy choice for hosting, as many people share the inclusive set someone back of server maintenance.
[url=http://hostinghouse.pl]hosting[/url]

Anonymous said...

[url=http://casodex-bicalutamide.webs.com/]purchase Bicalutamide
[/url] buy Bicalutamide
Pencial
Biprosta

Anonymous said...

[url=http://amoxicilline.webs.com/]acheter Trimox en ligne
[/url][url=http://acheter-amoxicilline.webs.com/]amoxicilline enfant posologie
[/url] amoxicillin yan etkileri
agram loudГ©ac
amoxicilline large spectre

Anonymous said...

[url=http://www.microgiving.com/profile/ribavirin]order rebetol online
[/url] buy copegus
rebetol buy online
copegus buy online

Anonymous said...

[url=http://www.eventective.com/eventsites/longchampsacsa/]sac longchamp moins cher[/url] In this way, insulation fibers that may have clung on the gear wouldn't scatter in another place. Save up 60% when shopping Mulberry Brynmore For Macbook Pro Leather Messenger Bag Light Coffee for Men at our Mulberry outlet. Put the coveralls in a garbage bag and seal it before putting it in a trashcan. If you see any fibers clinging on your skin, remove them with duct tape.
[url=http://longchampbagsd.webeden.net/#/blog/4574070481]sacs longchamps[/url] Another great advantage of diaper bag backpacks is that they can be used by both moms and dads. Most ALL Handbags is Factory order.Highly Appreciated Mulberry Women's Alexa Leather Satchel Blue Bag, 100% original & quality traditional diaper bags are designed with the mom in mind, so they are either too girly or too cute for a hands-on dad to use proudly when going out with the baby. With backpacks, that is not the case at all.
[url=http://longchamppliagea.webnode.nl/]sacs longchamps[/url] Phu Quoc civic esplanade is amid in the northeast of the island and belongs to Kien Giang Province\'s three communes of Bai Thom, Cua Duong and Ham Ninh. It covers an breadth of 31,422 hectares and is home to hundreds of flora and fauna and a forest, river, streams, waterfalls, mountains and hills and is disconnected into three areas. One is carefully protected, addition is ecologically adequate and the administration-service-scientific analysis area... The products are popular among the elite class, but these are also being sported by many in the low and middle income brackets. These are also widely available in many vintage stores and Designer Mulberry Women's Smaller Bayswater Printed Leather Shoulder Light Coffee Bag sale unique thrift shops as well. Bags, in particular, match well with pleated skirts and sweater vests, which can create a refined and sophisticated look..