1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
const int MAX_NUM = 30;
int main(){
int acctnum_array[MAX_NUM];
double balance_array[MAX_NUM];
int read_accts(int[], double[], int);
void print_accts(int[], double[],int);
void menu ();
int findacct(int[],int,int);
int new_acct(int [], double [],int);
int numaccts;
char selection; // type of transaction selected
bool cond=false; //used as condition for the do-while loop
cout.setf(ios::fixed,ios::floatfield);
cout.precision(2); //set decimal precision
//reads in data
numaccts=read_accts(acctnum_array,balance_array,MAX_NUM);
print_accts(acctnum_array,balance_array,numaccts);
do{
menu();
cin>>selection;
switch (selection)
{
case 'W':
case 'w':
withdrawal(acctnum_array,balance_array,numaccts);
break;
case 'D':
case 'd':
deposit(acctnum_array,balance_array,numaccts);
break;
case 'N':
case 'n':
numaccts=new_acct(acctnum_array,balance_array,numaccts);
break;
case 'B':
case 'b':
balance(acctnum_array,balance_array,numaccts);
break;
case 'Q':
case 'q':
print_accts(acctnum_array,balance_array,numaccts);
cond=true;
break;
default:
cout<<"\nThis selection was not valid, Please try again "<<endl<<endl;
break;
}
}while (cond!=true);
return 0;
}
int read_accts(int acctnum_array[], double balance_array[], int max_accts)
{
ifstream infile;
infile.open("c:\\c++\\prg6input.txt");
int num_accts=0,x;
double y;
infile>>x;
while(!infile.eof()&& num_accts< max_accts){
acctnum_array[num_accts]=x;
infile>>y;
balance_array[num_accts]=y;
num_accts++;
infile>>x;
}
infile.close();
return num_accts;
}
void print_accts(int acctnum_array[], double balance_array[], int num_accts)
{
for ( int i=0; i<num_accts;i++){
cout<<"Account number: "<<acctnum_array[i]<<" has a balance of ";
cout<<balance_array[i]<<endl<<endl;
}
return;
}
void menu()
{
cout<<"\nSelect one of the following options"<<endl;
cout<<"W - Withdrawal"<<endl;
cout<<"D - Deposit"<<endl;
cout<<"N - New Account"<<endl;
cout<<"B - Balance"<<endl;
cout<<"Q - Quit"<<endl;
return;
}
int findacct(int acctnum_array[], int num_accts, int account)
{
cout<<account<<endl;
cout<<num_accts<<endl;
int check=-1;
for(int i=0;i < num_accts;i++){
if (acctnum_array[i]==account)
check=i; //returns index number if account is valid
}
return check; //returns -1 if account is not valid
}
int new_acct(int acctnum_array[], double balance_array [], int num_accts)
{
int accountnum,index,newacct;
newacct=num_accts;
cout<<"\nPlease enter a new account number"<<endl;
cin>>accountnum;
index=findacct(acctnum_array,num_accts,accountnum);
if (index!=-1)
cout<<"\nThis account number already exists"<<endl;
else{
newacct=num_accts+1;
acctnum_array[newacct]=accountnum;
cout<<acctnum_array[newacct]<<endl;
balance_array[newacct]=5;
cout<<balance_array[newacct]<<endl;
cout<<"\nThis account has been processed and now has a balance of 0"<<endl;
print_accts(acctnum_array,balance_array,newacct);
}
return newacct;
}
|