Академический Документы
Профессиональный Документы
Культура Документы
Submitted in partial fulfillment for the degree of Bachelor of Science (Hons) in Computing
ACKNOWLEDGEMENTS
Firstly we would like to thank our lecturer Mr.Udesh Amarasinghe for all the help and guidance given to us while doing this assignment. Especially for teaching us this module in such a way that we were able to learn this highly technical module very easily. Also there are many individuals who have helped us in numerous ways directly and indirectly so that we were able to complete this assignment. APIIT Lanka for providing us with resources and the Tech Team at APIIT Lanka for their assistance at required times. And last but not least our friends, parents and the well-wishers without whose moral support and encouragement, we would not have been able to do a good job. Finally, if there are any shortcomings in this project, then we request to excuse us for all those and accept this documentation. Ahamed Nishadh Deshan Ilangakoon Tiffaniya Fernando Taiyaba Ahmed
TABLE OF CONTENTS
1.0 - INTRODUCTION ............................................................................................... 1 1.1 SECTION A: DATA STRUCTURE .......................................................... 1 1.2 SECTION B: DYNAMIC MEMORY ALLOCATION AND LINK LIST1 2.0 SOURCE CODE ................................................................................................. 2 2.1 SECTION A ................................................................................................ 2 2.2 SECTION B ................................................................................................ 8 2.2.1 PART A................................................................................................ 8 2.2.2 PART 2 .............................................................................................. 10 3.0 ASSUMPTIONS ............................................................................................... 13 4.0 AGREED WORK PERCENTAGE................................................................... 14
ii
1.0 - INTRODUCTION
We were asked to implement two applications using C programming concepts. Part A appreciates the use and application of data structure while part B uses dynamic memory and link list.
do {
2
clrscr(); printf(" PREMADASA PARKING GARAGE"); printf("\n ========================\n\n\n"); printf("SELECT ACTION TO PERFORM"); printf("\n1. New Vehicle\n2. Modify Entry\n3. View Vehicles\n4. Exit\n\n YOUR CHOICE : "); fflush(stdin); scanf("%d",&opt); switch(opt) { case 1: { newvehicle(&q); break; } case 2: { modify(&q); break; } case 3: { viewvehicles(&q); break; } case 4: { _exit(1); break; } default: { printf("\n INVALID CHOICE!!!\n PRESS ANY KEY TO CONTINUE"); } } getch(); }while (opt<=4||opt>0); }
void insert(queue *qu, char vnum[10], int tin, char vet) { if(qu->rear<max) {
3
qu->rear++; strcpy(qu->vehicle[qu->rear].vplnum,vnum); qu->vehicle[qu->rear].timein = tin; qu->vehicle[qu->rear].vtype = vet; qu->vehicle[qu->rear].status = 'A'; qu->vehicle[qu->rear].position=qu->rear+1; qu->vehicle[qu->rear].moved =0; } else { printf("\nPARKING IS FULL"); } } void newvehicle(queue *q2) { if(q2->rear<max) { char lnum[10],status,vt; int in,pos2; clrscr(); printf(" PREMADASA PARKING GARAGE"); printf("\n ========================\n\n\n"); printf(" ENTER NEW VEHICLE DETAILS "); printf("\n\n 1. Enter Vehicle Type[c/v] : "); fflush(stdin); scanf("%c",&vt); printf("\n\n 1. Licence Plate Number : "); fflush(stdin); scanf("%s",&lnum); printf("\n 2. Enter Time In : "); fflush(stdin); scanf("%d",&in); insert(q2,lnum,in,vt); receipt(q2,q2->rear); } else { printf("\nPARKING IS FULL"); } } void modify(queue *q3) {
char lpnum[10]; int compres=0,pos=-1,i; if(q3->rear>=q3->front) { clrscr(); printf(" PREMADASA PARKING GARAGE"); printf("\n ========================\n\n\n"); printf(" MODIFY VEHICLE DETAILS \n\n"); printf("Enter License Plate Number to Search : "); scanf("%s",lpnum); do { pos++; compres=strcmp(q3->vehicle[pos].vplnum,lpnum); }while(compres!=0); if (compres==0) { clrscr(); printf(" PREMADASA PARKING GARAGE"); printf("\n ========================\n\n\n"); printf(" MODIFY VEHICLE DETAILS \n\n"); printf("1. License Plate Number : %s \n",q3>vehicle[pos].vplnum); printf("2. Time In : %d\n",q3->vehicle[pos].timein); printf("\n3. Enter Time Out : "); fflush(stdin); scanf("%d",&q3->vehicle[pos].timeout); q3->vehicle[pos].hrs = (q3->vehicle[pos].timeout - q3>vehicle[pos].timein); if(q3->vehicle[pos].position > 1) { for(i=0;i<(q3->vehicle[pos].position-1);i++) { q3->vehicle[i].moved++; } } q3->vehicle[pos].status = 'D'; payment(q3,pos); receipt(q3,pos); remove(q3,pos); } else { printf("\n\n SPECIFIC VEHICLE NOT AVAILABLE"); }
5
} else { printf("\n\n NO VEHICLES IN THE PARK"); } } void remove(queue *q4, int posi) { if(q4->rear>q4->front) { while(posi<=q4->rear) { q4->vehicle[posi]=q4->vehicle[posi+1]; posi++; } q4->rear--; if(q4->rear==1) { q4->rear=-1; } } else { printf("CAR PARK IS EMPTY"); } }
void receipt(queue *q5, int pos1) { clrscr(); printf(" PREMADASA PARKING GARAGE"); printf("\n ========================\n\n\n"); if(q5->vehicle[pos1].status == 'A') { printf(" PREMADASA PARKING GARAGE"); printf("\n ========================\n\n\n"); printf("ENTRANCE TICKET\n\n"); printf("1. License Plate Number : %s \n",q5>vehicle[pos1].vplnum); printf("2. Time In : %d\n",q5->vehicle[pos1].timein); printf("3. Slot No : %d\n",q5->vehicle[pos1].position); printf("\n PARKING FEES"); if(q5->vehicle[pos1].vtype='c') { printf("\nFirst 2 Hours : Rs. 50.00 "); printf("\nEach Additional Hour : Rs. 20.00");
6
} else { printf("\nFirst 2 Hours : Rs. 60.00 "); printf("\nEach Additional Hour : Rs. 25.00"); } } if(q5->vehicle[pos1].status == 'D') { printf(" PREMADASA PARKING GARAGE"); printf("\n ========================\n\n\n"); printf("RECEIPT\n\n"); printf("1. License Plate Number : %s \n",q5>vehicle[pos1].vplnum); printf("2. Time In : %d\n",q5->vehicle[pos1].timein); printf("3. Time Out : %d\n",q5->vehicle[pos1].timeout); printf("4. Hours Parked : %d\n",q5->vehicle[pos1].hrs); printf("5. Times Moved : %d\n",q5>vehicle[pos1].moved); printf("6. TOTAL PAYABLE : %.2f\n",q5>vehicle[pos1].totamnt); } } void payment(queue *q6,int pos3) { if(q6->vehicle[pos3].vtype='c') { if(q6->vehicle[pos3].hrs<2) { q6->vehicle[pos3].totamnt=50; } else { q6->vehicle[pos3].totamnt = ((q6->vehicle[pos3].hrs2)*20)+50; } } if(q6->vehicle[pos3].vtype='v') { if(q6->vehicle[pos3].hrs<2) { q6->vehicle[pos3].totamnt=60; } else { q6->vehicle[pos3].totamnt = ((q6->vehicle[pos3].hrs2)*25)+60; }
7
} if(q6->vehicle[pos3].moved>10) { q6->vehicle[pos3].totamnt = (q6->vehicle[pos3].totamnt + (q6>vehicle[pos3].totamnt * 0.01)); } } void viewvehicles(queue *q7) { int i=0; if(q7->rear>=q7->front) { printf("\tSLOT \tVEHICLE ID\tTIME IN\n"); for(i=0;i<=q7->rear;i++) { printf("\t%d\t%s\t\t%d\n",q7->vehicle[i].position,q7>vehicle[i].vplnum,q7->vehicle[i].timein); } } else { printf("\n\n NO VEHICLES IN THE PARK"); } }
link *node = (struct link*) malloc (sizeof(struct link)); if (hd==NULL) { node->data=item; node->name=n; node->next=NULL; hd=node; } else { link *temp; for(temp = hd;temp->next != NULL;temp=temp->next); temp->next=node; node->data=item; node->name=n; node->next = NULL; } } //execute function void execute() { link *temp; link *pre; while (count>0) { for(pre=NULL,temp=hd; temp!=NULL;pre=temp,temp=temp>next) { if (temp->data>0) { printf("%c,\t", temp->name); temp->data = temp->data - 4; } else { if(pre==NULL) { hd=temp->next; free(temp); count--; } else { if(temp->next==NULL) { pre=temp; free(temp); count--;
9
main() { int timeQ,i; char name; i=1; hd=NULL; while (i==1) { clrscr(); printf("ROUND ROBIN ALGORITHUM"); printf("\n\nEnter Task Name: \t"); fflush(stdin); scanf("%c",&name); printf("\nEnter Task Burst Time: \t");; fflush(stdin); scanf("%d",&timeQ);; insert(timeQ,name); printf("To continue press: 1 or To Stop Press: 0\n"); fflush(stdin); scanf("%d",&i); count++; } printf("Order of Process Execution: "); execute(); }
2.2.2 PART 2
#include<stdio.h> #include<malloc.h>
10
#include <conio.h> typedef struct link { int time; char name; link *next; }; link *hd; void insert(int item, char n) { link *node = (struct link*) malloc (sizeof(struct link)); if (hd==NULL) { node->time=item; node->name=n; node->next=NULL; hd=node; } else { link *temp; for(temp = hd;temp->next != NULL;temp=temp->next); temp->next=node; node->time=item; node->name=n; node->next = NULL; } }
void execute() { link *temp; int wait=0; for(temp=hd; temp!=NULL;temp=temp->next) { printf("%c\t\t", temp->name); printf("%d\n",wait); wait=wait+temp->time; } } main() { int timeQ,i; char name;
11
i=1; hd=NULL; while (i==1) { clrscr(); printf("FIRST IN FIRST OUT ALGORITHUM"); printf("\n\nEnter Task Name: \t"); scanf("%c",&name); flushall(); printf("\nEnter Task Burst Time: \t");; scanf("%d",&timeQ);; flushall(); insert(timeQ,name); printf("To continue press: 1 or To Stop Press: 0\n"); scanf("%d",&i); flushall(); } printf("\nProcess Waiting time\n\n"); printf("Process Name \tWaiting Time\n"); execute(); }
12
3.0 ASSUMPTIONS
1. The arrival time, only the hour when the vehicle arrived is recorded. It is the same case with the departure time. 2. The time is inserted in the 24hr format clock.
13
I, hereby agree that the above members have undertaken the above tasks and their work is reflective of what I have written above. Group Leader : A.N.Ahamed Nishadh (CB004081) Signature :
14