NAME
ADDRESS
CITY, STATE, AND ZIP
TELEPHONE NUMBER
ACCOUNT BALANCE
DATE OF LAST PAYMENT
The structure should be used to store customer account records in a file. The program should have a menu that lets the user perform the following operations:
• Enter new records into the file.
• Search for a particular customer’s record and display it.
• Search for a particular customer’s record and delete it.
• Search for a particular customer’s record and change it.
• Display the contents of the entire file.
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.
// info.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream?
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
struct Info
{
string name;
string address;
string city;
string state;
string zip;
string tele;
double balance;
string date;
};
vector < Info > Bank;
bool more();
Info takeIn();
void flushCin();
void newAcc();
void menu();
void showAll();
void editAcc( int );
int main()
{
for(;;)/> menu();
}
bool more()
{
cout << "More (y/n) ? ";
int reply = cin.get();
if(reply != '\n') flushCin();
return reply=='y' || reply=='Y';
}
void flushCin()
{
while( cin.get() != '\n' );
}
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 << "TELEPHONE NUMBER : ";
getline( cin, file.tele );
cout << "DATE OF LAST PAYMENT : ";
getline( cin, file.date );
for(;;)/>
{
cout << "Balance : ";
cin >> file.balance;
if( !cin.good() )
{
cout << "\nERROR! Entry NOT accepted! ... Re-enter numbers only!\n";
cin.clear();
flushCin();
continue;
flushCin();
break;
}
cout<< "\nYou 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 != '\n') flushCin();
ok = (reply=='y' || reply=='Y');
}while(!ok );
return file;
}
void menu()
{
cout << "\nWelcome to you bank company that has lost all your money.\n"
<< "Please choose an action from the menu displayed below.\n\n"
<< "Press 1 to enter a new account(s).\n"
<< "Press 2 to see ALL your current balances.\n"
<< "Press 3 to edit a current balance.\n"
<< "Press 4 to exit.\n\n"
<< "Your choice : " << flush;
string temp;
getline( cin, temp );
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 << "\nWhich account to edit ? ";
getline( cin, temp );
choice = atoi( temp.c_str() );
editAcc( choice-1 );
break;
case 4:
exit(1);
default:
cout << "\nNot 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 << "\nPress 'Enter' to continue ... ";
flushCin();
}
}
void editAcc( int i )
{
if( i > int(Bank.size()) || i < 0 )
{
cout << "\nNo Account with this number " << i+1 << endl;
return;
}
cout << "\nEnter new data ...\n" << flush;
Info tmp = takeIn();
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;
}

New Topic/Question
Reply



MultiQuote





|