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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include <cstdlib>
#include <iostream>
#include <ctype.h>
using namespace std;
void Menu( int & choice);
void enterCustomer( int i, char cArray[][25], int rows);
void enterAccNum( int i, char accArray[][6],int rows, int & runningC, int & runningD);
void enterBalance( int & i, float bArray[], int rows);
void updateAccount( int i, char accArray[][6], char cArray[][25], int rows, int & runningC, int & runningD);
int main(int argc, char *argv[])
{
int choice, i=0, runningC=10000, runningD=10000;
float balArray[20];
char cArray[20][25], accArray[20][6];
do{
Menu(choice);
cin.ignore();
switch( choice)
{
case 1 : enterCustomer( i, cArray, 20);
enterAccNum(i, accArray,20, runningC, runningD);
enterBalance( i, balArray, 20);
break;
case 2 : updateAccount( accArray, cArray, 20, runningC, runningD);
break;
default : cout <<"About to exit "<<endl;
}
} while( choice != 4);
system("PAUSE");
return EXIT_SUCCESS;
}
void Menu( int & choice)
{
cout << " 1\t enter details"<<endl;
cout <<" 2\t update details"<<endl;
cout <<" 4 \t exit system"<<endl;
cout <<"Enter choice "<<endl;
cin >> choice;
}
//----------------------------------------------------
//enter customer name
//----------------------------------------------------
void enterCustomer( int i, char cArray[][25], int rows)
{
if ( i < rows )
{
cout << "Enter Customer name"<<endl;
cin.getline(cArray[i], 25 +1);
}
}
void enterAccNum( int i, char accArray[][6],int rows, int & runningC, int & runningD)
{
char reqChoice;
if ( i < rows)
{
cout << "Enter C for current and D for Deposit"<<endl;
cin >>reqChoice;
reqChoice = toupper( reqChoice );
cout<<"Test 1" <<reqChoice<<endl;
char tempChoice[2];//change char to tempChoice cstring
tempChoice[0] = reqChoice;
tempChoice[1] = '\0';
char runningStr[6];
if ( strcmp(tempChoice, "C") ==0)
{
itoa( runningC, runningStr, 10);
strcat( runningStr, tempChoice);
cout << "Test 2 " <<runningC<<endl;
cout << "Test 3 " <<runningStr<<endl;
runningC++;
}
else
{
itoa( runningD, runningStr, 10);
strcat( runningStr, tempChoice);
runningD++;
}
strcpy( accArray[i], runningStr);
cout <<"accArray[0] "<<accArray[0]<<endl;
}
else
{
cout <<" No more accounts available"<<endl;
}
}
void enterBalance( int & i, float bArray[], int rows)
{
if( i < rows)
{
cout << "Enter balance "<<endl;
cin >> bArray[i];
cout << endl;
}
else
cout << "Too many accounts"<<endl;
}
void updateAccount( char accArray[][6], char cArray[][25], int rows, int & runningC, int & runningD)
{
char name[25];
int j =0;
char typeAcc;
cout << "Enter customer name"<<endl;
cin.getline(name, 25+1);
while( strcmp(cArray[j], name ) != 0 )
{ j++;}
int len = strlen(accArray[j]);
//get the last character 'C' or 'D' from the given string at j
char ch = accArray[j][len -1];
//convert from character e.g 'C' to "C"
char tempCh[2];
tempCh[0] = ch;
tempCh[1] = '\0';
//blank out the strings
char runningStr[6];
strcpy(runningStr, "");
strcpy(accArray[j], "");
//if character is a "C" convert to a "D"
//note the name & balance remain the same - still at same indexed position j
if ( strcmp( "C" , tempCh) ==0 )
{
itoa(runningD, runningStr, 10);
runningC++;
strcat(runningStr, "D");
}
else
{
itoa( runningC, runningStr, 10);
runningD++;
strcat(runningStr, "C");
}
strcpy(accArray[j], runningStr);
cout << "New accArray updated" <<accArray[j]<<endl;
}
|