Question
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
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.
Here is the code I've been working with:
#include
using namespace std;
struct Customer { string name; string address; string city; string state; string zipCode; string telephone; double balance; string date; };
int main(){
int n, custNo; Customer list[50]; int count = 0; while(true){ cout << "1.Enter new account information "; cout << "2.Change account information "; cout << "3.Display all account information "; cout << "4.Exit the program ";
cout << "Enter choice "; cin >> n; cin.get(); if (n == 4) break; if (n == 1){ cout << "Customer Name:"; cin >> list[count].name; cout << "Customer Address:" ; cin >> list[count].address; cout << "City:" ; cin >> list[count].city; cout << "Zip code:"; cin >> list[count].zipCode; cout << "Telephone:"; cin >> list[count].telephone; do { cout << "Account balance:"; cin >> list[count].balance; if (list[count].balance < 0){ cout << "Balance can not be negative "; } } while (list[count].balance < 0); cout << "Date of last payment:"; cin >> list[count].date; cout << endl; cout << "You have entered information for customer number " << count+1 << endl; cout << "Customer Name:" << list[count].name << endl; cout << "Customer Address:" << list[count].address << endl; cout << "City:" << list[count].city << endl; cout << "Zip code:" << list[count].zipCode << endl; cout << "Telephone:" << list[count].telephone << endl; cout << "Account balance:" << fixed << setprecision(2) << list[count].balance << endl; cout << "Date of last payment:" << list[count].date << endl; cout << endl << endl; count++; } if (n == 2){ cout << "Cutomer number:"; cin >> custNo; if (custNo > count){ cout << "Invalid number "; continue; } cout << "Customer Name:" << list[custNo-1].name << endl; cout << "Customer Address:" << list[custNo-1].address << endl; cout << "City:" << list[custNo-1].city << endl; cout << "Zip code:" << list[custNo-1].zipCode << endl; cout << "Telephone:" << list[custNo-1].telephone << endl; cout << "Account balance:" << fixed << setprecision(2) << list[custNo-1].balance << endl; cout << "Date of last payment:" << list[custNo-1].date << endl; cout << " "; cout << "Enter changes: "; cout << "Customer Name:"; cin >> list[custNo-1].name; cout << "Customer Address:"; cin >> list[custNo-1].address; cout << "City:"; cin >> list[custNo-1].city; cout << "Zip code:"; cin >> list[custNo-1].zipCode; cout << "Telephone:"; cin >> list[custNo-1].telephone; do { cout << "Account balance:"; cin >> list[custNo-1].balance; if (list[custNo-1].balance < 0){ cout << "Balance can not be negative "; } } while (list[custNo-1].balance < 0);
cout << "Date of last payment:"; cin >> list[custNo-1].date; count++; cout << "You have entered information for customer number " << custNo << endl; cout << "Customer Name:" << list[custNo-1].name << endl; cout << "Customer Address:" << list[custNo-1].address << endl; cout << "City:" << list[custNo-1].city << endl; cout << "Zip code:" << list[custNo-1].zipCode << endl; cout << "Telephone:" << list[custNo-1].telephone << endl; cout << "Account balance:" << fixed << setprecision(2) << list[custNo-1].balance << endl; cout << "Date of last payment:" << list[custNo-1].date << endl; cout << endl << endl; }
if (n == 3){ for (int i = 0; i < count; i++){ cout <<"---------------------------------------------------- "; cout << "Customer Number:" << i+1 << endl; cout << "Customer Name:" << list[i].name << endl; cout << "Customer Address:" << list[i].address << endl; cout << "City:" << list[i].city << endl; cout << "Zip code:" << list[i].zipCode << endl; cout << "Telephone:" << list[i].telephone << endl; cout << "Account balance:" << fixed << setprecision(2) << list[i].balance << endl; cout << "Date of last payment:" << list[i].date << endl; cin.get(); } } }
return 0; }
Some problems that I've been having is that the output keeps wanting to print on the same line instead of separate lines. Also, it is not printing what customer # I've created after filling in Option 1. I tried to post a picture of my output, but it would not let me. So, I will post what comes up in the exact format that my output is. Also, the code should be done in C++ please.
Here is what my outputs looks like when I am typing in the info for Option 1:
1.Enter new account information
2.Change account information
3.Display all account information
4.Exit the program
Enter choice
1
Customer Name: Grace
Customer Address: 234 Rover Oaks
City:Zip code:Telephone: 23456
Account balance: 234
Here is what it looks like after putting in all of the info:
1.Enter new account information
2.Change account information
3.Display all account information
4.Exit the program
Enter choice
1
Customer Name: Girl
Customer Address: 234 Rover Oaks Lane
City:Zip code:Telephone:Account balance: 77494
Date of last payment: 12/12/1222
You have entered information for customer number 1
Customer Name:Girl
Customer Address:234
City:Rover
Zip code:Oaks
Telephone:Lane
Account balance:77494.00
Date of last payment:12/12/1222
1.Enter new account information
2.Change account information
3.Display all account information
4.Exit the program
Enter choice
Thank you in advance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started