1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
#include<fstream>
using namespace std;
//declare structure types
struct date{
int day, mounth ,year;
};
struct AppointmenRecord{
string name;
string description;
date appdate;
string time;
};
const int 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 deleteAppointmenRecords( );
void editAppointmenRecords( );
void displayRecords( );
void searchAppointmenRecords( );
void readAppointmenRecords( );
void writeAppointmenRecords( );
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: deleteAppointmenRecords( );
break;
//case 3: editAppointmenRecords( );
break;
case 4: displayRecords( );
break;
//case 5: searchAppointmenRecords( );
break;
case 6: writeAppointmenRecords( );
break;
case 7: readAppointmenRecords( );
break;
case 8: system("cls");
cout<<"\nEND OF SESSION\n\n";
endOfSession = true;
break;
default: cout<<endl<<"Wrong option number!! Try again\n";
cin.get();
}
}
}
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. Delete An Appointmen Record(s)"<<endl;
cout<<"\t 3. Edit An Appointmen Record(s)"<<endl;
cout<<"\t 4. Display Appointmens Records"<<endl;
cout<<"\t 5. Search An Appointmen Record(s)"<<endl;
cout<<"\t 6. Write An Appointmen Record To The File"<<endl;
cout<<"\t 7. Read An Appointmen Record From The File"<<endl;
cout<<"\t 8. 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: ";
getline(cin, AppointmenList[currentSize].description);
cout<<"Enter Appointmen date: ";
cin>>AppointmenList[currentSize].appdate.day;
cin>>AppointmenList[currentSize].appdate.mounth;
cin>>AppointmenList[currentSize].appdate.year;
cin.get();
cout<<"Enter Appointmen time: ";
getline(cin, AppointmenList[currentSize].time);
cout<<endl;
currentSize += 1; //update CurrentSize
}
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)<<"Person"<<setw(20)<< "Appointment"<<setw(12)<<"Appointment"<<setw(12)<<"\t Appointment"<<endl;
cout<<setw(20)<<"Name"<<setw(20)<< "Descriptions"<<setw(12)<<"Date"<<setw(15)<<"\t Time\n"<<endl;
}
void displayRecords( )
{ /* print the data from the array of records under a suitable header*/
int index, option,sdate;
system("cls"); //clear screen
cout<<"\n\t1. Display For Certein Date"<<endl; //Display the records for certein Date.
cout<<"\t2. Display All Appointments"<<endl;
cout<<"\nEnter Option Number: "; //Enter option
cin>>option;
cin.get();
if(option == 1)
system("cls"); //clear screen
cout<<"\nEnter the Date You want To Display: ";
cin>>sdate;
system("cls"); //clear screen
displayHeading( );
if (option == 2)
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<<AppointmenList[index].appdate.day;
cout<<"/"<<AppointmenList[index].appdate.mounth;
cout<<"/"<<setw(12)<<AppointmenList[index].appdate.year;
cout<<setw(12)<<AppointmenList[index].time;
cout<<endl<<endl;
}
//give the user a chance to read the output data
cout<<endl<<"Press any character to continue ";
cin.get(); //read entered character
else
cout<<endl<<"Wrong option number!! Try again\n";
cin.get();
}
void writeAppointmenRecords( )
{
int index;
//create and open an output text file
ofstream outfile("C:\\Documents and Settings\\Administrator\\Desktop\\AppointmenRecords.txt", ios::out);
// Check if file is opened
if(!outfile) //return true if file is not opened
{ cout<<"\nFailed to open file!!!!\n";
cout<<"\nPress any key to proceed ";
cin.get();
}
for (index=0; index<currentSize; index++)
{
outfile<<AppointmenList[index].name;
outfile<<setw(15)<<AppointmenList[index].description;
outfile<<setw(15)<<AppointmenList[index].appdate.day;
outfile<<"/"<<AppointmenList[index].appdate.mounth;
outfile<<"/"<<AppointmenList[index].appdate.year;
outfile<<setw(15)<<AppointmenList[index].time<<endl;
}
//write values to file in an 15 characters field.
outfile.close( ); // close file
cin.get();
}
void readAppointmenRecords( )
{
currentSize=0;
//create a stream and open the file 'AppointmenRecords.txt' for input
ifstream infile("C:\\Documents and Settings\\Administrator\\Desktop\\AppointmenRecords.txt", ios::in);
// check if file is opened
if(!infile) //return true if file is not opened
{ cout<<"\nFailed to open file!!!!\n";
//indicate program failed
cin.get();
}
while (!infile.eof( )) //eof( ) End Of File function. Returns false if end file reached
{
getline(infile, AppointmenList[currentSize].name);
getline(infile, AppointmenList[currentSize].description);
infile.get();
infile>>AppointmenList[currentSize].appdate.day;
infile>>AppointmenList[currentSize].appdate.mounth;
infile>>AppointmenList[currentSize].appdate.year;
getline(infile, AppointmenList[currentSize].time);
currentSize+=1;
}
infile.close( ); // close file
currentSize = currentSize -1;
cin.get();
}
|