Write a C++ program to save the meeting schedule for the day. Appointments are booked randomly using a linked list. Set the start and end time and the minimum and maximum duration of the visit. Enrollment features for- a)Viewing available slots b)Booking an appointment c)Cancelling an appointment (validity check, time limits, availability etc.) d)Sorting the list by time e)Sorting the list by 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

Post a Comment

Previous Post Next Post