in c with comments please 117 Customer Accounts Write a pro
in c++ with comments please :)
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.
Solution
Try this program it may helps you,
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
// Globals (Initialization)....
struct Info
{
string name;
string address;
string city;
string state;
string zip;
string tele;
double balance;
string date;
};
// using a Global variable here (to keep function calls simple ... to start)
vector < Info > Bank;
bool more();
Info takeIn();
void flushCin();
void newAcc();
void menu();
void showAll();
void editAcc( int );
int main()
{
for(;;) menu(); // loops forever ... until exit(1) called in menu ...
}
// defaults to no ...
bool more()
{
cout << \"More (y/n) ? \";
int reply = cin.get();
if(reply != \'\ \') flushCin();
return reply==\'y\' || reply==\'Y\';
}
void flushCin()
{
while( cin.get() != \'\ \' );
}
Info takeIn()
{
Info file;
bool ok;
do
{
cout << \"Name : \";
getline( cin, file.name );
cout << \"Address : \";
getline( cin, file.address );
cout << \"City : \";
getline( cin, file.city );
cout << \"State : \";
getline( cin, file.state );
cout << \"Zip : \";
getline( cin, file.zip );
cout << \"Tele : \";
getline( cin, file.tele );
cout << \"Date : \";
getline( cin, file.date );
for(;;) // forever loop ... until break
{
cout << \"Balance : \";
cin >> file.balance;
if( !cin.good() )
{
cout << \"\ ERROR! Entry NOT accepted! ... Re-enter numbers only!\ \";
cin.clear();
flushCin();
continue; // from the top of this inner \'for loop\' right now ...
}
// if reach here ... then a number was entered
flushCin();
break;
}
// confirm ok ...
cout<< \"\ You entered:\" << endl;
int w =45;
cout<< left;
cout<< setw(w) << \"Customer\'s name is \" << file.name << endl;
cout<< setw(w) << \"Customer\'s address is \" << file.address << endl;
cout<< setw(w) << \"Customer\'s current city of residence is \" << file.city << endl;
cout<< setw(w) << \"Customer\'s current state of residence is \" << file.state << endl;
cout<< setw(w) << \"Customer\'s zip code is \" << file.zip << endl;
cout<< setw(w) << \"Customer\'s current telephone number is \" << file.tele << endl;
cout<< setw(w) << \"Customer\'s late date of payment is \" << file.date << endl;
cout<< setw(w) << \"Customer\'s late recorded account balance is \" << file.balance << endl;
cout<< right;
cout << \"Ok ... (y/n) ? \";
int reply = cin.get();
if(reply != \'\ \') flushCin();
ok = (reply==\'y\' || reply==\'Y\'); // defaults to no ...
}while(!ok );
return file;
}
void menu()
{
cout << \"\ Welcome to you bank company.\ \"
<< \"Please choose an action from the menu displayed below.\ \ \"
<< \"Press 1 to enter a new account(s).\ \"
<< \"Press 2 to see ALL your current balances.\ \"
<< \"Press 3 to Change a account information.\ \"
<< \"Press 4 to exit.\ \ \"
<< \"Your choice : \" << flush;
string temp;
getline( cin, temp );
// convert temp to C string; atoi returns 0 if non-integer for first char\'s
int choice = atoi( temp.c_str() );
switch(choice)
{
case 1:
do { newAcc(); } while( more() );
break;
case 2:
cout << \"All your current account balances are ...\" << endl;
showAll();
break;
case 3:
showAll();
cout << \"\ Which account to edit ? \";
getline( cin, temp );
// convert temp to C string; atoi returns 0 if non-integer for first char\'s
choice = atoi( temp.c_str() );
editAcc( choice-1 );
break;
case 4:
exit(1);
default:
cout << \"\ Not a valid choice ...\" << endl;
}
}
void newAcc()
{
Info tmpFile = takeIn();
Bank.push_back( tmpFile );
}
void showAll()
{
int w = 45;
for(unsigned i = 0; i < Bank.size(); ++i )
{
cout<< setw(4) << \"Customer\'s number \" << i+1 << endl;
cout<< left;
cout<< setw(w) << \"Customer\'s name is \" << Bank[i].name << endl;
cout<< setw(w) << \"Customer\'s address is \" << Bank[i].address << endl;
cout<< setw(w) << \"Customer\'s current city of residence is \" << Bank[i].city << endl;
cout<< setw(w) << \"Customer\'s current state of residence is \" << Bank[i].state << endl;
cout<< setw(w) << \"Customer\'s zip code is \" << Bank[i].zip << endl;
cout<< setw(w) << \"Customer\'s current telephone number is \" << Bank[i].tele << endl;
cout<< setw(w) << \"Customer\'s late date of payment is \" << Bank[i].date << endl;
cout<< setw(w) << \"Customer\'s late recorded account balance is \" << Bank[i].balance << endl;
cout<< right << \"\ Press \'Enter\' to continue ... \";
flushCin(); // wait for Enter key press ...
}
}
void editAcc( int i )
{
if( i > int(Bank.size()) || i < 0 )
{
cout << \"\ No Account with this number \" << i+1 << endl;
return;
}
// ok ... Account exists ... so ...
cout << \"\ Enter new data ...\ \" << flush;
Info tmp = takeIn(); // example of editing all the data ...
Bank[i].name = tmp.name;
Bank[i].address = tmp.address;
Bank[i].city = tmp.city;
Bank[i].state = tmp.state;
Bank[i].zip = tmp.zip;
Bank[i].tele = tmp.tele;
Bank[i].date = tmp.date;
Bank[i].balance = tmp.balance;
}
Thank You.



