DBDS - APIIT
-
Upload
malith-waniganayake -
Category
Documents
-
view
220 -
download
0
Transcript of DBDS - APIIT
-
7/30/2019 DBDS - APIIT
1/20
ASIA PACIFIC INSTITUTE OF INFORMATION TECHNOLOGY
APIIT Diploma Part I
Group Assignment
Data Bases and Data Structures
Prepared By
Malith Waniganayake CB004144
Hishara Silva CB004160
Harin Fernando CB004134
Module Code & TitleAAPP001-3-2-DBDS
CohortDF10A1ICT
Date of Submission
05-05-2011
Instructor
Mr.Udesh Amarasinghe
Submitted in partial fulfilment for the degree of
Bachelor of Scence (Hons) in Computing
http://apiit.edu.my/ -
7/30/2019 DBDS - APIIT
2/20
2
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.
-
7/30/2019 DBDS - APIIT
3/20
3
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.
-
7/30/2019 DBDS - APIIT
4/20
4
WORK BREAKDOWN STRUCTURE
STUDENT NAME PART A PART B
1 2
Malith Waniganayake 33% 33% 33%
Harin Fernando 33% 33% 33%
Hishara Silva 33% 33% 33%
TOTAL 100% 100% 100%
-
7/30/2019 DBDS - APIIT
5/20
5
Part A
Program Code
#include
#include#define MAX 10#include
/*-------------------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); /*call inisializing Function*/
do
{
-
7/30/2019 DBDS - APIIT
6/20
6
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 Enter car slot?:-");
-
7/30/2019 DBDS - APIIT
7/20
7
int carslot;
scanf("%d",&carslot);
details ptrd;
details *ptr;
ptrd=pop(s,carslot);
ptr=&ptrd;
printf("\n\t\tDo you want to print the Bill ? (Y/N)");flushall();
scanf("%c",&lev);
clrscr();
if(lev=='y'||lev=='Y')
{printf("\n\n\t\t----------------------------------");
printf("\n\n\t\t\t Bill Details");
printf("\n\n\t\t----------------------------------");
printf("\n\n\n\t\tTotal charge=%d",ptr->chrgDetails);
printf("\n\t\tParked Hours=%d",ptr->parkingTym);printf("\n\t\tMoved times= %d",ptr->noOfTymMove);printf("\n\t\tTime of arrival =%d",ptr->tymOfArrival);
printf("\n\n\t\tTime of Departure =%d",ptr->tymOfDepart);
}
}
void print(stack *s)
{
clrscr();
printf("\t ==============================================");
printf("\n\t | Parking Position \t| Plate Number |");
printf("\n\t ==============================================");
for(int i=0; itop;i++){
details d=s->ele[i];
details *ptrd=&d;
printf("\n\t |\t %d \t\t| %d \t |",i+1,ptrd->plateNo);
}
printf("\n\t ==============================================\n");
printf(" \n\n\t Press Enter ");
getch();
}
/*-------------------inisializing Function------------------*/
void inisializing(stack *s){
s->top=-1; /*top inisializing to -1*/
}
/*-------------------isfull Function------------------*/
int isfull(stack *s)
{
if(s->top>MAX)
return 1;
-
7/30/2019 DBDS - APIIT
8/20
8
else
return 0;
}
/*-------------------isempty Function------------------*/
int isempty(stack *s)
{
if(s->toptop++;
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;ktop;k++)
{
details d1=s->ele[k];details *d2;
d2= &d1;
d2->noOfTymMove=+1;
s->ele[k-1]=d1;}
-
7/30/2019 DBDS - APIIT
9/20
9
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); /*call push Function*/
}
void welcome()
-
7/30/2019 DBDS - APIIT
10/20
10
{
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();
}
-
7/30/2019 DBDS - APIIT
11/20
11
Part B
1. Programe code#include
#include
#include#include
#include
#include
/*-------------------Structures------------------*/
typedef struct burstime
{
char taskname[20];
int time;
burstime *next; //this is the structure which saves the details about the burst time
burstime *prev;
};
typedef struct list
{
burstime *head; // this is the structre listint count;
};
/*-------------------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);
-
7/30/2019 DBDS - APIIT
12/20
12
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
-
7/30/2019 DBDS - APIIT
13/20
13
/*-------------------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)
-
7/30/2019 DBDS - APIIT
14/20
14
{
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->timehead)
{
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{
-
7/30/2019 DBDS - APIIT
15/20
15
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);
}
-
7/30/2019 DBDS - APIIT
16/20
16
Part B
2. Programe code#include
#include
#include#include
#include
#include
/*-------------------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); /*call initial Function*/
do
{
char name[20];
char time[10];
int sum=1;
clrscr();
-
7/30/2019 DBDS - APIIT
17/20
17
printf("\n\t ----------------------------------------------------");
printf("\n\t Calculating Wating Time Time");
printf("\n\t ----------------------------------------------------");
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); /*call addrear Function*/
}
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); /*call enterdetailsprint Function*/
waitingtimeprint(&l); /*call waitingtimeprint Function*/
}
-
7/30/2019 DBDS - APIIT
18/20
18
/*-------------------initial Function------------------*/
void initial(list *p)
{
p->head=NULL; /*initializing head to Null*/
}
/*-------------------correction Function------------------*/
int correction(char y)
{
int asc,x;
asc=toascii(y); /*convertion to ascii*/
if((asc>=48) && (asctaskname,name); /*making a node and adding values*/
n->time=t;
n->next=NULL;
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)
-
7/30/2019 DBDS - APIIT
19/20
19
p->head=n;
/*New node linked with head*/
else
{
for(i=p->head; i->next!=NULL; i=i->next);{
i->next=n; /*New node link with a node*/
}
}
}
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"); /*Printing the task waiting waiting time*/
for(i=p->head; i!=NULL; i=i->next)
{
x++;
if(i==p->head)
{
printf("\n\n\t\t%d) %s ----> 0",x,i->taskname);printf("\n\t\t--------------------------------------");
-
7/30/2019 DBDS - APIIT
20/20
}
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--------------------------------------");
}
}
}