Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Belowing is my c++ program about the bank account, but it does not work. I have

ID: 3869080 • Letter: B

Question

Belowing is my c++ program about the bank account, but it does not work. I have no idea about how to fix it, so does anybody can help me? Thanks a lot.

#include<iostream>

#include<string>

#include<fstream>

#include<iomanip>

#include<cctype>

#include<cstdlib>

#include<cmath>

using namespace std;

void new_line()

{

char symbol;

do{

cin.get(symbol);

}

while(symbol!=' ');

}

//Numeric conversion to a string

void int2str(int n,char *str)

{

char buf[10]="";

int i=0;

int len=0;

int temp=n<0?-n:n; //Temp is the absolute value of n

if(str==NULL)

{

return;

}

while(temp)

{

buf[i++]=(temp%10)+'0'; //Put the number of temp on each bit into buf

temp=temp/10;

}

len=n<0?++i:i; //If n is negative, then one more need to store the negative sign

str[i]=0; //The end is the end character 023

while(1)

{

i--;

if(buf[len-i-1]==0)

{

break;

}

str[i]=buf[len-n-1]; //Copy the characters in the buf array to the string

}

if(i==0)

{

str[i]='-'; //If it is negative, add a negative sign

}

} //The account and password used to manage the open program

void safe_conduct()

{

int input_num=0;

char un[11],pw[11];

cout<<"Please log in first Username19921005 Password0000"<<endl;

bool blag; //Logo wrong

do{

blag=0;

cout<<"Username";

cin>>un;

cout<<"Password";

cin>>pw;

if(strcmp(un,"19921005")!=0)

{

blag=0;

cout<<"Username entered incorrectly"<<endl;

}

if(!blag)

{

if(strcmp(pw,"0000")!=0)

{

blag=1;

cout<<"Password entered incorrectly"<<endl;

}

}

if(blag)

{

input_num++;

switch(input_num)

{

case 1:cout<<"You can also enter it twice"<<endl;

break;

case 2:cout<<"You can only enter it once"<<endl;

break;

case 3:cout<<"You do not have permission to continue typing and the program will close"<<endl;

exit(0);

}

}

}while(blag);

}

//Account class

class users

{

public:

users(ifstream &file_in); //Constructor, while reading account data from a file

users() //Overload the constructor so that it is used to open an account

{

balance=0;

next=NULL;

}

void new_user(); //Create new account information

void put_id(int id_new); //Get account number

char *get_id(); //Return account

char *get_password(); //Return password

char *get_name(); //Return username

char *get_id_card(); //Return ID

char *get_phone(); //Return Phone number

long get_balance(); //Return balance

void take_money(); //Take money

void saving(); //Saving

void saving(long money); //Turn into account

long virement(); //Transfer account

void out_to_file(ofstream &file_out); //Write into file

void out_to_screen(); //Output to the screen

void put_next(users *n); //Get the pointer

users *back_next(); //Return pointer

private:char id[5]; //Account

char password[7]; //Password

char name[9]; //Username

char id_card[18]; //ID

string company; //Company

char phone[11]; //Phone number

string address; //Address

long balance; //Balance

users *next; //Point to the next account

};

users::users(ifstream &file_in)

{

file_in>>id>>password>>name>>id_card>>company>>phone>>address>>balance;

next=NULL;

}

void users::new_user()

{ char new_pw[7],ok_new_pw[7];

cout<<"Please enter the Username";

cin>>name; bool blag;

do{ blag=0;

cout<<"Please enter the password";

cin>>new_pw;

for(char *i=new_pw;*i!='';i++)

{

if(*i<='!'||*i>='~')

{

blag=1;

cout<<"The password does not conform to the specification! please enter again"<<endl;

break;

}

}

cout<<"Confirm Password";

cin>>ok_new_pw;

if(strcmp(new_pw,ok_new_pw)!=0)

{

blag=1;

cout<<"The password is different"<<endl;

}

else blag=0;

}while(blag);

strcpy(password,new_pw);

cout<<"Please enter your ID";

cin>>id_card;

cout<<"Please enter your company";

cin>>company;

cout<<"Please enter your phone number";

cin>>phone;

cout<<"Please enter your address";

cin>>address;

cout<<endl;

cout<<"The account information you are applying for isAccount"<<id<<" Username"<<name<<" ID"<<id_card<<" Company"<<company<<" Phone number"<<phone<<" Address"<<address<<" Balance"<<balance<<endl<<endl<<endl;

}

