




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This assignment focuses on practical application of c++ programming concepts to manage customer data. It involves creating a menu-driven program that allows users to input, display, search, and compare customer information. The program utilizes structures, file handling, and input validation techniques to demonstrate fundamental programming principles.
Typology: Assignments
1 / 8
This page cannot be seen from the preview
Don't miss anything!





1. Make a menu-driven program. Display the following options: a. Press 1 to input customer data in the file b. Press 2 to display all data c. Press 3 to search for a specific customer d. Press 4 to compare salary e. Press e to exit 2. There must be a login page with the credentials: username: “admin” and password: “12345”. The credentials should be read from a file named “login.txt”. If user input is correct, it allows you to see the menu otherwise ask username and password again. 3. Your program should stay in execution till you press e. Apply input validation. 4. For option 1: Create an array of 10 customers and store the data in a file named “customer.txt”. The ID should be auto-assigned. Therefore, there will be no chance of duplication. 5. For option 3: Define search() function to Search the customer by its ID in the file. Display the complete data on the console of the customer if found in the file, if not display the message “No Customer Found”. 6. For option 4: Define the compare_salary() function that compares the salary of each customer and displays the data of the only customer that has the largest salary among all.
highest_salary_index = i; } } std::cout << "\nCustomer with the highest salary:\n"; std::cout << "ID: " << customers[highest_salary_index].ID << "\n" << "Name: " << customers[highest_salary_index].name << "\n" << "Email: " << customers[highest_salary_index].email << "\n" << "Salary: " << customers[highest_salary_index].salary << "\n"; } bool login() { std::ifstream loginFile("login.txt"); if (!loginFile) { std::cerr << "Error: Could not open login file." << std::endl; return false; } std::string username, password, storedUsername, storedPassword; loginFile >> storedUsername >> storedPassword; loginFile.close(); while (true) { std::cout << "Enter username: "; std::cin >> username; std::cout << "Enter password: "; std::cin >> password; if (username == storedUsername && password == storedPassword) { std::cout << "Login successful!\n"; return true; } else { std::cout << "Invalid credentials. Please try again.\n"; } } } int main() { Customer customers[10]; int size = 0; int idCounter = 1; char choice; do { std::cout << "\nMenu:\n" << "1. Input customer data\n" << "2. Display all data\n" << "3. Search for a specific customer\n" << "4. Compare salary\n" << "e. Exit\n" << "Enter your choice: "; std::cin >> choice; switch (choice) { case '1': { if (size >= 10) {
std::cout << "Customer limit reached.\n"; break; } customers[size] = input_data(idCounter); ++size; ++idCounter; break; } case '2': { displayall(customers, size); break; } case '3': { int id; std::cout << "Enter customer ID to search: "; std::cin >> id; search(id, customers, size); break; } case '4': { compare_salary(customers, size); break; } case 'e': { std::cout << "Exiting program. Goodbye!\n"; break; } default: { std::cout << "Invalid choice. Please try again.\n"; } } } while (choice != 'e'); return 0; } Output: