/* Heaps - ADT This program will read data about overbooked customers, find their priority and serial numbers, build a heap, then display customers in priority sequence Written By: Iurii Tatishchev Changed By: Iurii Tatishchev IDE: CLion */ #include #include #include #include "Customer.h" #include "Heap.h" using namespace std; // Function Prototypes int compareCustomer(const Customer &c1, const Customer &c2); void processArrival(Heap &heap, ifstream &inputFile, int seq); void processServe(Heap &heap); void displayRejected(Heap &heap); int main() { // Get input file name string inputFileName; cout << "Input file name: "; getline(cin, inputFileName); cout << endl; // Open input file ifstream inputFile(inputFileName); if (!inputFile.good()) { cerr << "Error: could not open file " << inputFileName << "\n"; return 1; } // Create heap Heap heap; // Process input file char command; int seq = 1; while (inputFile >> command) { switch (command) { case 'A': processArrival(heap, inputFile, seq); seq++; break; case 'S': processServe(heap); break; default: cerr << "Error: invalid command " << command << "\n"; return 1; } } cout << "Served overbooked customers: " << seq - heap.getCount() - 1 << "\n\n"; // Display rejected customers int rejectedCustomers = heap.getCount(); displayRejected(heap); cout << "Rejected overbooked customers: " << rejectedCustomers << "\n"; return 0; } int compareCustomer(const Customer &c1, const Customer &c2) { if (c1.getSerial() < c2.getSerial()) return 1; if (c1.getSerial() > c2.getSerial()) return -1; return 0; } void processArrival(Heap &heap, ifstream &inputFile, int seq) { int years, mileage; string name; inputFile >> years >> mileage; getline(inputFile >> ws, name); Customer customer(years, mileage, seq, name); heap.insertHeap(customer, compareCustomer); } void processServe(Heap &heap) { if (heap.isEmpty()) { cout << "Heap is empty" << endl; return; } Customer customer; heap.deleteHeap(customer, compareCustomer); cout << customer << endl; } void displayRejected(Heap &heap) { Customer customer; while (!heap.isEmpty()) { heap.deleteHeap(customer, compareCustomer); cout << customer << endl; } }