Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ Please create the program Customer Accounts write a program that uses a s

ID: 3809310 • Letter: I

Question

In C++

Please create the program

Customer Accounts

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 10 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.

Input validation: When the data for a new account is entered, user must enter all fields. No negative account balances should be entered.

Explanation / Answer

Here is the code for you:

#include <iostream>
using namespace std;

struct CustomerAccount
{
    string name;
    string city;
    string state;
    string zip;
    string telephoneNumber;
    double accountBalance;
    string dateOfLastPayment;
};

void addNewAccount(CustomerAccount customer[], int &count)
{
    cout << "Enter the customer name: ";
    cin >> customer[count].name;
    cout << "Enter the city: ";
    cin >> customer[count].city;
    cout << "Enter the state: ";
    cin >> customer[count].state;
    cout << "Enter the zip code: ";
    cin >> customer[count].zip;
    cout << "Enter the telephone number: ";
    cin >> customer[count].telephoneNumber;
    cout << "Enter the account balance: ";
    cin >> customer[count].accountBalance;
    while(customer[count].accountBalance < 0)
    {
       cout << "Account balance cannot be negative..." << endl;
       cout << "Enter the account balance: ";
        cin >> customer[count].accountBalance;
    }
    cout << "Enter the date of last payment: ";
    cin >> customer[count].dateOfLastPayment;
    count++;
}
void updateAddress(CustomerAccount customer[], int count)
{
    int num;
    cout << "We have a total of " << count << " customers." << endl;
    cout << "Enter the number of customer you want to change the address: ";
    cin >> num;
    cout << "Enter the city: ";
    cin >> customer[num-1].city;
    cout << "Enter the state: ";
    cin >> customer[num-1].state;
    cout << "Enter the zip code: ";
    cin >> customer[num-1].zip;
}
void updatePhone(CustomerAccount customer[], int &count)
{
    int num;
    cout << "We have a total of " << count << " customers." << endl;
    cout << "Enter the number of customer you want to change the phone number: ";
    cin >> num;
    cout << "Enter the phone number: ";
    cin >> customer[num-1].telephoneNumber;
}
void depositAmount(CustomerAccount customer[], int &count)
{
    int num;
    cout << "We have a total of " << count << " customers." << endl;
    cout << "Enter the number of customer you want to deposit to: ";
    cin >> num;
    cout << "Enter the amount to deposit: ";
    double amount;
    cin >> amount;
    while(amount < 0)
    {
       cout << "You should deposit a positive value..." << endl;
       cout << "Enter the amount to deposit: ";
       cin >> amount;
    }
    customer[num-1].accountBalance += amount;
}

void withdrawAmount(CustomerAccount customer[], int &count)
{
    int num;
    cout << "We have a total of " << count << " customers." << endl;
    cout << "Enter the number of customer you want to withdraw from: ";
    cin >> num;
    cout << "Enter the amount to withdraw: ";
    double amount;
    cin >> amount;
    while(amount < 0)
    {
       cout << "You should withdraw a positive value..." << endl;
       cout << "Enter the amount to withdraw: ";
       cin >> amount;
    }
    if(amount > customer[num-1].accountBalance)
        cout << "Insufficient balance.... Can't process your request..." << endl;
    else
        customer[num-1].accountBalance -= amount;
}
void getPaymentDate(CustomerAccount customer[], int &count)
{
    int num;
    cout << "We have a total of " << count << " customers." << endl;
    cout << "Enter the number of customer you want to retrieve the payment date: ";
    cin >> num;
    cout << customer[num-1].dateOfLastPayment << endl;
}
int main()
{
    CustomerAccount customers[10];
    int numOfCustomers = 0, choice;
    while(true)
    {
       cout << "1. Add a new account." << endl;
       cout << "2. Update Address." << endl;
       cout << "3. Update Phone number." << endl;
       cout << "4. Deposit Amount." << endl;
       cout << "5. Withdraw Amount." << endl;
       cout << "6. Get last payment date." << endl;
       cout << "7. Quit." << endl;
       cout << "Enter your choice: ";
       cin >> choice;
       switch(choice)
       {
          case 1:       addNewAccount(customers, numOfCustomers); break;
          case 2:       updateAddress(customers, numOfCustomers); break;
          case 3:       updatePhone(customers, numOfCustomers); break;
          case 4:       depositAmount(customers, numOfCustomers); break;
          case 5:       withdrawAmount(customers, numOfCustomers); break;
          case 6:       getPaymentDate(customers, numOfCustomers); break;
          case 7:       return 0;
          default:   cout << "Invalid option." << endl;
       }
    }
}