Beruflich Dokumente
Kultur Dokumente
Group Assignment
Data Bases and Data Structures
Prepared By
Malith Waniganayake CB004144
Hishara Silva CB004160
Harin Fernando CB004134
Cohort
DF10A1ICT
Date of Submission
05-05-2011
Instructor
Mr.Udesh Amarasinghe
ACKNOWLEDGEMENT
It had been a wonderful experience, developing this Project. It would be imperative to
extend our sincere thanks to several people who have helped us in making this project
a reality.
Our most sincere appreciation goes to Mr. Udesh Amarasinghe, our DSBS lecturer for
helping us on completion of this project and without whom the completion of this
project would not have been a success.
We wish to thank APIIT Lanka for providing us with excellent facilities and
inspiration. We also would like to thank all the lab assistance for enabling us to use
the computer laboratories.
Last but not least, our friends who were doing this project with us and sharing our
ideas. They were helpful that when we combined and discussed together, we had this
task done.
INTRODUCTION
Introduction of Premadasa car parking system
As a group project we were assigned to solve two problems related to data bases and
data structures from what we have learned throughout this semester. The Premadasa
Parking Garage is a small venue which is used to park only cars and vans and can
hold up to a maximum of 10 ten vehicles at a time.
We have to implement a system to take the daily recordings and to keep the
information on which vehicle is parked in which are and the time of arrival and
departure.
The new system will calculate the payments and the reductions of the parking time
and a print out of the bill is given to the customer.
STUDENT NAME
PART A
PART B
1
Malith Waniganayake
33%
33%
33%
Harin Fernando
33%
33%
33%
Hishara Silva
33%
33%
33%
TOTAL
100%
100%
100%
Part A
Program Code
#include <stdio.h>
#include<stdlib.h>
#define MAX 10
#include<conio.h>
/*-------------------Structures------------------*/
typedef struct details
{
int plateNo;
int parkingTym;
int parkSlot;
int chrgDetails;
int tymOfArrival;
int tymOfDepart;
int duration;
float ttlCharge;
int noOfTymMove;
};
typedef struct stack
{
details ele[MAX];
int top;
};
/*-------------------Function Headers------------------*/
void inisializing(stack*);
int isfull(stack*) ;
int isempty(stack*);
void push(stack*,details);
details pop(stack*,int);
void addDetails(stack*);
void park(stack*);
void leave(stack*);
void print(stack*);
void welcome();
/*-------------------main Function------------------*/
main()
{
char cont;
stack s;
welcome();
inisializing(&s);
do
{
int i;
clrscr();
printf("\n\t ===========================================================");
printf(" \n\t ++++++++++++ PREMADASA CAR PARK SYSTEM +++++++++++++++++ " );
printf("\n\t ===========================================================");
printf(" \n\n\n\t ## Select you Choice (Enter the number) ");
printf("\n\n\t 1) park");
printf("\n\n\t 2) leave");
printf("\n\n\t 3) print");
printf("\n\n\t 4) Exit");
printf("\n\n\t Enter your choice? = ");
int choice;
scanf("%d",&choice);
switch (choice)
{
case 1:
park(&s);
break;
case 2:
leave(&s);
break;
case 3:
print(&s);
break;
case 4:
clrscr();
printf("\n\t !!!! Thank you for using PREMADASA CAR PARK SYSTEM
!!!! ");
printf("\n\n\t\t\t !!!! GOODBYE !!!!");
getch();
abort();
default:
break;
}
printf("\n\t Do you want to continue(Y/N):-");
fflush(stdin);
scanf("%c",&cont);
printf("\n");
}while((cont=='y')||(cont=='Y'));
abort();
}
void park(stack *s)
{
addDetails(s);
}
void leave(stack *s)
{
char lev;
printf("\n
\t
int carslot;
scanf("%d",&carslot);
details ptrd;
details *ptr;
ptrd=pop(s,carslot);
ptr=&ptrd;
/*-------------------isfull Function------------------*/
int isfull(stack *s)
{
if(s->top>MAX)
return 1;
else
return 0;
}
/*-------------------isempty Function------------------*/
int isempty(stack *s)
{
if(s->top<=-1)
return 1;
else
return 0;
}
/*-------------------push Function------------------*/
void push(stack *s, details d)
{
int full;
full=isfull(s);
/*call isfull Function*/
if(full==0)
s->top++;
s->ele[s->top]=d;
}
/*-------------------pop Function------------------*/
details pop(stack *s,int carslot)
{
int empty;
details d;
empty=isempty(s);
/*call isempty Function*/
if(empty==0)
d=s->ele[carslot-1];
for(int k=carslot;k<=s->top;k++)
{
details d1=s->ele[k];
details *d2;
d2= &d1;
d2->noOfTymMove=+1;
s->ele[k-1]=d1;
}
s->top--;
return(d);
}
void addDetails(stack *s)
{
fflush(stdin);
details d;
details *ptrd=&d;
char type;
ptrd->noOfTymMove =0;
printf("\n\t Enter Plate no( 4 Digits only) = ");
scanf("%d",&ptrd->plateNo);
printf("\n\t Enter parking Time(In hours) = ");
scanf("%d",&ptrd->parkingTym);
printf("\n\t Enter parking Slot = ");
scanf("%d",&ptrd->parkSlot);
fflush(stdin);
printf("\n\tWhat is the vehicle type (C/V)?");
scanf("%c",&type);
if(type=='c')
{ int addi=50;
addi=addi+( (ptrd->parkingTym-2)*20) ;
ptrd->chrgDetails=addi;
}
if(type=='v')
{ int addi=60;
addi=addi+( (ptrd->parkingTym-2)*25) ;
ptrd->chrgDetails=addi;
}
printf("\n\n\t\Enter time Of Arrival -: ");
scanf("%d",&ptrd->tymOfArrival);
printf("\n\n\t\Enter time Of Departure -: ");
scanf("%d",&ptrd->tymOfDepart);
/*printf("\n\n\tEnter duration; -: ");
scanf("%d",&ptrd->duration);
printf("\n\n\t\Enter ttlCharge -: ");
scanf("%f",&ptrd->ttlCharge);
printf("\n\n\t\Enter noOfTymMove; -: ");
scanf("%d",&ptrd->noOfTymMove); */
push(s,d);
}
void welcome()
{
printf("\n\t ===========================================================");
printf(" \n\t ++++++++++++ PREMADASA CAR PARK SYSTEM +++++++++++++++++ " );
printf("\n\t ===========================================================");
printf(" \n\n\n\n\n\n\t\t\t !!! WELCOME !!! " );
printf(" \n\n\n\n\n\n\t\t\t Press Enter to LOGIN " );
getch();
}
10
Part B
1. Programe code
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
/*-------------------Structures------------------*/
typedef struct burstime
{
char taskname[20];
int time;
burstime *next;
burstime *prev;
};
typedef struct list
{
burstime *head;
int count;
};
//this is the structure which saves the details about the burst time
/*-------------------Functions------------------*/
void init(list*);
burstime* makenode(list*,char taskname[],int time);
void addtorearposi(list*,char taskname[],int time);
void print(list*);
void printtasks(list*);
int checkifcorrect(char time);
/*-------------------main Function------------------*/
main()
{
char cont;
list l;
init(&l);
// initializing Function
do
{
char taskname[20];
char t,time[10]={NULL};
int sum=0,i,d,x=0;
clrscr();
printf("\n\t ================== Round Robin Algorithm
===================");
printf("\n\n\n\t Burst Time Calculation ");
fflush(stdin);
printf("\n\n\n\n\t\t1) Enter The Task Name of the process -:");
gets(taskname);
11
printf("\n\n\n\t\t2) Enter The Burst Time To Complete The above Task %s -:",
taskname);
gets(time);
for(i=0; time[i]!='\0'; i++)
{
x=checkifcorrect(t=time[i]);
sum=sum+x;
}
if(sum==0)
{
d=atoi(time);
addtorearposi(&l,taskname,d);
}
else
{
printf("\n\n\n\t\t\tError:- Wrong Burst Time value Entered");
}
printf("\n\n\n\n\t\tDo you want to continue(Y/N):-");
fflush(stdin);
scanf("%c",&cont);
printf("\n");
}while((cont=='y')||(cont=='Y'));
clrscr();
printf("\n\t ================== Round Robin Algorithm
===================");
printtasks(&l);
print(&l);
}
/*-------------------initializing Function------------------*/
void init(list *p)
{
p->head=NULL;
p->count=-1;
}
/*-------------------checkcorrect Function------------------*/
int checkifcorrect(char y)
{
int asc,x;
asc=toascii(y);
if((asc>=48) && (asc<=57))
x=0;
else if(asc==0)
x=0;
else
x=2;
return x;
}
12
/*-------------------makenode Function------------------*/
burstime* makenode(char taskname[] ,int time)
{
burstime *n;
n=(burstime*)malloc(sizeof(burstime));
strcpy(n->taskname,taskname);
n->time=time;
n->next=NULL;
n->prev=NULL;
return(n);
}
/*-------------------addtorear Function------------------*/
void addtorearposi(list *p,char taskname[] ,int time)
{
burstime *n,*i;
n=makenode(taskname,time);
if(p->head==NULL)
p->head=n;
else
{
for(i=p->head; i->next!=NULL; i=i->next);
{
i->next=n;
n->prev=i;
}
}
p->count++;
}
/*-------------------printtasksandtime Function------------------*/
void printtasks(list *p)
{
int x=0;
burstime *i;
printf("\n\n\t
============================================================");
printf("\n\t |\t Task Name \t \t| \t\t Burst Time |");
printf("\n\n\t
============================================================");
for(i=p->head; i!=NULL; i=i->next)
13
{
x++;
printf("\n\t\t%d) %s \t\t\t\t %d ",x, i->taskname,i->time);
}
}
/*-------------------printcompletedtasks Function------------------*/
void print(list *p)
{
int x=0;
burstime *i;
int newtime;
printf("\n\n\t ### The order of completed Tasks");
do
{
for(i=p->head; i!=NULL; i=i->next)
{
if(i->time<=4)
{
if(i==p->head)
{
x++;
printf("\n\n\t\t\t%d) %s",x, i->taskname);
p->head=i->next;
free(i);
p->count--;
}
else if(i->next==NULL)
{
x++;
printf("\n\n\t\t\t%d) %s",x, i->taskname);
i->prev->next=NULL;
free(i);
p->count--;
}
else
{
14
x++;
printf("\n\n\t\t\t%d) %s",x, i->taskname);
i->next->prev=i->prev;
i->prev->next=i->next;
free(i);
p->count--;
}
}
else
{
printf("\n\n\t\t\t%d) %s",x, i->taskname);
newtime=i->time-4;
i->time=newtime;
}
}
}while(p->count>-1);
}
15
Part B
2. Programe code
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<conio.h>
/*-------------------Structures------------------*/
typedef struct waitingtime
{
char taskname[20];
int time;
waitingtime *next;
};
/*-------------------Function Headers------------------*/
typedef struct list
{
waitingtime *head;
};
void initial(list*);
waitingtime* makenode(char name[],int);
void addrear(list*,char name[],int);
void waitingtimeprint(list*);
int correction(char time);
void enterdetailsprint(list*);
/*-------------------main Function------------------*/
void main()
{
char cont;
int i,x,s;
list l;
initial(&l);
do
{
char name[20];
char time[10];
int sum=1;
clrscr();
16
printf("\n\t
printf("\n\t
printf("\n\t
----------------------------------------------------");
Calculating Wating Time Time");
----------------------------------------------------");
fflush(stdin);
printf("\n\n\n\n\t\t1) Enter task name :");
gets(name);
printf("\n\n\n\t\t2) Enter required time to complete task %s :", name);
gets(time);
for(i=0; time[i]!='\0'; i++)
{
x=correction(time[i]);
/*call correction
Function*/
sum=sum*x;
}
if(sum==1)
{
s=atoi(time);
addrear(&l,name,s);
else
{
printf("\n\n\n\t\t\tError:- Wrong Time value Entered");
}
printf("\n\n\t ----------------------------------------------------");
printf("\n\n\n\n\t\tDo you want to continue(Y/N):-");
fflush(stdin);
scanf("%c",&cont);
printf("\n");
} while((cont=='y')||(cont=='Y'));
clrscr();
printf("\n\n\t ----------------------------------------------------");
printf("\n\t
Calculating Wating Time Time");
printf("\n\t ----------------------------------------------------");
enterdetailsprint(&l);
waitingtimeprint(&l);
17
/*-------------------initial Function------------------*/
void initial(list *p)
{
p->head=NULL;
}
/*-------------------correction Function------------------*/
int correction(char y)
{
int asc,x;
asc=toascii(y);
/*convertion to ascii*/
return(n);
}
/*-------------------addrear Function------------------*/
void addrear(list *p,char name[],int t)
{
waitingtime *n,*i;
n=makenode(name,t);
/*call makenode Function*/
if(p->head==NULL)
18
p->head=n;
/*New node linked with head*/
else
{
for(i=p->head; i->next!=NULL; i=i->next);
{
i->next=n;
}
}
}
void enterdetailsprint(list *p)
{
waitingtime *i;
int x=0;
/*printing user entered details*/
printf("\n\n\n\n\t\tUser Entered Details");
printf("\n\t\t--------------------");
for(i=p->head; i!=NULL; i=i->next)
{
x++;
printf("\n\n\t\t%d) %s ----> %d",x,i->taskname,i->time);
printf("\n\t\t--------------------------------------");
}
}
/*------------------waitingtimeprint Function------------------*/
void waitingtimeprint(list *p)
{
int x=0;
waitingtime *i,*j;
printf("\n\n\n\n\t\tThe Task Name And Wating Time");
printf("\n\t\t------------------------------");
printf("\n");
19
}
else
{
int sum=0;
for(j=p->head; j!=i; j=j->next)
{
sum=sum+j->time;
}
printf("\n\n\t\t%d) %s ----> %d",x,j->taskname,sum);
printf("\n\t\t--------------------------------------");
}
}
}
20