Manag CPP
Manag CPP
#include <fstream>
class Tour {
private:
char destination[100];
char startDate[20];
char endDate[20];
float cost;
public:
Tour(const char* dest, const char* start, const char* end, float cst)
: cost(cst) {
copyString(destination, dest, sizeof(destination));
copyString(startDate, start, sizeof(startDate));
copyString(endDate, end, sizeof(endDate));
}
private:
void copyString(char* dest, const char* src, size_t maxSize) {
size_t i = 0;
while (i < maxSize - 1 && src[i] != '\0') {
dest[i] = src[i];
++i;
}
dest[i] = '\0';
}
};
void addTour() {
ofstream outFile("tours.txt", ios::app);
if (!outFile) {
cerr << "Error opening file!" << endl;
return;
}
char dest[100];
char start[20];
char end[20];
float cost;
outFile.close();
cout << "Tour added successfully!" << endl;
}
char line[100];
bool found = false;
inFile.getline(line, sizeof(line));
cout << "Start Date: " << line << endl;
inFile.getline(line, sizeof(line));
cout << "End Date: " << line << endl;
inFile.getline(line, sizeof(line));
cout << "Cost: " << line << endl;
found = true;
break;
} else {
// Skip the rest of the tour details
for (int i = 0; i < 3; ++i) {
inFile.getline(line, sizeof(line));
}
}
}
if (!found) {
cout << "Tour not found." << endl;
}
inFile.close();
}
char newDest[100];
char newStart[20];
char newEnd[20];
float newCost;
if (!found) {
cout << "Tour not found." << endl;
}
file.close();
}
int main() {
int userType;
cout << "Select User Type" << endl;
cout << "1. Admin" << endl;
cout << "2. Customer" << endl;
cout << "Enter your choice: ";
cin >> userType;
if (userType == 1) {
char username[50];
char password[50];
if (authenticateAdmin(username, password)) {
cout << "Login successful. Welcome, admin!" << endl;
int adminChoice;
do {
cout << "\nAdmin Menu" << endl;
cout << "1. Add Tour" << endl;
cout << "2. Display Tours" << endl;
cout << "3. Search Tour" << endl;
cout << "4. Update Tour" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: ";
cin >> adminChoice;
switch (adminChoice) {
case 1:
addTour();
break;
// Add cases for 2, 3, 4...
default:
cout << "Invalid choice. Please try again." << endl;
}
} else {
cout << "Invalid username or password. Access denied." << endl;
}
} else if (userType == 2) {
// Customer menu
int customerChoice;
do {
cout << "\nCustomer Menu" << endl;
cout << "1. Show Tours" << endl;
cout << "2. Purchase Tickets" << endl;
cout << "3. Enter Phone Number" << endl;
cout << "4. Exit" << endl;
cout << "Enter your choice: ";
cin >> customerChoice;
switch (customerChoice) {
case 1:
// Function definition for displaying tours
cout << "Displaying Tours..." << endl;
break;
case 2:
// Function definition for purchasing tickets
cout << "Purchasing Tickets..." << endl;
break;
case 3: {
// Function definition for inputting phone number
char input[15];
int valid = 0;
char customerPhone[15] = {0}; // Initialize the array to zero
while (!valid) {
cout << "Enter your phone number (only digits): ";
cin >> input;
if (valid) {
int i = 0;
while (input[i] != '\0') {
customerPhone[i] = input[i];
++i;
}
customerPhone[i] = '\0';
cout << "Phone number entered: " << customerPhone <<
endl;
} else {
cout << "Invalid phone number! Please enter only
digits." << endl;
}
}
break;
}
case 4:
cout << "Exiting customer menu." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}