Databases and Data Structures [Individual Assignment]

download Databases and Data Structures [Individual Assignment]

of 37

Transcript of Databases and Data Structures [Individual Assignment]

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    1/38

    1 | P a g e

    Asia Pacific Institute of Information Technology

    Databases and Data Structures AAPP001-3-2

    Cover Page

    Group Project

    Student declaration:

    I declare that:

    yWe understand what is meant by plagiarismyThe implication of plagiarism have been explained to us by our lectureryThis project is all our work and I have acknowledged any use of the published or

    unpublished works of other people.Group Leaders Signature:

    Date:17/09/2009

    Total number of pages including this cover

    page: Class Code: DF 0931 ICT

    Submission

    Date:July 29 ,2009 Due Date: September 17, 2009

    Students'

    Full Names

    Leader:

    Praveena Sarathchandra (CB003403)

    Members:

    Pulasthi Perera (CB003472)

    Total number of pages including this cover page:

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    2/38

    2 | P a g e

    Table of Contents

    Acknowledgement .................................................................................................................... 3

    Introduction .............................................................................................................................. 4

    Project Description .................................................................................................................... 5

    Implementation of Link Lists .................................................................................................. 5

    Implementation of Circular Queue......................................................................................... 6

    Critical Evaluation......................................................................... Error! Bookmark not defined.

    Appendices ............................................................................................................................... 7

    Sourse code .............................................................................. Error! Bookmark not defined.

    Bibliography ........................................................................................................................ 19

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    3/38

    3 | P a g e

    Acknowledgement

    First of all we sincerely thank our lecturer Mr. Udesh Amarasinghe for his continuous

    guidance and support in the preparation of this report. With the thorough guidance andexpertise that we gained from him we are able to properly get a clear idea of what we

    had to do in this project.

    We also would like contribute our thanks to the computer laboratories and the library of

    the Asia Pacific Institute of Information Technology, for basically providing us with

    necessary Internet facilities and reference facilities for this project.

    We sincerely thank our friends who had always been around to support us. And alsowould like to express or sincere gratitude for all people who gave their immense support

    to make this project success.

    Last but not least we have to thankful for our family members who make us free from allthe duties, which help us to finish this project on time.

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    4/38

    4 | P a g e

    Introduction

    This project had been taken out as an objective of completion of the project assigned for

    the module Database and Data Structures, According to the requirements highlighted in

    the project. The two scenarios covered in the project were covered accordingly using the

    knowledge gained throughout the module.

    We were implementing and develop the program successfully during the time period.

    The first part of the project was implementing a program to handle the emergency room

    in a hospital using C programming language. This part check the knowledge of link lists

    in the module and the next part was covered using the knowledge of circular queues. In

    here we have to implement and develop the program to handle paki9ng of vehicles in a

    car park.

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    5/38

    5 | P a g e

    Project Description

    Implementation of Link Lists

    The project is based on a patient scheduling system of an emergency room of a hospital.I had to use linked lists in C programing language for implementation.

    In this program there are six options in the main menu. They are to add a new patient tothe end of the list, add patients to the beginning of the list, move patient to front, printthe entire list, and Remove a node from the list and to exit from the program.

    The program has to be user friendly and user can be able to use the functions of thisprogram easily without any complexity.

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    6/38

    6 | P a g e

    Implementation of Circular Queue

    In this task we where assign to make a car park system with a pre define size of 10.

    The main idea is to keep track of all vehicles which are two types vans and cars so thatnecessary billing can be done

    What we have done is a menu driven application which as all the functions such asadding, remove, delete and calculating billing are one of the main functions available.

    As this is a queue the counter the increase when a vehicle is removed.

    In case user miss enters the license number to re-edit it without removing we haveincluded an addition function to the system where the user enters the miss enteredlicense number and replace it by entering the real license number.

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    7/38

    7 | P a g e

    Appendices

    Source Codes

    Linked Lists

    #include

    #include

    #include

    #include

    #include

    int id=100;

    struct list{

    int id;

    char name[20];

    int age;

    int cstate;

    char ail[20];

    struct list *next;

    }*head;

    void menu();

    void initialize();

    void addPatientF();

    void addPatientT();

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    8/38

    8 | P a g e

    void preempt();

    void display();

    void removenode(struct list *head);

    main(){

    int choice;

    struct list *head;

    head = NULL;

    initialize();

    do{

    menu();

    scanf("%d", &choice);

    switch(choice){

    case 1:

    addPatientT();

    break;

    case 2:

    addPatientF();

    break;

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    9/38

    9 | P a g e

    case 3:

    preempt();

    break;

    case 4:

    display();

    break;

    case 5:

    removenode(&head);

    break;

    case 6:

    exit(0);

    break;

    default:

    printf("Wrong input");

    getch();

    }

    }while(choice != 5);

    if(choice ==5){

    exit(1);

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    10/38

    10 | P a g e

    }

    }

    void initialize(){

    head = NULL;

    }

    void addPatientF(){

    struct list *newnode;

    char name[20];

    int age;

    int cstate;

    char ail[20];

    clrscr();

    printf("Enter New Patient details\n\n");

    printf("ID: %d", id++);

    printf("\n--------Enter new patient details---------\n\n");

    printf("\tName: ");

    fflush(stdin);

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    11/38

    11 | P a g e

    gets(name);

    printf("\n\tAge: ");

    fflush(stdin);

    scanf("%d", &age);

    printf("\n\tCritical State: (Rate 0-3)");

    fflush(stdin);

    scanf("%d", &cstate);

    printf("\n\tAilment: ");

    fflush(stdin);

    gets(ail);

    newnode = (struct list*)malloc(sizeof(struct list));

    newnode->id = id;

    strcpy(newnode->name, name);

    newnode->age = age;

    newnode->cstate = cstate;

    strcpy(newnode->ail, ail);

    if(head == NULL){

    head = newnode;

    head->next = NULL;

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    12/38

    12 | P a g e

    } else {

    newnode->next = head;

    head = newnode;

    }

    }

    void addPatientT(){

    struct list *newnode;

    struct list *tmp = head;

    char name[20];

    int age;

    int cstate;

    char ail[20];

    clrscr();

    printf("Enter New Patient details\n\n");

    printf("ID: %d", id++);

    printf("\n--------Enter new patient details---------\n\n");

    printf("\tName: ");

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    13/38

    13 | P a g e

    fflush(stdin);

    gets(name);

    printf("\n\tAge: ");

    fflush(stdin);

    scanf("%d", &age);

    printf("\n\tCritical State: (Rate 0-3)");

    fflush(stdin);

    scanf("%d", &cstate);

    printf("\n\tAilment: ");

    fflush(stdin);

    gets(ail);

    newnode = (struct list*)malloc(sizeof(struct list));

    newnode->id = id;

    strcpy(newnode->name, name);

    newnode->age = age;

    newnode->cstate = cstate;

    strcpy(newnode->ail, ail);

    newnode->next=NULL;

    if(head == NULL){

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    14/38

    14 | P a g e

    head = newnode;

    head->next = NULL;

    } else {

    newnode->next = NULL;

    while(tmp->next != NULL){

    tmp = tmp->next;

    }

    tmp->next = newnode;

    }

    }

    void menu(){

    clrscr();

    printf("\n1. Add new patient to the end");

    printf("\n2. Add new patient to the beginning");

    printf("\n3. Move patient to front");

    printf("\n4. Print out the entire list");

    printf("\n5. Remove a node from the list");

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    15/38

    15 | P a g e

    printf("\n6. Quit the program\n\n");

    }

    void display(){

    struct list *temp;

    temp = head;

    if(temp == NULL){

    printf("List empty");

    }

    while(temp != NULL){

    printf("\t\n%d\n", temp->id);

    printf("Name: %s\n", temp->name);

    printf("Critical State: %d\n", temp->cstate);

    printf("Ailement: %s\n", temp->ail);

    temp = temp->next;

    }

    getch();

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    16/38

    16 | P a g e

    }

    void removenode(struct list *head){

    int id;

    int found=0;

    struct list *current = head;

    printf("Enter ID: ");

    fflush(stdin);

    scanf("%d", &id);

    while(current->next != NULL) {

    if(current->id == id){

    found++;

    break;

    }

    current = current->next;

    }

    if(found == 0){

    printf("No patient found for that ID");

    }

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    17/38

    17 | P a g e

    free(current);

    getch();

    }

    void preempt(){

    struct list *tmp, *current;

    int id;

    tmp = head;

    printf("\nEnter patient ID :");

    scanf("%d", &id);

    while(tmp->id != id){

    current = tmp;

    tmp = tmp->next;

    if(tmp == NULL){

    printf("End of list");

    break;

    }

    }

    current->next = tmp->next;

    tmp->next = head;

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    18/38

    18 | P a g e

    head = tmp;

    //printf("%s", tmp->name);

    getch();

    }

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    19/38

    19 | P a g e

    Queues

    /*

    ABC CAR PARK SYSTEM v1.0

    ORGINALLY CODED BY - Praveena Sarathchandra on 17th

    September 2009

    2009

    */

    #include

    #include

    #include

    #include

    #include

    #include

    #include

    #define MAX 10

    struct cars{

    int plateno;

    time_t intime;

    int moved;

    char vtype;

    };

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    20/38

    20 | P a g e

    struct queue{

    int front;

    int rear;

    int count;

    struct cars newq[MAX];

    }mainq;

    //**************FUNCTION PROTOTYPES*******************\\

    void header();

    void menu();

    void showInput(struct queue *mainq);

    void input(struct queue *mainq, int plate, char type, time_t intime, char vtype);

    void init(struct queue *mainq);

    void display(struct queue *mainq);

    void printReceipt(struct queue *mainq, char type, int plate, time_t inTime, int slot, char

    vtype);

    void fullMsg();

    void emptyMsg();

    main(){

    int choice;

    init(&mainq);

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    21/38

    21 | P a g e

    do{

    menu();

    scanf("%d", &choice);

    switch(choice){

    case 1:

    showInput(&mainq);

    break;

    case 2:

    display(&mainq);

    break;

    }

    }while(choice != 3);

    if(choice == 3)

    exit(1);

    }

    //**************FUNCTION DECLARATION*******************\\

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    22/38

    22 | P a g e

    void menu(){

    clrscr();

    header();

    printf("\n\t\t1. Input Vehicle info\n");

    printf("\t\t2. Show Stats\n");

    printf("\t\t3. Exit\n\n");

    printf("\n\n\t\tEnter Choice : ");

    }

    void header(){

    printf("\n\t\t************************************************* ");

    printf("\n\t\t------------- ABC VEHICLE PARK -----------------\n");

    printf("\t\t*************************************************\ n\n");

    }

    void showInput(struct queue *mainq){

    int plate;

    char type;

    char vtype;

    time_t intime;

    clrscr();

    header();

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    23/38

    23 | P a g e

    printf("\n\t\tArrival(a) / Departure(d): ");

    fflush(stdin);

    scanf("%c", &type);

    type = tolower(type);

    switch(type){

    case 'a':

    if(mainq->count >=10){

    fullMsg();

    } else {

    clrscr();

    header();

    printf("\t\t\t [Enter Vehicle details]\n\n");

    printf("\t\tEnter vehicle type (Car - c, Van - v):");

    fflush(stdin);

    scanf("%c", &vtype);

    vtype = tolower(vtype);

    printf("\t\tLicense Plate No:");

    fflush(stdin);

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    24/38

    24 | P a g e

    scanf("%d", &plate);

    intime = time(NULL);

    input(mainq, plate, 'a', intime, vtype);

    }

    break;

    case 'd':

    time_t timenow;

    clrscr();

    header();

    printf("\n\t\t\t[Enter Vehicle details]\n\n");

    printf("\t\t\tLicense Plate No:");

    fflush(stdin);

    scanf("%d", &plate);

    timenow = time(NULL);

    input(mainq, plate, 'd', timenow,NULL );

    break;

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    25/38

    25 | P a g e

    }

    }

    void init(struct queue *mainq){

    mainq->front = 0;

    mainq->rear = -1;

    mainq->count = 0;

    for(int i=0;inewq[i].plateno = 0;

    mainq->newq[i].intime = 0;

    mainq->newq[i].moved = 0;

    }

    }

    void input(struct queue *mainq, int plate, char type, time_t intime, char vtype){

    int i=0,j=0;

    time_t outTime;

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    26/38

    26 | P a g e

    switch(type){

    case 'a':

    mainq->newq[++mainq->rear].plateno = plate;

    mainq->newq[mainq->rear].intime = intime;

    mainq->newq[mainq->rear].vtype = vtype;;

    mainq->count++;

    printReceipt(mainq, 'a', plate, intime, mainq->rear+1, vtype);

    getch();

    break;

    case 'd':

    i=0;

    //get the index for the given plate #

    while(mainq->newq[i].plateno != plate){

    i++;

    }

    outTime = time(NULL);

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    27/38

    27 | P a g e

    if(i == 0){

    for(j=i+1; jrear ; j++){

    mainq->newq[j-1].plateno = mainq-

    >newq[j].plateno;

    mainq->newq[j-1].moved = mainq-

    >newq[j].moved;

    mainq->newq[j-1].moved +=1;

    mainq->newq[j-1].intime = mainq-

    >newq[j].intime;

    }

    mainq->rear--;

    } else if( (i > 0) && (i < mainq->rear)) {

    for(j=0;jnewq[j].moved++;

    }

    for(j=i+1; jrear ; j++){

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    28/38

    28 | P a g e

    mainq->newq[j-1].plateno = mainq->newq[j].plateno;

    mainq->newq[j-1].moved = mainq->newq[j].moved;

    mainq->newq[j-1].moved +=1;

    mainq->newq[j-1].intime = mainq->newq[j].intime;

    mainq->newq[j].plateno = 0;

    mainq->newq[j].moved= 0;

    mainq->newq[j].intime=0;

    }

    mainq->rear--;

    }else if( i == mainq->rear){

    mainq->newq[i].plateno = 0;

    mainq->newq[i].moved= 0;

    mainq->newq[i].intime=0;

    mainq->rear--;

    }

    mainq->count--;

    printReceipt(mainq, 'd', plate, outTime, mainq->rear+1, mainq-

    >newq[i].vtype);

    getch();

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    29/38

    29 | P a g e

    break;

    }

    }

    void display(struct queue *mainq){

    if(mainq->count == 0){

    emptyMsg();

    } else {

    clrscr();

    header();

    for(int i=0;irear;i++){

    printf("\n\t\t-------SLOT %d--------\nLICENSE PLATE #%d \nVehicle

    type: %c \nTIME IN: %s \nMOVED TIMES: %d\n", i, mainq->newq[i].plateno, mainq-

    >newq[i].vtype, asctime(localtime(&mainq->newq[i].intime)), mainq->newq[i].moved);

    }

    getch();

    }

    }

    void printReceipt(struct queue *mainq, char type, int plate, time_t inTime, int slot, char

    vtype){

    time_t timeNow;

    timeNow = time(NULL);

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    30/38

    30 | P a g e

    float charge=0;

    float duration;

    float hrs;

    float discount=0;

    float total;

    header();

    switch(type){

    case 'a':

    clrscr();

    header();

    printf("\n\t\t\t ------------------------");

    printf("\n\t\t\t| New Car Added to Queue |");

    printf("\n\t\t\t ------------------------");

    printf("\n\t\tLICENSE PLATE : %d\n", plate);

    printf("\n\t\tVehicle Type: %c\n", vtype);

    printf("\n\t\tTime in: %s\n", asctime(localtime(&inTime)));

    printf("\t\tSlot : #%d\n", slot);

    break;

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    31/38

    31 | P a g e

    case 'd':

    duration = difftime(inTime,mainq->newq[slot].intime);

    switch(vtype){

    case 'c':

    if( duration

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    32/38

    32 | P a g e

    }

    if(mainq->newq[slot].moved > 10){

    discount = charge * (1/100);

    }

    total = charge - discount;

    clrscr();

    header();

    printf("\n\t\tLICENSE PLATE : %d\n", plate);

    printf("\t\tSlot : #%d\n", slot);

    printf("\n\t\tTime in: %s", asctime(localtime(&mainq->newq[slot].intime)));

    printf("\n\t\tTime out: %s", asctime(localtime(&inTime)));

    printf("\n\t\tDuration: %f", duration);

    printf("\n\t\tCharge: %.2f", charge);

    printf("\n\t\tTimes moved: %d", mainq->newq[slot].moved);

    printf("\n\t\tDiscount %.2f:", discount);

    printf("\n\t\t_________________________");

    printf("\n\t\tTOTAL CHARGE: %.2f", total);

    printf("\n\t\t_________________________");

    break;

    }

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    33/38

    33 | P a g e

    }

    void fullMsg(){

    printf("\n\t[THE QUEUE ISFULL]\n");

    getch();

    }

    void emptyMsg(){

    printf("\n\t\t\t[THE QUEUE IS EMPTY]\n");

    getch();

    }

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    34/38

    34 | P a g e

    Bibliography

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    35/38

    35 | P a g e

    WorkLoad Metrix

    Task Praveena Pulasthi

    Preparation and planning

    Analyze the requirements of system

    Design

    Propose a solution

    Research and select appropriate methodology for functions

    Circular Queues implementation

    Linked List implementation

    Development

    Develop necessary modules of the proposed

    system

    Circular Queues implementation

    Linked List implementation

    Testing

    Testing and Debugging

    Documentation and Presentation

    Report and documentation

    Presentation

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    36/38

    36 | P a g e

    ASIA PACIFIC INSTITUTE OF INFORMATION TECHNOLOGY

    AAPP001-3-2-DATABASES & DATA STRUCTURES

    Assignment Marking Scheme

    Group:

    Student Id:

    Criteria

    Marks

    Comments

    Implementation (12 marks)

    y Program logic (3)

    y Validation checks (3)

    y Expected results (3)

    y Workable system (3)

    Efficiency memory utilisation (8 marks)

    y Efficient memory utilisation (4)

    y Modular/ Compact program (3)

    y No user ofunnecessary global

    vars, go to statements etc (2)

    Comprehension (12 marks)

    y Explanation ofcode (4)

    y Capability to debug errors (4)

    y Logic justification (4)

    Assignment contribution (8 marks)

    y Workload distribution (6)

    y Initiative taken (2)

    Total: 40 marks

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    37/38

    37 | P a g e

    ASIA PACIFIC INSTITUTE OF INFORMATION TECHNOLOGY

    AAPP001-3-2-DATABASES & DATA STRUCTURES

    Assignment Marking Scheme

    Group:

    Student Id:

    Criteria

    Marks

    Comments

    Implementation (12 marks)

    y Program logic (3)

    y Validation checks (3)

    y Expected results (3)

    y Workable system (3)

    Efficiency memory utilisation (8 marks)

    y Efficient memory utilisation (4)

    y Modular/ Compact program (3)

    y No user ofunnecessary global

    vars, go to statements etc (2)

    Comprehension (12 marks)

    y Explanation ofcode (4)

    y Capability to debug errors (4)

    y Logic justification (4)

    Assignment contribution (8 marks)

    y Workload distribution (6)

    y Initiative taken (2)

    Total: 40 marks

  • 8/8/2019 Databases and Data Structures [Individual Assignment]

    38/38