Computer Programming Assignment: Customer Data Management in C++, Assignments of Computer Programming

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

2023/2024

Available from 01/27/2025

shaaf-saqib
shaaf-saqib 🇵🇰

3 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Programming
BSCS – 1B
Department of Computer Science
Bahria University, Lahore Campus
Assignment: [4]
Date: Week 15, 17th December 2024
Name: Shaaf Saqib
Roll No: 03-134242-085
Evaluation of CLO Question
Number
Marks Obtained
Marks
CLO3: Apply programming concepts to model requirements and
solve simple computing problems using a high-level
programming language.
1 10
Total Marks 20
Question 1:
For a given structure,
struct Customer
{
int ID;
string name;
string email;
int salary;
};
Implement the following functions with appropriate input arguments and return type.
Customer input_data();
void search(int);
void compare_salary();
void displayall();
pf3
pf4
pf5
pf8

Partial preview of the text

Download Computer Programming Assignment: Customer Data Management in C++ and more Assignments Computer Programming in PDF only on Docsity!

Computer Programming

BSCS – 1B

Department of Computer Science

Bahria University, Lahore Campus

Assignment: [4]

Date: Week 15, 17 th^ December 2024

Name: Shaaf Saqib

Roll No: 03-134242-

Evaluation of CLO Question

Number

Marks Obtained

Marks

CLO3: Apply programming concepts to model requirements and

solve simple computing problems using a high-level

programming language.

Total Marks 20

Question 1:

For a given structure,

struct Customer

int ID;

string name;

string email;

int salary;

Implement the following functions with appropriate input arguments and return type.

 Customer input_data();

 void search(int);

 void compare_salary();

 void displayall();

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: