Thanks for replaying Litz
actualy it was like this but i changed when i was tring different thinks.
im now getting any errors or warnings.
so what can be wrong with my codes????
here is my all program(trying to make) code if you want you can run it and see yourself thanks.
Code:
#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 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: writeAppointmenRecords( );
break;
case 6: readAppointmenRecords( );
break;
case 7: 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. Write An Appointmen Record To The File"<<endl;
cout<<"\t 6. Read An Appointmen Record From The File"<<endl;
cout<<"\t 7. 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;
}
cin.get();
}
else {
cout<<endl<<"Wrong option number!! Try again\n";
cin.get();
//give the user a chance to read the output data
cout<<endl<<"Press any character to continue ";
//cin.get(); //read entered character
}
}
void writeAppointmenRecords( )
{
int index;
//create and open an output text file
ofstream outfile("C:\\Documents and Settings\\zafer\\Desktop\\AppointmenRecords.txt",ios::out | ios::app);
// 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\\zafer\\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();
}