***** Please read the requirements in details then write a program and test to s
ID: 3738668 • Letter: #
Question
***** Please read the requirements in details then write a program and test to see if it works before answering ***** Thank you a lot for your help!!!
Write a C++ program that uses a structure to store the following data about a customer account : Name ; Address; City, State and Zip; Phone#; 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 contents of any element, and display all of the data stored in the array. The program needs to have Menu-driven user interface.
Input Validation: 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.
THEN
Add a function that allows the user to search the structure array for a particular customer's account. It needs to accept part of the customer's name as an argument and then search for an account with a name that matches it. All accounts that match should be displayed. If no account matches, a message saying so should be displayed.
Explanation / Answer
Hello, I have a solution for you. Implemented everything as per the requirements.
//code.cpp
#include<iostream>
#define MAX_ACCOUNTS 10
using namespace std;
//structure to define a customer account
struct Account{
string name;
string address;
string city;
string state;
string zip;
string phone;
double balance;
string dateOfLastPayment;
};
//variable to keep the track of added accounts
int numAccounts=0;
//defining an array of 10 accounts
Account accounts[MAX_ACCOUNTS];
//method to display the menu
void displayMenu(){
cout<<"1. Add Account"<<endl;
cout<<"2. Edit Account"<<endl;
cout<<"3. Display Accounts"<<endl;
cout<<"4. Search Account"<<endl;
cout<<"5. Quit"<<endl;
cout<<"## Enter your choice: ";
}
//method to add an account
void addAccount(){
if(numAccounts==MAX_ACCOUNTS){
cout<<"Array is full!"<<endl;
}else{
string name,address,city,zip,state,phone,date;
double balance;
cout<<"Enter name: ";
cin>>name;
cout<<"Enter address: ";
cin>>address;
cout<<"Enter city: ";
cin>>city;
cout<<"Enter zip: ";
cin>>zip;
cout<<"Enter state: ";
cin>>state;
cout<<"Enter phone: ";
cin>>phone;
cout<<"Enter date of last payment: ";
cin>>date;
do{
cout<<"Enter balance: ";
cin>>balance;
}while(balance<0);
Account acc;
acc.name=name;
acc.address=address;
acc.city=city;
acc.balance=balance;
acc.dateOfLastPayment=date;
acc.zip=zip;
acc.state=state;
acc.phone=phone;
accounts[numAccounts]=acc;
numAccounts++;
}
}
//method to edit an account
void editAccount(){
cout<<"Enter name: ";
string name;
cin>>name;
bool found=false;
for(int i=0;i<numAccounts;i++){
if(accounts[i].name==name){
string address,city,zip,state,phone,date;
double balance;
cout<<"Enter new name: ";
cin>>name;
cout<<"Enter new address: ";
cin>>address;
cout<<"Enter new city: ";
cin>>city;
cout<<"Enter new zip: ";
cin>>zip;
cout<<"Enter new state: ";
cin>>state;
cout<<"Enter new phone: ";
cin>>phone;
cout<<"Enter date of last payment: ";
cin>>date;
do{
cout<<"Enter new balance: ";
cin>>balance;
}while(balance<0);
Account acc;
acc.name=name;
acc.address=address;
acc.city=city;
acc.balance=balance;
acc.dateOfLastPayment=date;
acc.zip=zip;
acc.state=state;
acc.phone=phone;
accounts[i]=acc;
found=true;
break;
}
}
if(!found){
cout<<"Account not found"<<endl;
}
}
//method to display all accounts
void displayAccounts(){
cout<<"...Accounts..."<<endl;
for(int i=0;i<numAccounts;i++){
cout<<"Name: "<<accounts[i].name<<endl;
cout<<"Balance: "<<accounts[i].balance<<endl;
cout<<"Address: "<<accounts[i].address<<endl;
cout<<"City: "<<accounts[i].city<<endl;
cout<<"Zip: "<<accounts[i].zip<<endl;
cout<<"State: "<<accounts[i].state<<endl;
cout<<"Phone: "<<accounts[i].phone<<endl;
cout<<"Date of last payment: "<<accounts[i].dateOfLastPayment<<endl;
cout<<endl;
}
cout<<"..._______..."<<endl;
}
//method to search for an account by name
void searchAccount(string name){
bool found=false;
for(int i=0;i<numAccounts;i++){
if(accounts[i].name==name){
cout<<"Name: "<<accounts[i].name<<endl;
cout<<"Balance: "<<accounts[i].balance<<endl;
cout<<"Address: "<<accounts[i].address<<endl;
cout<<"City: "<<accounts[i].city<<endl;
cout<<"Zip: "<<accounts[i].zip<<endl;
cout<<"State: "<<accounts[i].state<<endl;
cout<<"Phone: "<<accounts[i].phone<<endl;
cout<<"Date of last payment: "<<accounts[i].dateOfLastPayment<<endl;
cout<<endl;
found=true;
}
}
if(!found){
//not found
cout<<"Account not found"<<endl;
}
}
int main(){
int choice=0;
//looping until user wishes to quit
do{
displayMenu();
cin>>choice;//getting choice
switch(choice){
case 1: addAccount();//adding an account
break;
case 2: editAccount();//editing an account
break;
case 3: displayAccounts();//displaying all accounts
break;
case 4: cout<<"Enter name: ";
string name;
cin>>name;
searchAccount(name);//searching for an account
break;
}
}while(choice!=5);
return 0;
}
/*OUTPUT*/
1. Add Account
2. Edit Account
3. Display Accounts
4. Search Account
5. Quit
## Enter your choice: 1
Enter name: Alice
Enter address: Wonderland
Enter city: Texas
Enter zip: 667-889
Enter state: ABC
Enter phone: 1233-7762
Enter date of last payment: 11/03/2018
Enter balance: -25
Enter balance: 200
1. Add Account
2. Edit Account
3. Display Accounts
4. Search Account
5. Quit
## Enter your choice: 3
...Accounts...
Name: Alice
Balance: 200
Address: Wonderland
City: Texas
Zip: 667-889
State: ABC
Phone: 1233-7762
Date of last payment: 11/03/2018
..._______...
1. Add Account
2. Edit Account
3. Display Accounts
4. Search Account
5. Quit
## Enter your choice: 4
Enter name: Alice
Name: Alice
Balance: 200
Address: Wonderland
City: Texas
Zip: 667-889
State: ABC
Phone: 1233-7762
Date of last payment: 11/03/2018
1. Add Account
2. Edit Account
3. Display Accounts
4. Search Account
5. Quit
## Enter your choice: 4
Enter name: Bob
Account not found
1. Add Account
2. Edit Account
3. Display Accounts
4. Search Account
5. Quit
## Enter your choice: 5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.