Write C++ program for storing appointment schedule for day. Appointments are booked randomly using linked list. Set start and end time and min and max duration for visit slot. Write functions for- a)Display free slots b)Book appointment c)Cancel appointment ( check validity, time bounds, availability etc) d)Sort list based on time e)Sort list based on time using pointer manipulation

Write C++ program for storing appointment schedule for day. Appointments are booked
randomly using linked list. Set start and end time and min and max duration for visit slot.
Write functions for-
a)Display free slots
b)Book appointment
c)Cancel appointment ( check validity, time bounds, availability etc)
d)Sort list based on time
e)Sort list based on time using pointer manipulation.

OUTPUT FOR THE PROGRAM
#include<iostream>
#include<string.h>
using namespace std;
int nodes;
struct appoint
{
int status;
char start[10];
char end[10];
char max[10];
char min[10];
struct appoint *Next;
}*head;

void create_app()
{
    int i ;
    appoint *temp, *p;
 
    head = NULL;
 
    cout<<"\n\n How many Appointments";
    cin>>nodes;
 
    for(i=0; i<nodes; i++)
    {
    cout<<" NEW APPOINTMENT ";
       temp = new(struct appoint); //Step 1: Allocate Memory
   temp->status=0;
 
       cout<<"\n\t Enter Start Time: "; //Step 2: Store data and address
       cin>>temp->start;
       cout<<"\n\t Enter End Time: "; //Step 2: Store data and address
       cin>>temp->end;
       cout<<"\n\t Enter min Time: "; //Step 2: Store data and address
       cin>>temp->min;
       cout<<"\n\t Enter max Time: "; //Step 2: Store data and address
       cin>>temp->max;
     
       temp->Next = NULL;
 
       if(head == NULL) //Step 3: Attach node in linked List
       {
          head = temp;
          p = head;
       }
       else
       {
          p->Next = temp;
          p = p->Next;
       }
 
    } 
 
}

void display_SLL()
{
  appoint *p;
 
    p = head;
    cout<<"Status\tStart Time\tEnd Time\tMin Time\tMax Time\n";
    while(p != NULL)
    {
    if(p->status==0)
    {
    cout<<"Free";
    }
    else
    {
    cout<<"Booked";
}
       cout<<"\t\t"<<p->start<<"\t\t"<<p->end<<"\t\t"<<p->min<<"\t\t"<<p->max<<"\t\n";
       p = p->Next;
    }

}
void book_app()
{
char time[10];
struct appoint *p;
cout<<"\n\n\tEnter The Time Slot";
cin>>time;
p=head;
while(p!=NULL)
{
if(strcmp(time,p->start) == 0)
{
if(p->status == 0)
{
p->status=1;
cout<<"Your Appointment Is Booked\n\n";
}
else
cout<<"Appointment slot is Busy\n\n";
break;
}
else
p=p->Next;
}

if(p==NULL)
cout<<"\n\n Appointment slot is Not available\n\n";
display_SLL();

}

void cancel_app()
{
char time[10];
struct appoint *p;
cout<<"\n\n\tEnter Cancellation Time";
cin>>time;
p=head;
while(p!=NULL)
{
if(strcmp(time,p->start) == 0)
{
if(p->status == 1)
{
p->status=0;
cout<<"Your Appointment Is Cancelled\n\n";
}
else
cout<<"Appointment slot is Busy\n\n";
break;
}
else
p=p->Next;
}

if(p==NULL)
cout<<"\n\n Appointment slot is Not available\n\n";
display_SLL();


}

void sort_app()
{
char str[10];
struct appoint *p;
int i;
for(i=0;i<nodes-1;i++)
{
p = head;
while(p->Next!=NULL)
{
if(strcmp(p->start,p->Next->start)>0)
{
int tmp=p->status;
p->status=p->Next->status;
p->Next->status=tmp;

strcpy(str,p->start);
strcpy(p->start,p->Next->start);
strcpy(p->Next->start,str);

strcpy(str,p->end);
strcpy(p->end,p->Next->end);
strcpy(p->Next->end,str);

strcpy(str,p->min);
strcpy(p->min,p->Next->min);
strcpy(p->Next->min,str);

strcpy(str,p->max);
strcpy(p->max,p->Next->max);
strcpy(p->Next->max,str);
}
p=p->Next;
}
}
cout<<"\n\nSORTED\n";
display_SLL();
}


int main()
{
create_app();

display_SLL();

book_app();

cancel_app();

sort_app();

return 0;
}
     

For more such posts click the link:-http://svencrai.com/G8W

Comments

Popular posts from this blog

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message ?Required copies not in stock? is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system

Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members.