Question: for the following C++ code write appropriate flowchart to represent it: #include #include #include #include using namespace std; //const int nor = 50; int readfromfile(char
for the following C++ code write appropriate flowchart to represent it:
#include
//const int nor = 50; int readfromfile(char name[][30], int phone[], int room[], int days[], int price[]); void addrecord(); void updaterecord(char name[][30], int phone[], int room[], int days[], int price[], int bil); void deleterecord(char name[][30], int phone[], int room[], int days[], int price[], int bil); int calculateprice(int room, int days); void display();
int main() { char name[50][30]; int phone[50], room[50], price[50], days[50]; char w = '1'; cout << "\t" << "************ ENTER THE PASS WORD FOR THE SYSTEM ************" << endl; cin >> w; system("CLS"); if (w == '1') { int i = 0;
while (i == 0) { cout << " ****************HOTEL RESERVATION SYSTEM****************" << endl; cout << "\t\t1. Add Your Reservation" << endl; cout << "\t\t2. Update Your Reservation" << endl; cout << "\t\t3. Delete Your Reservation" << endl; cout << "\t\t4. Check Your Reservation List" << endl;
cout << " *******************************************************" << endl; cout << "\t\tChoose your menu: "; cin >> i;
if (i == 1) { char LoopAgain = 'Y'; while (LoopAgain == 'Y') { system("CLS"); addrecord(); cout << " Do you want to continue to add reservation? Enter Y for yes,N for no: "; cin >> LoopAgain;
} if (LoopAgain == 'N') { i = 0; system("CLS"); } }
if (i == 2) { char LoopAgain = 'Y'; while (LoopAgain == 'Y') { system("CLS"); int bil = readfromfile(name, phone, room, days, price); updaterecord(name, phone, room, days, price, bil); cout << " Data updated successfully..." << endl; cout << " Do you want to update more records? Enter Y for yes,N for no: "; cin >> LoopAgain; } if (LoopAgain == 'N') { i = 0; system("CLS"); } }
if (i == 3) { char LoopAgain = 'Y'; while (LoopAgain == 'Y') { system("CLS"); int bil = readfromfile(name, phone, room, days, price); deleterecord(name, phone, room, days, price, bil); cout << " Record deleted successfully..." << endl; cout << " Do you want to delete more record? Enter Y for yes, N for no: "; cin >> LoopAgain; } if (LoopAgain == 'N') { i = 0; system("CLS"); } }
if (i == 4) { system("CLS"); display(); i = 0; system("pause"); system("CLS"); } } } else cout << "\t" << "***TRY AGAIN***" << endl;
}
int readfromfile(char name[][30], int phone[], int room[], int days[], int price[]) { ifstream theFile("record.txt", ios::in); int bil = 0;
while (theFile >> name[bil] >> phone[bil] >> room[bil] >> days[bil] >> price[bil]) { bil++; } theFile.close(); return bil; }
void addrecord() { char name[30]; int phone, room, price, days;
cout << " Name Reserved Under :\t"; cin >> name; cout << "Phone number\t:\t"; cin >> phone; cout << "Number of room to book\t:\t"; cin >> room; cout << "Days of staying\t:\t"; cin >> days; price = calculateprice(room, days);
ofstream theFile("record.txt", ios::app); theFile << name << "\t" << phone << "\t" << room << "\t" << days << "\t" << price << endl; theFile.close(); }
void updaterecord(char name[][30], int phone[], int room[], int days[], int price[], int bil) { int change, i;
display(); cout << " Select your number:\t"; cin >> i; i = i - 1; cout << "******************************************" << endl; cout << " 1.Phone number." << endl; cout << "2.Number of room." << endl; cout << "3.Days of staying." << endl; cout << " What do you want to change:\t"; cin >> change;
if (change == 1) { cout << " Enter new phone number: \t"; cin >> phone[i]; } else if (change == 2) { cout << " Enter new number of room:\t"; cin >> room[i]; } else if (change == 3) { cout << " Enter new days of staying:\t"; cin >> days[i]; }
price[i] = calculateprice(room[i], days[i]);
ofstream theFile("record2.txt", ios::out); for (int i = 0; i < bil; i++) { theFile << name[i] << "\t" << phone[i] << "\t" << room[i] << "\t" << days[i] << "\t" << price[i] << endl; } theFile.close();
remove("record.txt");
rename("record2.txt", "record.txt"); }
void deleterecord(char name[][30], int phone[], int room[], int days[], int price[], int bil) { int num; display(); cout << "Select your number:\t"; cin >> num; num = num - 1;
ofstream theFile("record2.txt", ios::out); for (int i = 0; i < bil; i++) { if (i != num) { theFile << name[i] << "\t" << phone[i] << "\t" << room[i] << "\t" << days[i] << "\t" << price[i] << endl; } } theFile.close();
remove("record.txt");
rename("record2.txt", "record.txt"); }
int calculateprice(int room, int days) { int price; price = room * 120; price = price * days; return price; }
void display() { string name; int no = 1, phone, room, days, price; cout << "no\tName\t\tPhone Number\tNumber of Room\tStaying Days\tPrice(RM)" << endl; cout << "---\t----------\t------------\t--------------\t------------\t---------" << endl; ifstream theFile("record.txt", ios::in); while (theFile >> name >> phone >> room >> days >> price) { cout << no << "\t" << name << "\t\t0" << phone << "\t" << room << "\t\t" << days << "\t\t" << price << endl; no++; } theFile.close();
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
