Customer Accounts Write a program that uses a structure to store the following d
ID: 3917887 • Letter: C
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 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.
C++ Programming
Explanation / Answer
Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
struct Customer{
string name;
string address;
string city;
string state;
string zip;
string telephone;
double balance;
string lastPaidDate;
};
void printCustomer(const Customer &c);
void printAll(Customer c[], int n);
void inputCustomer(Customer &c);
void updateCustomer(Customer c[], int n);
int main(){
int choice = 0;
Customer customers[20];
int n = 0;
while(choice != 4){
cout << "1. Enter new account information" << endl;
cout << "2. Change account information" << endl;
cout << "3. Display all account information" << endl;
cout << "4. Exit" << endl;
cout << "Enter your choice: ";
cin >>choice;
cin.ignore(); // get rid of newline
switch(choice){
case 1:
inputCustomer(customers[n]);
cout << "You have entered information for customer #" << n << endl;
n++;
break;
case 2:
updateCustomer(customers, n);
break;
case 3:
printAll(customers, n);
break;
case 4:
break;
default:
cout << "Invalid menu choice!" << endl;
}
cout << endl << endl;
}
}
void printCustomer(const Customer &c){
cout << "Customer name: " << c.name << endl;
cout << "Customer address: " << c.address << endl;
cout << "City: " << c.city << endl;
cout << "State: " << c.state << endl;
cout << "Zip code: " << c.zip << endl;
cout << "Telephone: " << c.telephone << endl;
cout << "Account balance: $" << c.balance << endl << endl;
system("pause");
}
void printAll(Customer c[], int n){
for(int i = 0; i < n; i++){
cout << "Customer #" << i << endl;
printCustomer(c[i]);
}
}
void inputCustomer(Customer &c){
cout << "Name: ";
getline(cin, c.name);
cout << "Address: ";
getline(cin, c.address);
cout << "City: ";
getline(cin, c.city);
cout << "State: ";
getline(cin, c.state);
cout << "Zip code: ";
cin >> c.zip;
cout << "Telephone: ";
cin >> c.telephone;
cout << "Account balance: ";
cin >> c.balance;
while(c.balance < 0){
cout << "Invalid account balance. Please enter again: ";
cin >> c.balance;
}
}
void updateCustomer(Customer c[], int n){
int index;
cout << "Enter customer number to change: ";
cin >> index;
cin.ignore();
if(index <0 || index >= n)
cout << "Invalid customer number!" << endl;
else {
cout << "Existing customer information" << endl;
printCustomer(c[index]);
cout << endl;
cout << "Enter new details for the customer #" << index << endl;
inputCustomer(c[index]);
cout << "Updated information for customer #" << index << endl;
}
}
output
======
1. Enter new account information
2. Change account information
3. Display all account information
4. Exit
Enter your choice: 1
Name: John Smith
Address: aaaaa
City: cccc
State: ssss
Zip code: 12222
Telephone: 33333
Account balance: 1000
You have entered information for customer #0
1. Enter new account information
2. Change account information
3. Display all account information
4. Exit
Enter your choice: 1
Name: Bob
Address: addadad
City: cdifdfs
State: sste
Zip code: 44444
Telephone: 5554555
Account balance: 2000
You have entered information for customer #1
1. Enter new account information
2. Change account information
3. Display all account information
4. Exit
Enter your choice: 3
Customer #0
Customer name: John Smith
Customer address: aaaaa
City: cccc
State: ssss
Zip code: 12222
Telephone: 33333
Account balance: $1000
sh: pause: command not found
Customer #1
Customer name: Bob
Customer address: addadad
City: cdifdfs
State: sste
Zip code: 44444
Telephone: 5554555
Account balance: $2000
1. Enter new account information
2. Change account information
3. Display all account information
4. Exit
Enter your choice: 2
Enter customer number to change: 1
Existing customer information
Customer name: Bob
Customer address: addadad
City: cdifdfs
State: sste
Zip code: 44444
Telephone: 5554555
Account balance: $2000
Enter new details for the customer #1
Name: Alice
Address: trririri
City: yiryir
State: lllkf
Zip code: 99999
Telephone: 6666
Account balance: 3000
Updated information for customer #1
1. Enter new account information
2. Change account information
3. Display all account information
4. Exit
Enter your choice: 3
Customer #0
Customer name: John Smith
Customer address: aaaaa
City: cccc
State: ssss
Zip code: 12222
Telephone: 33333
Account balance: $1000
Customer #1
Customer name: Alice
Customer address: trririri
City: yiryir
State: lllkf
Zip code: 99999
Telephone: 6666
Account balance: $3000
1. Enter new account information
2. Change account information
3. Display all account information
4. Exit
Enter your choice: 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.