Question

In: Computer Science

C++ 11.7: Customer Accounts Write a program that uses a structure to store the following data...

C++

11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account: Customer name Customer address City State ZIP code Telephone Account balance Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Prompts And Output Labels. Your main menu should be the following: 1. Enter new account information 2. Change account information 3. Display all account information 4. Exit the program The user is expected to enter 1 or 2 or 3 or 4. The main menu is displayed at the start of the program and after the handling of choices 1, 2 and 3. If 1 is entered for the main menu, the program prompts for each of the data listed above, in the order listed above, using the above data descriptions (e.g. "ZIP code") as prompts (followed in each case by a colon). After reading in and processing the data, the program prints You have entered information for customer number X where X is the customer number: 0 for the first customer and increasing by 1 for each subsequent customer that is entered. If 2 is entered for the main menu, the program prompts for the customer number: Customer number: Upon entering a valid customer number the program displays all the data for the particular customer that has been saved: Customer name: ... Customer address: ... City: ... State: ... ZIP code: ... Telephone: ... Account balance: ... Date of last payment: ... The program then skips one or two lines and prompts for a change, using the same prompts as in choice 1 above for all the data items associated with a customer. If 3 is entered for the main menu, the program displays all the data for each customer that has been saved, using the display format in choice 2 above. After the display of each customer the program prompts "Press enter to continue..." and waits for the user to hit return. If 4 is entered for the main menu, the program terminates. Input Validation (OPTIONAL).When the data for a new account is entered, be sure the user enters data for all the fields. No negative account balances should be entered.

.make sure it good with codelab

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

//Include required header files
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//Declare structure for cutsimer details
struct CustomerAccount
{
        string cust_name;
        string cust_address;
        string cust_city;
        string cust_state;
        int ZIP_code;
        double telephoneNumber;
        double accountBalance;
        string dateOfLastPayment;
};

//function prototypes
CustomerAccount getDetails(CustomerAccount &);
int getCustomer(CustomerAccount[], int, string);
void displayDetails(CustomerAccount[], int);

//main method
int main()
{
        //declare the size
        const int SIZE = 20;

        //array size
        CustomerAccount customers[SIZE];
        CustomerAccount customer;
        //declare local variables
        int customerChoice;
        int count = 0;
        int cust_count = 0;
        string fullName;
        int change;
        //use do-while loop to repeat the code until
        //user wants to exit from the program
        do
        {
                //print the menu
                cout << endl;
                cout << "---------------MENU---------------" << endl;
                cout << "1.Enter new account information: " << endl;
                cout << "2.Change account information: " << endl;
                cout << "3.Display all account information: " << endl;
                cout << "4.Exit the program" << endl;
                cout << "Enter your choice (1/2/3/4): ";
                cin >> customerChoice;
                //switch case for each menu option
                switch (customerChoice)
                {
                case 1:
                        customers[count] = getDetails(customer);
                        cout << "You have entered information for customer number "
                             << count << endl;
                        count++;
                        cust_count = count;
                        break;
                case 2:
                        //prompt for customer number
                        cout << "Enter customer number: ";
                        cin >> count;
                        //print the details
                        cout << "Customer name: "
                             << customers[count].cust_name << endl;
                        cout << "Customer address: "
                             << customers[count].cust_address << endl;
                        cout << "City: " << customers[count].cust_city
                             << endl;
                        cout << "State: " << customers[count].cust_state
                             << endl;
                        cout << "ZIP code: " << setprecision(10)
                             << customers[count].ZIP_code << endl;
                        cout << "Telephone: " << setprecision(15)
                             << customers[count].telephoneNumber << endl;
                        cout << "Account balance: $" << setprecision(15)
                             << customers[count].accountBalance << endl;
                        cout << "Date of last payment: "
                             << customers[count].dateOfLastPayment << endl;
                        //prompt and read the full name of the customer
                        cout << endl
                             << "Enter full name of customer to be modified: ";
                        cin >> fullName;
                        change = getCustomer(customers, count, fullName);
                        //if the name is not valid
                        //print the message and break from the case
                        if (change == -1)
                        {
                                cout << endl
                                     << "Wrong customer name to change" << endl;
                        }
                        //otherwise reprompt for changing details
                        else
                        {
                                customers[change] = getDetails(customer);
                        }
                        break;
                //display details
                case 3:
                        displayDetails(customers, cust_count);
                        break;

                //exit from the switch case
                case 4:
                        exit(0);
                default:
                        cout << "Enter 1, 2, 3 or 4 only." << endl;
                }
        } while (customerChoice != 4 && count < SIZE);
        return 0;
}