void users::put_id(int id_new)

{

char new_id[5];

int num;

for(int i=3;i>=0;i--) //Numeric conversion to a string

{

num=id_new%10;

new_id[i]=num+'0';

id_new/=10;

}

new_id[4]='';

strcpy(id,new_id);

}

char *users::get_id()

{

return id;

}

char *users::get_password()

{

return password;

}

char *users::get_name()

{

return name;

}

char *users::get_id_card()

{

return id_card;

}

char *users::get_phone()

{

return phone;

}

long users::get_balance()

{

return balance;

}

void users::take_money()

{

if(balance<=0)

{

cout<<"Your balance is empty! Can not withdraw money! after the deposit can be re-taken"<<endl; return;

}

long m;

bool blag;

do

{

blag=0;

cout<<"Please enter the withdrawal amount";

cin>>m;

if(m>=balance)

{

blag=1;

cout<<"The amount you entered is greater than the balance and can not be removed! please enter again"<<endl;

}

}

while(blag);

balance=balance-m;

}

void users::saving()

{

long m;

bool blag;

do

{

blag=0;

cout<<"Please enter the deposit amount";

cin>>m;

if(m<0)

{

cout<<"Please enter the amount correctly";

cin>>m; blag=1;

}

}

while(blag);

balance=balance+m;

}

void users::saving(long money)

{

balance=balance+money;

}

long users::virement()

{

long money;

bool blag;

do

{

blag=0;

cout<<"Please enter the amount to be transferred";

cin>>money;

if(money>=balance)

{

cout<<"Insufficient balance! please enter again"<<endl;

blag=1;

}

}

while(blag);

balance=balance-money;

return money;

}

void users::out_to_file(ofstream &file_out)

{

file_out<<id<<" "<<password<<" "<<name<<" "<<id_card<<" "<<company<<" "<<phone<<" "<<address<<" "<<balance;

}

void users::out_to_screen()

{

cout.setf(ios::left);

cout<<setw(6)<<"Account"<<id

<<setw(9)<<" Username"<<name

<<setw(10)<<" ID"<<id_card

<<setw(13)<<" Company"<<company

<<setw(12)<<" Phone number"<<phone

<<setw(13)<<" Address"<<address

<<setw(9)<<" Balance"<<balance

<<endl;

cout.setf(ios::right);

}

void users::put_next(users *n)

{

next=n;

}

users *users::back_next()

{

return next;

}

//Query: select the query conditions: 1 - account name; 2 - account; 3 - ID number

users *u_search(users *head,int choice,bool b=1)

{

users *p;

bool blag=1;

switch(choice)

{

   case 0:

break;

  

case 1:

char name[9];

cout<<"Enter the account name";

cin>>name;

for(p=head;p!=NULL;p=p->back_next())

{

if(strcmp(p->get_name(),name)==0)

{

p->out_to_screen();

blag=0;

}

}

break;

  

case 2:

char id[5],password[6];

cout<<"Please enter the username";

cin>>id;

cout<<"Please enter the password";

cin>>password;

for(p=head;p!=NULL;p=p->back_next())

{

if(strcmp(p->get_id(),id)==0&&strcmp(p->get_password(),password)==0)

{

if(b)//******************????

{

p->out_to_screen();

blag=0;

}

else return p;

}

}

break;

  

case 3:

char id_card[19];

cout<<"Please enter your ID";

cin>>id_card;

for(p=head;p!=NULL;p=p->back_next())

{

if(strcmp(p->get_id_card(),id_card)==0)

{

p->out_to_screen();

blag=0;

}

}

break;

default:

cout<<"Option error"<<endl;

return NULL;

}

if(blag)

{

cout<<"There is no account"<<endl;

return NULL;

}

}

int n_id(users *head)

{

int id;

int now_id=0,num;

users *p;

char ne_id[5];

bool blag;

for(id=0;id<=9999;id++)

{

blag=1;

now_id=id;

int2str(now_id,ne_id); //Numeric conversion to a string

for(int i=3;i>=0;i--) //Numeric conversion to a string

{

num=now_id%10;

ne_id[i]=num+'0';

now_id/=10;

}

ne_id[4]='';

for(p=head;p!=NULL;p=p->back_next())

{

if(strcmp(p->get_id(),ne_id)==0)

{

blag=0;

break;

}

}

if(blag)

return id;

}

}

void zi_title()

{

cout<<"________________________________"<<endl<<endl;

cout<<" 1-Open an account 2-Sales 3-Deposit 4-Withdrawals 5-Transfer 6-Inquire 0-Quit"<<endl<<endl;

cout<<"________________________________"<<endl;

}

int main()

{

ifstream f_in;

ofstream f_out;

f_in.open("banksystem.txt");

safe_conduct();

users *p;

users *head, //The head of the entire list of head nodes

*user, //Create a new account pointer

*later, //The end of the entire list of pointers

*next; //The next node

if(f_in.peek()!=EOF)

{

head=new users(f_in);

user=later=head;

for(;f_in.peek()!=EOF;)

{

next=new users(f_in);

user->put_next(next);

later=next;

}

}

else

head=NULL;

f_in.close();

int choice;

do

{

zi_title();

cin>>choice;

bool blag=0;

switch(choice)

{

case 1:

cout<<"---Open an account--- ";

user=new users;

user->put_id(n_id(head));

user->new_user();

if(head==NULL)

head=user;

else

later->put_next(user);

later=user;

break;

  

case 2:

cout<<"---Sales--- ";

if(head==0)

{

cout<<"No account yet! It is recommended to open an account"<<endl;

break;

}

char id_[5],password_[6];

cout<<"Please enter the account number to be sold";

cin>>id_; //Delete the nodes in the linked list

cout<<"Please enter the password";

cin>>password_;

next=head;

if(strcmp(head->get_id(),id_)==0&&strcmp(head->get_password(),password_)==0)

{

head=head->back_next();

delete next;

blag=1;

}

else

{

for(user=head;user!=NULL;user=user->back_next())

{

if(strcmp(user->get_id(),id_)==0&&strcmp(head->get_password(),password_)==0)

{

next->put_next(user->back_next());

blag=1;

delete user;

break;

}

next=user;

}

}

if(blag)

cout<<"successfully deleted"<<endl;

else

cout<<"There is no account"<<endl;

break;

  

case 3:

cout<<"---Deposit--- ";

user=u_search(head,2,0);

user->saving();

user->out_to_screen();

break;

  

case 4:

cout<<"---Withdrawals--- ";

user=u_search(head,2,0);

user->take_money();

user->out_to_screen();

break;

  

case 5:

cout<<"---Transfer--- ";

cout<<"Tansfer out "<<"******";

user=u_search(head,2,0);

cout<<"Tansfer in "<<"******";

next=u_search(head,2,0);

next->saving(user->virement());

user->out_to_screen();

next->out_to_screen();

break;

  

case 6:

cout<<"---Inquire--- ";

cout<<"Select the query criteria 1-Account name 2-Username 3-ID";

int choi;

cin>>choi;

u_search(head,choi);

break;

  

case 0:

f_out.open("banksystem.txt");

if(f_out.fail())

{

cout<<"File open error"<<endl;

exit(1);

}

for(user=head;user!=NULL;user=user->back_next())

{

user->out_to_file(f_out);

}

f_out.close();

break;

default:

cout<<"There is no option"<<endl;

break;

}

}

while(choice);

cout<<"Thank you for using"<<endl;

return 0;

}

Explanation / Answer

#include #include class account { char cust_name[20]; int acc_no; char acc_type[20]; public: void get_accinfo() { coutcust_name; coutacc_no; coutacc_type; } void display_accinfo() { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote