Home > Back-end >  Could you tell me the bank account management system (binary file storage) is what will appear when
Could you tell me the bank account management system (binary file storage) is what will appear when

Time:09-21

this is the run results:

This is a function of its registered accounts (input binary function) :
 void show1 () {
//initialization information
Cout & lt; <"Please enter account:";
String acNumber;
Cin & gt;> AcNumber;
Cout & lt; <"Please input the user name:";
String name;
Cin & gt;> name;
Cout & lt; <"Please enter the id number:";
String id;
Cin & gt;> Id;
Cout & lt; <"Please enter the address:";
String addr.
Cin & gt;> Addr.
Cout & lt; <"Please enter the amount of deposit:";
Double sumOfMonney;
Cin & gt;> SumOfMonney;
//cout & lt; <"Please set the account password:";
String p;
P=getPassword ();
//create account
The Account newaccount (acNumber, id, name, addr, sumOfMonney, p);

//open a binary file storage account
String fname="storeInfo";
Fstream fs (fname, the ios: : binary | ios: : out);
if (! Fs) {
Cout & lt; <"Store file open failed" & lt; }
//acNumber
Int len=newaccount. GetAcNumber (.) length ();
Fs. Write ((char *) & amp; Len, sizeof (int));
Fs. Write (newaccount. GetAcNumber () c_str (), len);
//id
Len=newaccount. GetID (). The length ();
Fs. Write ((char *) & amp; Len, sizeof (int));
Fs. Write (newaccount. GetID () c_str (), len);
//the name
Len=newaccount. GetName (). The length ();
Fs. Write ((char *) & amp; Len, sizeof (int));
Fs. Write (newaccount. GetName () c_str (), len);
//addr
Len=newaccount. GetAddr (.) length ();
Fs. Write ((char *) & amp; Len, sizeof (int));
Fs. Write (newaccount. GetAddr () c_str (), len);
//sumOfMonney
Double s=newaccount. GetSumOfMonney ();
Fs. Write ((char *) & amp; S, sizeof (double));
//password
Len=newaccount. GetPassword (.) length ();
Fs. Write ((char *) & amp; Len, sizeof (int));
Fs. Write (newaccount. GetPassword () c_str (), len);
//state
Bool state=true;
Fs. Write ((char *) & amp; The state, sizeof (bool));
//close the file
Fs. Flush ();
Fs. The close ();
Cout & lt; <"New account success!" }

This is a function of its display user information
//read the account information 
Void show2 () {
//according to the index of information user accounts
Cout & lt; <"Please input your account:" & lt; String num.
Cin & gt;> Num.
Fstream fs (" storeInfo ", the ios: : binary | ios: : in);
if (! Fs) {
Cout & lt; <"Failed to read the account information, please ensure the account has been established," & lt;
}
The Account a;
//determine whether file index finished
while (! Fs. Eof ()) {
Char buffer [100]={0};
Int len=0;
//acNumber
Fs. Read ((char *) & amp; Len, sizeof (int));
Fs. Read (buffer, len);
A.s etAcNumber (buffer);
//id
Fs. Read ((char *) & amp; Len, sizeof (int));
Fs. Read (buffer, len);
A.s etID (buffer);
//the name
Fs. Read ((char *) & amp; Len, sizeof (int));
Fs. Read (buffer, len);
A.s etName (buffer);
//addr
Fs. Read ((char *) & amp; Len, sizeof (int));
Fs. Read (buffer, len);
A.s etAddr (buffer);
//sumOfMonney
Double monney=0;
Fs. Read ((char *) & amp; Monney, sizeof (double));
A.s etSumOfMonney (monney);
//password
Fs. Read ((char *) & amp; Len, sizeof (int));
Fs. Read (buffer, len);
A.s etPassword (buffer);
//state
Bool state=true;
Fs. Read ((char *) & amp; The state, sizeof (bool));
Fs. Read (buffer, len);
A.s etState (buffer);
//find user accounts
If (al-qeada etAcNumber ()==num) {
//the password protect user account
for (int i=0; I & lt; 3; I++) {
Cout & lt; <"Please first" & lt; String p;
P=getPassword ();
//password input is correct, according to user information
If (p==al-qeada etPassword ()) {
A.s howInfo ();
Fs. The close ();

return;
}
//input error, and input the opportunity
The else {
If (I & lt; 2)
Cout & lt; <"Wrong password, please enter again." & lt; }

}
//input number out, back to the main menu
Cout & lt; <"Password is not correct,";

return;
}

}
//not index to the account
Cout & lt; <"This account was not found, please register" & lt;

}

CodePudding user response:

Read/write a string, it is best to get the length information is accurate

CodePudding user response:

reference 1/f, the truth is right or wrong response:
, speaking, reading and writing string, best to get the length information accurate
how clear ah, this all have already took the length, feeling eventually use char to change come back,

CodePudding user response:

Learn to step through, see what was read out?

CodePudding user response:

The
reference 2 floor? A???? Q reply:
Quote: reference 1/f, the truth is right or wrong response:
, speaking, reading and writing string, best to get the length information accurate
how clear ah, this all have already took the length, feeling eventually use char to change back,

Because buffer began to read a long back and read the short, so read behind the front end will contain the value, each time you read the new fields, memset

CodePudding user response:

refer to 4th floor, Simple, Soft reply:
Quote: refer to the second floor? A???? Q reply:
Quote: reference 1/f, the truth is right or wrong response:
, speaking, reading and writing string, best to get the length information accurate
how clear ah, this all have already took the length, feeling eventually use char to change back,

Because buffer began to read a long back and read the short, so read behind the front end will contain the value, each time you read the new fields, memset

Because when read read will not be attached at the back endnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related