hi everyone
i have a courswork and i start to write this
Data Structure
Create a data structure suitable for storing data for a list of appointments. Each appointment record should include the following fields:
Field Field data type
• Person name string
• Appointment descriptions (e.g. Lunch) string
• Appointment Date structure
• day integer
• month integer
• year integer
• Time string
The program should be menu driven and allow the user to interactively select and perform the following tasks:
1. Add details of one or more appointments to the appointment structure;
a) Add validation to step1
• Check if there is enough room in the structure to accommodate the appointment record(s) you want to add;
• Check if there is an appointment on the same date and time.
(Obviously you can have several appointments on the same day at different
times, and for the same time on different days.)
• In case of failure of any of the above checks the program should print an appropriate warning message and not proceed with the operation.
2. Edit an appointment: change the person name or the appointment description but not the Time or Date;
3. Delete an appointment;
• Search for the appointment in appointments structure using the appointment date and time;
• Delete the appointment by shifting the records following the record to be deleted upwards;
4. Display appointments details:
a) For a certain date;
b) All appointments
Appointments should be displayed under the following header:
Person Appointment Appointment Appointment
Name Description Date Time
5. Write appointments list records to a file;
• Store each appointment record fields as follows:
person name
appointment description
appointment time
day month year
Each line should be followed by a new line character (i.e. use endl or '\n' )
6. Read appointments list records from a file;
• Data must be read in the same order it was written.
• Note: you need to read a character left in the input buffer after reading each record (use: infile.get( ) ) so that data is read properly.
7. Quit program.
Your program should be modular by developing separate functions for the above tasks. Comment your program. Each function should have at least one comment saying what the function does
#include <iostream>
#include<iomanip>
#include <cstdlib>
#include <string>
usingnamespace std;
//declare structure types
struct AppointmenRecord{
string name;
string description;
double date;
double time;
};
constint listSize = 30; //number of records in array
int currentSize = 0;
//declare a list of records.
AppointmenRecord AppointmenList[listSize]; //global array of records
// Functions prototypes.
void addAppointmenRecords( );
void displayAllRecords( );
void editAppointmen( );
void displayMenu(int &option);
void main( )
{
int option;
bool endOfSession = false;
//get user action choice
while (!endOfSession)
{
displayMenu(option);
switch (option)
{
case 1: addAppointmenRecords( );
break;
case 2: displayAllRecords( );
break;
//case 3: editAppointmenRecords( );
break;
case 4: system("cls");
cout<<"\nEND OF SESSION\n\n";
endOfSession = true;
break;
default: cout<<endl<<"Wrong option number!! Try again\n";
}
}
}
void displayMenu(int &option)
{ // display menu options and choose one
system("cls"); //clear screen
cout<<endl<<endl;
cout<<"\t * APPOINTMENTS DATA MENU *"<<endl<<endl;
cout<<"\t 1. Add An Appointmen record(s)"<<endl;
cout<<"\t 2. Display All Appointmens records"<<endl;
cout<<"\t 3. Edit An Appointmen record(s)"<<endl;
cout<<"\t 4. End Session"<<endl;
cout<<endl<<setw(28)<<"Enter option number: ";
cin>>option;
cin.get();
}
void addAppointmenRecords( )
{
int number, i;
system("cls"); //clear screen
cout<<"\nHow many Appointmen you wish to add? ";
cin>>number;
cin.get(); //read newline character left in the buffer
if( (number + currentSize ) <= listSize) //There is still room in the array
for( i = 1; i<=number; i++)
{
cout<<"\nEnter Person name: ";
getline(cin, AppointmenList[currentSize].name);
cout<<"Enter Appointmen Descriptions: ";
cin>>AppointmenList[currentSize].description;
cout<<"Enter Appointmen date: ";
cin>>AppointmenList[currentSize].date;
cout<<"Enter Appointmen time: ";
cin>>AppointmenList[currentSize].date;
cout<<endl;
cin.get(); //read newline character left in the buffer
currentSize += 1;
}
else
cout<<"Overflow!!!! Appointmen List is full"<<endl;
cout<<"\nPress any key to continue"<<endl;
cin.get(); //read a character
}
void displayHeading( )
{
cout<<setiosflags(ios::left); //left justify output
cout<<endl<<setw(20)<<"Name"
<<setw(20)<< "Descriptions"
<<setw(12)<<"Date"
<<setw(15)<<"Time"<<endl;
}
void displayAllRecords( )
{ /* print the data from the array of records under a suitable header*/
int index;
system("cls");
displayHeading();
cout<<setiosflags(ios::left); //left justify output
for (index = 0; index < currentSize; index++)
{
cout<<setw(20)<<AppointmenList[index].name;
cout<<setw(15)<<AppointmenList[index].description;
cout<<setw(12)<<AppointmenList[index].date;
cout<<setw(12)<<AppointmenList[index].time<<endl;
}
//give the user a chance to read the output data
cout<<endl<<"Press any character to continue ";
cin.get(); //read entered character
}
am i on the write way????
if i am doing wrong can yous tell me your recommendation??/
thanks...