//Implement method to read the details of the customer
CustomerAccount getDetails(CustomerAccount &obj)
{
        cout << endl;
        //prompt and read the customer name
        cout << "Enter the name of customer: ";
        cin >> obj.cust_name;
        //prompt and read the customer address
        cout << "Enter the address of customer: ";
        cin >> obj.cust_address;
        //prompt and read the customer city
        cout << "Enter the city of customer: ";
        cin >> obj.cust_city;
        //prompt and read the customer state
        cout << "Enter the state of customer: ";
        cin >> obj.cust_state;
        //prompt and read the customer ZIP code
        cout << "Enter the ZIP code: ";
        cin >> obj.ZIP_code;
        //prompt and read the customer telephone number
        cout << "Enter the telephone number: ";
        cin >> obj.telephoneNumber;

        //prompt and read the customer account balance
        cout << "Enter the account balance: $";
        cin >> obj.accountBalance;
        //check for the invalid daetails
        while (obj.accountBalance < 0)
        {
                cout << "Enter the positive value: $";
                cin >> obj.accountBalance;
        }
        //prompt and read the date of last payment
        cout << "Enter the date of last payment in the form of - dd/mm/yyyy: ";
        cin >> obj.dateOfLastPayment;
        //return the object of the array
        return obj;
}
//implement method to return the customer number
int getCustomer(CustomerAccount cust[], int size, string name)
{
        int customer_number = -1;
        for (int i = 0; i <= size; i++)
        {
                if (cust[i].cust_name == name)
                {
                        customer_number = i;
                        break;
                }
        }
        return customer_number;
}

//implement method to dsiplay the list of custmers
void displayDetails(CustomerAccount customers[], int size)
{
        //if size is 0
        if (size == 0)
        {
                //print message
                cout << endl
                     << "No customers in the array to display" << endl;
        }
        //otherwise print the details of each customer
        else
        {
                for (int i = 0; i < size; i++)
                {
                        cout << endl;
                        cout << "Customer name: "
                             << customers[i].cust_name << endl;
                        cout << "Customer address: "
                             << customers[i].cust_address << endl;
                        cout << "City: " << customers[i].cust_city << endl;
                        cout << "State: " << customers[i].cust_state << endl;
                        cout << "ZIP code: " << setprecision(10)
                             << customers[i].ZIP_code << endl;
                        cout << "Telephone: " << setprecision(15)
                             << customers[i].telephoneNumber << endl;
                        cout << "Account balance: $" << setprecision(15)
                             << customers[i].accountBalance << endl;
                        cout << "Date of last payment: "
                             << customers[i].dateOfLastPayment << endl;
                }
        }
}

Related Solutions

11.7: Customer Accounts Write a program that uses a structure to store the following data about...
11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Prompts And...
Write a program that uses a structure to store the following data about a customer account:...
Write a program that uses a structure to store the following data about a customer account: Name Address City, State and Zip Telephone number Account balance Date of last payment The program should use an array of at least 5 structures. It should let the user enter data into the array, change the contents of any element and display all the data stored in the array. The program should have a menu-driven interface and use functions as appropriate. Input validation:...
Write a program that uses a structure to store the following weather data for a particular...
Write a program that uses a structure to store the following weather data for a particular month: Total Rainfall High Temperature Low Temperature Average Temperature. The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. (The average temperature should be calculated.) Once the data are entered for all the months, the program should calculate and display the average...
Write a program that uses a structure to store the following data: (Remember to use proper...
Write a program that uses a structure to store the following data: (Remember to use proper formatting and code documentation) Member Name Description name student name idnum Student ID number Scores [NUM_TESTS] an array of test scores Average Average test score Grade Course grade Declare a global const directly above the struct declaration const int NUM_TESTS = 4; //a global constant The program should ask the user how many students there are and should then dynamically allocate an array of...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write a C program that will read different data types from the following file and store...
Write a C program that will read different data types from the following file and store it in the array of structures. Given file: (This file have more than 1000 lines of similar data): time latitude longitude depth mag magType nst gap dmin 2020-10-19T23:28:33.400Z 61.342 -147.3997 12.3 1.6 ml 12 84 0.00021 2020-10-19T23:26:49.460Z 38.838501 -122.82684 1.54 0.57 md 11 81 0.006757 2020-10-19T23:17:28.720Z 35.0501667 -117.6545 0.29 1.51 ml 17 77 0.1205 2020-10-19T22:47:44.770Z 38.187 -117.7385 10.8 1.5 ml 15 100.22 0.049 2020-10-19T22:42:26.224Z...
Write a C++ program that uses array to store the salaries of 10 employees working in...
Write a C++ program that uses array to store the salaries of 10 employees working in a small firm. The program should take average of the salaries and the max and min salaries being paid to the employees
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Write a C program that contains a structure that uses predefined types and union. • Create...
Write a C program that contains a structure that uses predefined types and union. • Create a struct with name, age, kind (Either child, college student, or adult), and kindOfPerson (Either kid, student, or adult) • kids have a school field. Students have college and gpa. Adults have company and salary. • Create one non-dynamic struct with the content for a college student: "Bob", 20, K-State, 3.5 • Create one struct dynamically for a kid with: "Alison", 10, "Amanda Arnold...
3. Write a C++ program that takes in the name of a store, and the following...
3. Write a C++ program that takes in the name of a store, and the following details for 4 employees working at the store; their first name, last name, number of hours they worked that week and how much they are paid per hour. Your program should output the name of the store, along with each employee's full name and how much they earned that week in the manner below. Monetary values should be format to 2 decimal places. Also...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT