In: Computer Science
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
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;
}
}
}