Jun 16, 2012 at 10:17am UTC
Hey guys. My project is a reservation system. My problem is in filestreaming ( i think) . My objective that I can't figure out is to show that the cottage is reserved continously. My problem is after the 1st input, it no longer shows the "Reserved" previously. How do i this?
Here's my code: (you can run it to see)
#include<iostream>
#include<iomanip>
#include<fstream>
#include<conio.h>
#include<windows.h>
#include<string>
#include<cstdlib>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void admenu();
void usermenu();
void password();
void ACottages(string);
void Cottages(int,int);
int Convert(char);
void Reserve();
void QuitProgram();
void ResetCottages();
void Header();
class ychoice{};
class nchoice{};
class nvalidp{};
struct reserve
{
char name[100];
int ncottage;
};
/**********************************/
string EnterPassword()
{
string NumAsString="";
char ch=getch();//h
while (ch!='\r'){
cout<<'*';//***
NumAsString+=ch;//"hello"
ch=getch();//
}
return NumAsString;
}
/**********************************/
/**********************************/
void main()
{
int ulit=0;
char ans;
bool flag=true;
while(flag)
{
system("cls");
Header();
cout<<"[1]User \n"
<<"[2]Administrator\n"
<<"Choice: ";
cin>>ans;
ans=tolower(ans);
switch(ans)
{
case '1':
usermenu();
flag=false;
break;
case '2':
// password();
system("cls");
admenu();
flag=false;
break;
}//end switch
}//end while
}//end main
/**********************************/
/**********************************/
void password()
{
int ulit=0 , attempts=0;
bool flag=true;
system("cls");
Header();
cout<<"Welcome Administrator!\n"
<<"password:";
while(flag)
{
string password=EnterPassword();
try
{
if(password=="hello")
{
cout<<"\nprocessing your password";
do
{
Sleep(1000);
cout<<".";
ulit++;
}while(ulit<2);
flag=false;
}//end if
else
throw nvalidp();
}//end try
catch (nvalidp)
{
cout<<"\nprocessing your password";
Sleep(1000);
cout<<".";
system("cls");
cout<<"Wrong Password!"<<endl;
cout<<"password:";
attempts++;
if (attempts>=3)
{
flag=false;
system("cls");
cout<<"You Have Exceeded the Attempts Allowed \n"
<<"Program Terminated \n";
exit(1);
}//end if
continue;
}//end catch nvalidp
}//end while
}//end password;
/**********************************/
void admenu()
{
char choice;
string AvailableCottages;
bool flag=true;
while(flag)
{
system("cls");
Header();
cout<<" ==========ADMINISTRATOR MENU==========\n";
cout<<" [1] Available cottages \n"
<<" [2] Reset Available\n"
<<" [3] Quit \n"
<<" Please enter your choice:";
cin>>choice;
choice=tolower(choice);
switch(choice)
{
case '1':
ACottages(AvailableCottages);
flag=false;
break;
case '2':
ResetCottages();
flag=false;
break;
case '3':
QuitProgram();
flag=false;
break;
}//end switch
}//end while
}//end Admenu
/********************************/
void usermenu()
{
char select;
int x=0,y=0;
bool flag=true;
string Acall;
while (flag)
{
system("cls");
Header();
cout<<" ========Welcome Guest=======\n"
<<" [1] View available cottages \n"
<<" [2] Reserve a cottage \n"
<<" [3] Quit \n"
<<" Please your choice:";
cin>>select;
select=tolower(select);
switch(select)
{
case '1':
ACottages(Acall);
flag=false;
break;
case '2':
Reserve();
flag=false;
break;
case '3':
QuitProgram();
flag=false;
break;
}//end switch
}//end while
}//end usermenu
/********************************/
void Cottages(int ColLetter, int NumRows)
{
{
int x,y;
int z=1;
ofstream fout;
string letter = "abcde";
string stat="Available";
string res="Reserved ";
Header();
fout.open("cottages.txt");
for(x=0; x < 5;x++)
fout<<setw(14)<<letter.at(x);
fout<<endl;
for(y = 0; y<8; y++)
{
fout<<" "<<y+1;
for(x=0;x<5;x++)
{
if( ( ColLetter == (x+1) ) && (NumRows == (y+1) ) )
fout<<" [ "<<res<<" ]";
else
fout<<" [ "<<stat<<" ]";
z++;
}//end inner for
fout<<endl;
}//end outer for
ifstream instream("cottages.txt");
char ch;
while(!instream.eof())
{
instream.get(ch);
cout<<ch;
}
instream.close();
}
}//end Cottages
/********************************/
void Reserve()
{
reserve c;
char cInput;
int nInput,i;
int x=0,y=0;
int X,Y;
int z=1;
string letter = "abcde";
string areceive;
ofstream fout;
system("cls");
Header();
fout.open("cottages.txt");
ACottages(areceive);
cout<<"\nHow many cottages would you like to Reerve? [1-40] : ";
cin>>c.ncottage;
for(i=0;i<c.ncottage;i++)
{
cout<<"\nEnter The Cottage Number You Want to Reserve ["<<i+1<<"/"<<c.ncottage<<"]\n"
<<"[letter number] :";
cin>>cInput>> nInput;
X = Convert(cInput);
Y = nInput;
Cottages(X,Y);
cout<<" Your Cottage is at: "<<cInput<<" "<<Y<<endl;
}//end outer for
fout.close();
}//end Reserve
/********************************/
void ACottages(string available)
{
string stat="Available";
string letter = "abcde";
available=stat;
int x,y;
int z=1;
ofstream fout;
available=stat;
fout.open("cottages.txt");
Header();
for(x=0; x < 5;x++)
fout<<setw(14)<<letter.at(x);
fout<<endl;
for(y = 0; y<8; y++)
{
fout<<" "<<y+1;
for(x=0;x<5;x++)
{
fout<<" [ "<<available<<" ]";
z++;
}//end inner for
fout<<endl;
}//end outer for;
ifstream instream("cottages.txt");
char ch;
while(!instream.eof())
{
instream.get(ch);
cout<<ch;
}
instream.close();
}//end ACottages
/********************************/
void ResetCottages()
{
cout<<endl;
}//end ResetCottages
/********************************/
void QuitProgram()
{
char ans;
do
{
try
{
cout<<"Do You Really Want to Quit ? [y/n]";
cin>>ans;
ans=tolower(ans);
if (ans=='y')
throw ychoice();
else if (ans=='n')
throw nchoice();
}//end try
catch(ychoice)
{
system("cls");
cout<<"Program Terminated"<<endl;
exit(1);
}//end catch ychoice
catch(nchoice)
{
main();
}//end catch nchoice
}while((ans!='y')||(ans!='n'));
}//end QuitProgram
void Header()
{
system("cls");
cout<<" ***********************************************************************\n"
<<" * *\n"
<<" * RESORT R E S E R V A T I O N *\n"
<<" * *\n"
<<" ***********************************************************************\n";
cout<<endl;
cout<<endl;
}
int Convert(char cLetter)
{
cLetter = toupper(cLetter);
switch(cLetter)
{
case 'A':
return 1;
break;
case 'B':
return 2;
break;
case 'C':
return 3;
break;
case 'D':
return 4;
break;
case 'E':
return 5;
break;
}
}
Jun 16, 2012 at 10:35am UTC
And also. I can't view the available cottages that I reserved