hi all,
we need some assistance in our program. please advise
question:
A community centre has decided to computerize the booking of two badminton courts.
The two courts are named as B1 and B2. Bookings are to be done on a two-hour block
from 10am to 10pm daily.
Each booking record should have the Facility Name, Day and Time, the player’s NRIC
number and the booking status of the court. Each player’s record should have name,
NRIC number and Telephone number.
Design the necessary classes and member functions to achieve the following tasks :
a. Allow user to book the court by entering the facility name, day and time. If it is
available, prompt the user to enter his name, NRIC number and telephone number.
Display a message “Courts is booked” if the facility has already been booked by
other player.
b. Allow user to enquire the availability of court for the entire week.
c. Allow user to enquire his/her booking by entering NRIC number.
d. Store the booking record in a text file when the system terminates.
we have problem with question b)
header
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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Record
{
protected:
char F_name[2];
string Day;
int Time;
string NRIC;
int status;
string p_name;
string IC_no;
int Tele_no;
string temp;
};
class Book : protected Record
{
private:
ifstream fin;
ofstream fout;
protected:
string name;
string day;
int time;
public:
void book();
void availability();
void enquire();
};
#include "class.h"
#include <string>
using namespace std;
void Book::book()
{
cin.get();
cout << "Pls enter the facility name : ";
getline(cin, name);
cout << "Pls enter the day u wan to book: ";
getline(cin, day);
cout << "Pls enter the time u wan to book : ";
cin >> time;
fin.open("BookRecord.txt");
do {
fin >> F_name;
getline(fin, temp, ' ');
getline(fin, p_name, ' ');
getline(fin, Day, ' ');
fin >> Time;
if ((F_name == name)&&(Day == day)&&(Time == time))
status = 1;
else status = 0;
getline(fin, temp);
} while ((status != 1)&&(!fin.eof()));
fin.close();
if (status == 1)
cout << "Court is booked.\n";
else {
fflush(stdin);
cout << "Pls enter ur name : ";
getline(cin, p_name);
cout << "Pls enter ur NRIC(num onli) : ";
cin >> IC_no;
cout << "Pls enter ur telephone no : ";
cin >> Tele_no;
fout.open("BookRecord.txt", ios::app);
fout << name << " " << p_name << " " << day << " " << time << " " << IC_no << " " << Tele_no << endl;
fout.close();
}
}
void Book::availability()
{
string s1,s2;
int t;
fin.open("BookRecord.txt");
fin >> name >> p_name >>Day >> Time >> s1 >> s2;
t = Time;
while (!fin.eof())
{
fin >> name >> p_name>> Day >> Time >>s1 >> s2;
for (int i = 0; i < 5; i += 2)
if (Time == (t+2+i))
cout << "Day :" << Day << "The court " << name << " is available from " << t << ":00 to " << i << ":00.";
else cout << "\nDay: " <<Day << "The court " << name << " is available from " << t << ":00 to " << t+2+i << ":00.";
}
}
void Book::enquire()
{
string s3,s4;
cout << "Pls enter ur NRIC : ";
cin>> NRIC;
fin.open ("BookRecord.txt");
{
fin >> F_name >> p_name >> Day >> Time >> s3, s4;
getline(fin, NRIC, ' ');
if (NRIC == IC_no)
{
while (fin >> IC_no)
{
fin >> F_name >> Day >> Time >> s3 >> s4;
cout << F_name << " " << Day << " " << Time << " " ;
}
}
fin.close();
return;
}
}
main
#include <iostream>
#include <fstream>
#include <string>
#include "class.h"
using namespace std;
void main()
{
int value;
cout<<"Please Select Your Choice: "<<endl;
cout<<"1)Court Booking"<<endl;
cout<<"2)Enquire Availability Of Court"<<endl;
cout<<"3)Enquire Your Booking"<<endl;
cout<<"Your Choice Is : ";
cin>>value;
Book B;
if(value == 1)
{
B.book();
}
else if(value == 2)
{
B.availability();
}
else
{
B.enquire();
}
}
| |