|
| 1 | +#include <iostream> //input/output |
| 2 | +#include <fstream> //file |
| 3 | +#include <unistd.h> //sleep |
| 4 | +#include <iomanip> //setting width |
| 5 | +#include <ctime> //time |
| 6 | +#include <unordered_map> //hash table |
| 7 | + |
| 8 | +using namespace std; |
| 9 | + |
| 10 | +// customer class |
| 11 | +class Customer |
| 12 | +{ |
| 13 | +public: |
| 14 | + string customer_Name; |
| 15 | + int car_model; |
| 16 | + string car_Number; |
| 17 | +}; |
| 18 | + |
| 19 | +//Rent class |
| 20 | +// inherited class from customer class |
| 21 | +class Rent : public Customer |
| 22 | +{ |
| 23 | +private: |
| 24 | + // additional integer variables defined |
| 25 | + int numberOfDays; |
| 26 | + int rent_Fee; |
| 27 | + char str[200]; |
| 28 | + bool value; //A character array in which to store the data with Maximum number of characters to extract. |
| 29 | + |
| 30 | + unordered_map<string, Customer> customerRecords; // Hash table to store customer records based on car numbers |
| 31 | + |
| 32 | +public: |
| 33 | + Rent(); |
| 34 | + void welcome(); |
| 35 | + void fileReader(const char* carFile); |
| 36 | + void data(); |
| 37 | + void invoiceAmount(); //Computes |
| 38 | + void invoiceRecord(); |
| 39 | + void storeRentDetails(); |
| 40 | + void modify(); //Prints the invoice |
| 41 | +}; |
| 42 | + |
| 43 | +Rent::Rent() |
| 44 | +{ |
| 45 | + numberOfDays = 0; |
| 46 | + rent_Fee = 0; |
| 47 | +} |
| 48 | + |
| 49 | +void Rent::welcome() |
| 50 | +{ |
| 51 | + ifstream inputFile("welcome.txt"); //displaying welcome ASCII image text on output screen fn1353 |
| 52 | + if (!inputFile) { |
| 53 | + cout << "Cannot open input file.\n"; |
| 54 | + } |
| 55 | + char str[1000]; |
| 56 | + while (inputFile) { |
| 57 | + inputFile.getline(str, 1000); // delim defaults to '\n' cp |
| 58 | + if (inputFile) |
| 59 | + cout << str << endl; |
| 60 | + } |
| 61 | + inputFile.close(); |
| 62 | + sleep(1); |
| 63 | + cout << "\nStarting the program please wait....." << endl; |
| 64 | + sleep(1); |
| 65 | + cout << "\nloading up files....." << endl; |
| 66 | + sleep(1); //function which waits for (n) seconds |
| 67 | + system("CLS"); //cleares screen |
| 68 | +} |
| 69 | + |
| 70 | +void Rent::fileReader(const char* carFile) |
| 71 | +{ |
| 72 | + ifstream inputFile; |
| 73 | + inputFile.open(carFile); //displaying details of model A |
| 74 | + if (!inputFile) { |
| 75 | + cout << "Error in printing file. File not found!" << endl; |
| 76 | + } |
| 77 | + while (inputFile) { |
| 78 | + inputFile.getline(str, 200); |
| 79 | + if (inputFile) |
| 80 | + cout << str << endl; |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +void Rent::data() |
| 85 | +{ |
| 86 | + cout << "\n\n\t\t\t\tPlease Enter your Name: "; //taking data from the user |
| 87 | + cin >> customer_Name; |
| 88 | + cout << endl; |
| 89 | + do { |
| 90 | + //giving user a choice to select among three different models |
| 91 | + cout << "\t\t\t\t__________________________________________________________________" << endl; |
| 92 | + cout << "\t\t\t\tChoose a Car from the options below. \n "; |
| 93 | + cout << "\t\t\t\tChoose a number corresponding to the car you want to Select." << endl; |
| 94 | + cout << "\t\t\t\t__________________________________________________________________" << endl; |
| 95 | + cout << "\t\t\t\t1. Toyota 2021." << endl; |
| 96 | + cout << "\t\t\t\t2. Hyundai 2019." << endl; |
| 97 | + cout << "\t\t\t\t3. Ford 2020." << endl; |
| 98 | + cout << "\t\t\t\t4. Maruthi Suzuki 2022." << endl; |
| 99 | + cout << "\t\t\t\t5. Benz 2023." << endl; |
| 100 | + cout << "\t\t\t\t6. Lamborgini 2021." << endl; |
| 101 | + cout << endl; |
| 102 | + cout << "\t\t\t\t__________________________________________________________________" << endl; |
| 103 | + cout << "\n\t\t\t\tChoose: "; |
| 104 | + cin >> car_model; |
| 105 | + cout << endl; |
| 106 | + |
| 107 | + switch (car_model) { |
| 108 | + case 1: |
| 109 | + system("CLS"); |
| 110 | + cout << "You have chosen Toyota model 2021" << endl; |
| 111 | + fileReader("Toyota.txt"); |
| 112 | + sleep(2); |
| 113 | + break; |
| 114 | + case 2: |
| 115 | + system("CLS"); |
| 116 | + cout << "You have chosen Hyundai model 2019" << endl; |
| 117 | + fileReader("Hyundai.txt"); |
| 118 | + sleep(2); |
| 119 | + break; |
| 120 | + case 3: |
| 121 | + system("CLS"); |
| 122 | + cout << "You have chosen Ford model 2020" << endl; |
| 123 | + fileReader("Ford.txt"); |
| 124 | + sleep(2); |
| 125 | + break; |
| 126 | + case 4: |
| 127 | + system("CLS"); |
| 128 | + cout << "You have chosen Maruthi Suzuki model 2022" << endl; |
| 129 | + fileReader("Maruthi_Suzuki.txt"); |
| 130 | + sleep(2); |
| 131 | + break; |
| 132 | + case 5: |
| 133 | + system("CLS"); |
| 134 | + cout << "You have chosen Benz model 2023" << endl; |
| 135 | + fileReader("Benz.txt"); |
| 136 | + sleep(2); |
| 137 | + break; |
| 138 | + case 6: |
| 139 | + system("CLS"); |
| 140 | + cout << "You have chosen Lamborgini model 2021" << endl; |
| 141 | + fileReader("Lamborgini.txt"); |
| 142 | + sleep(2); |
| 143 | + break; |
| 144 | + default: |
| 145 | + cout << "Invalid Car Model. Please try again!" << endl; |
| 146 | + fileReader("thanks.txt"); |
| 147 | + exit(0); |
| 148 | + } |
| 149 | + } while (car_model < 1 && car_model > 6); |
| 150 | + |
| 151 | + cout << "________________________________________________________________________________________________" << endl; |
| 152 | + cout << "Please provide the following information:" << endl; |
| 153 | + |
| 154 | + //getting data from user related to rental service |
| 155 | + cout<< "Are you sure u want to rent this car, click 1 for yes and click 0 for no:"; |
| 156 | + cin>>value; |
| 157 | + if(value==1){ |
| 158 | + cout << "Please select a Car No. : "; |
| 159 | + cin >> car_Number; |
| 160 | + cout << "Number of days you wish to rent the car : "; |
| 161 | + cin >> numberOfDays; |
| 162 | + cout << endl; |
| 163 | + }else{ |
| 164 | + exit(0); |
| 165 | + fileReader("thanks.txt"); |
| 166 | + } |
| 167 | + |
| 168 | + // Store customer data in the hash table |
| 169 | + Customer customer; |
| 170 | + customer.customer_Name = customer_Name; |
| 171 | + customer.car_model = car_model; |
| 172 | + customer.car_Number = car_Number; |
| 173 | + |
| 174 | + customerRecords[car_Number] = customer; |
| 175 | +} |
| 176 | + |
| 177 | +void Rent::invoiceAmount() |
| 178 | +{ |
| 179 | + sleep(1); |
| 180 | + system("CLS"); |
| 181 | + cout << "Calculating rent. Please wait......" << endl; |
| 182 | + sleep(2); |
| 183 | + if (car_model == 1) |
| 184 | + rent_Fee = numberOfDays * 150; |
| 185 | + if (car_model == 2) |
| 186 | + rent_Fee = numberOfDays * 160; |
| 187 | + if (car_model == 3) |
| 188 | + rent_Fee = numberOfDays * 175; |
| 189 | + if (car_model == 4) |
| 190 | + rent_Fee = numberOfDays * 190; |
| 191 | + if (car_model == 5) |
| 192 | + rent_Fee = numberOfDays * 200; |
| 193 | + if (car_model == 6) |
| 194 | + rent_Fee = numberOfDays * 225; |
| 195 | +} |
| 196 | +void Rent::modify() |
| 197 | +{ |
| 198 | + string carNumber; |
| 199 | + cout << "Enter the Car Number of the customer you want to modify: "; |
| 200 | + cin >> carNumber; |
| 201 | + |
| 202 | + // Check if the customer record exists in the hash table |
| 203 | + if (customerRecords.find(carNumber) != customerRecords.end()) { |
| 204 | + Customer& customer = customerRecords[carNumber]; |
| 205 | + |
| 206 | + // Display the current rental details |
| 207 | + cout << "Current Rental Details:" << endl; |
| 208 | + cout << "Customer Name: " << customer.customer_Name << endl; |
| 209 | + cout << "Car Model: " << customer.car_model << endl; |
| 210 | + cout << "Car Number: " << customer.car_Number << endl; |
| 211 | + cout << "no.of days car rented: "<<numberOfDays<<endl; |
| 212 | + |
| 213 | + // Prompt the user to enter the modified details |
| 214 | + cout << "Enter the new rental details:" << endl; |
| 215 | + cout << "Customer Name: "; |
| 216 | + cin >> customer.customer_Name; |
| 217 | + cout << "Car Model: "; |
| 218 | + cin >> customer.car_model; |
| 219 | + cout<<"no.of days car rented: "; |
| 220 | + cin>>numberOfDays; |
| 221 | + |
| 222 | + // Update the rental details in the hash table |
| 223 | + customerRecords[carNumber] = customer; |
| 224 | + |
| 225 | + cout << "Rental details modified successfully." << endl; |
| 226 | + } else { |
| 227 | + cout << "Customer record not found." << endl; |
| 228 | + } |
| 229 | +} |
| 230 | + |
| 231 | + |
| 232 | +void Rent::invoiceRecord() |
| 233 | +{ |
| 234 | + time_t now = time(0); //getting local time |
| 235 | + char* date = ctime(&now); //Converting to a string |
| 236 | + cout << setw(80) << date << endl; |
| 237 | + cout << "\n\t\t CAR RENTAL - CUSTOMER INVOICE " << endl; |
| 238 | + cout << "\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; |
| 239 | + cout << "\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; |
| 240 | + cout << "\t\t | Invoice No. " << " |" << setw(10) << "#1001" << " |" << endl; //can be automatically generated |
| 241 | + cout << "\t\t | Customer Name " << " |" << setw(10) << customer_Name << " |" << endl; |
| 242 | + cout << "\t\t | Car Model " << " |" << setw(10) << car_model << " |" << endl; //car model |
| 243 | + cout << "\t\t | Car No. " << " |" << setw(10) << car_Number << " |" << endl; |
| 244 | + cout << "\t\t | Number of days " << " |" << setw(10) << numberOfDays << " |" << endl; |
| 245 | + cout << "\t\t | Rental Amount " << " |" << setw(10) << rent_Fee << " |" << endl; |
| 246 | + cout << "\t\t | Caution Money " << " |" << setw(10) << "0" << " |" << endl; //Can be calculated |
| 247 | + cout << "\t\t | Advanced " << " |" << setw(10) << "0" << " |" << endl; //Can be calculated |
| 248 | + cout << "\t\t |___________________________________________________________|" << endl; |
| 249 | + cout << "\t\t | Total Rental Amount " << " |" << setw(6) << "R " << rent_Fee << " |" << endl; |
| 250 | + cout << "\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; |
| 251 | + cout << "\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; |
| 252 | + cout << "\t\t NOTE: This is a computer-generated invoice. " << endl; |
| 253 | + cout << "\t\t It does not require an authorized signature." << endl; |
| 254 | + cout << "\t\t ***********************************************************" << endl; |
| 255 | + cout << "\t\t You are advised to pay up the amount before the due date." << endl; |
| 256 | + cout << "\t\t Otherwise, a penalty fee will be applied" << endl; |
| 257 | + cout << "\t\t ***********************************************************" << endl; |
| 258 | + |
| 259 | + system("PAUSE"); |
| 260 | + system("CLS"); |
| 261 | + |
| 262 | +} |
| 263 | +void Rent::storeRentDetails() |
| 264 | +{ |
| 265 | + ofstream outputFile; |
| 266 | + char fname[15]; |
| 267 | + time_t now = time(0); //getting local time |
| 268 | + char* date = ctime(&now); |
| 269 | + cout << " \t\t enter the filename which you need to store the details of this rent:"; |
| 270 | + cin>>fname; |
| 271 | + outputFile.open(fname,ios::app); // open the file in append mode |
| 272 | + |
| 273 | + // Check if the file was opened successfully |
| 274 | + if (!outputFile) { |
| 275 | + cout << "Error in opening file for writing." << endl; |
| 276 | + return; |
| 277 | + } |
| 278 | + |
| 279 | + // Write rent details to the |
| 280 | + outputFile << "Rent details generated at:"<< date << endl; |
| 281 | + outputFile << "Customer Name: " << customer_Name << endl; |
| 282 | + outputFile << "Car Model: " << car_model << endl; |
| 283 | + outputFile << "Car Number: " << car_Number << endl; |
| 284 | + outputFile << "Number of Days: " << numberOfDays << endl; |
| 285 | + outputFile << "Rent Fee: " << rent_Fee << endl; |
| 286 | + outputFile << endl; |
| 287 | + |
| 288 | + // Close the file |
| 289 | + outputFile.close(); |
| 290 | + |
| 291 | + cout << "Rent details have been stored successfully." << endl; |
| 292 | + fileReader("thanks.txt"); |
| 293 | +} |
| 294 | + |
| 295 | + |
| 296 | +int main() |
| 297 | +{ |
| 298 | + //Object created for rent class and further member functions are called. |
| 299 | + Rent rent; |
| 300 | + rent.welcome(); |
| 301 | + rent.data(); |
| 302 | + rent.modify(); |
| 303 | + rent.invoiceAmount(); |
| 304 | + rent.invoiceRecord(); |
| 305 | + rent.storeRentDetails(); |
| 306 | + return 0; |
| 307 | +} |
0 commit comments