Detailed analysis of the ATM simulation program compiled by C

Source: Internet
Author: User

//************************************

//**

// * Function. H *

//**

//************************************

# Include <iostream. h>

Class consumer;

Class ATM

// ATM

{

Public:

ATM (Consumer & CN): CNSM (CN)

{

}

Void welcome ();

// Login interface

Bool check_passwd (char N [], char PWD []);

// Check the password

Void change_passwd ();

// Change the password

Void fetchmoney ();

// Withdraw money

Void information ();

// Query information

Void exitatm ();

// Exit the system

Void functionshow ();

// Functional interface

Void lock ();

// Lock the machine

PRIVATE:

Int times;

// Record Password Input times

Consumer & CNSM;

};

Class consumer

// User

{

Public:

Friend class ATM;

Consumer (char name [], char num [],

Float money, char password []);

Protected:

Char * get_name ();

// Get the name

Char * get_num ();

// Get the card number

Char * get_passwd ();

// Obtain the password

Float get_money ();

// Obtain the balance

Void set_passwd (char PWD []);

// Set the password

Void set_money (float m );

// Get the money

PRIVATE:

Char passwd [8];

// User Password

Char name [20];

// User Name

Char num [20];

Float money;

};
//************************************

//**

// * Consumer class member functions *

//**

//************************************

# Include "function. H"

# Include <string. h>

Consumer: Consumer (char name [],

Char num [], float money, char password [])

{

Strcpy (name, name );

Strcpy (Num, num );

Money = money;

Strcpy (passwd, password );

}

Float consumer: get_money ()

{

Return money;

}

Char * Consumer: get_name ()

{

Return name;

}

Char * Consumer: get_num ()

{

Return num;

}

Char * Consumer: get_passwd ()

{

Return passwd;

}

Void consumer: set_money (float m)

{

Money-= m;

}

Void consumer: set_passwd (char PWD [])

{

Strcpy (passwd, PWD );

}

//************************************

//**

// * Member functions of the ATM class *

//**

//************************************

# Include "function. H"

# Include <string. h>

# Include <stdlib. h>

Void ATM: Welcome ()

{

Times = 0;

Cout <"$

Thank you !~!

"<Endl;

Char PWD [8], num [20], ch;

Int I = 0;

Do

{

I = 0;

Cout <Endl <"Enter the card number :";

Do

{

Cin. Get (CH );

Num [I] = CH;

} While (Ch! = '/N ');

Num[ I-1] = '/0 ';

I = 0;

Cout <"enter the password :";

Do

{

Cin. Get (CH );

PWD [I] = CH;

} While (Ch! = '/N ');

PWD [I-1] = '/0 ';

If (! Check_passwd (Num, PWD ))

{

Cout <"the card number or password you entered is incorrect,

Enter "<Endl;

Times;

}

Else

{

Functionshow ();

}

} While (Times <3 );

Lock ();

}

Bool ATM: check_passwd (char num [],

Char PWD [])

{

If (strcmp (Num, CNSM. get_num () = 0 & strcmp

(PWD, CNSM. get_passwd () = 0)

Return true;

Else

Return false;

}

Void ATM: functionshow ()

{

Int N;

Do

{

Cout <Endl <"Enter the corresponding operation serial number for the operation:

"<Endl;

Cout <"1) Change Password" <Endl

<"2) Withdrawal" <Endl

<"3) Querying balances" <Endl

<"4) withdraw from the system" <Endl;

Cout <"$> //";

Cin> N;

While (n <1 | n> 4)

{

Cout <"enter the correct operation number! "<Endl;

Cout <"$> //";

Cin> N;

}

Switch (N)

{

Case 1: change_passwd ();

Break;

Case 2: fetchmoney ();

Break;

Case 3: Information ();

Break;

Case 4: exitatm ();

Break;

}

} While (true );

}

Void ATM: change_passwd ()

{

Char PWD [8], repwd [8];

Times = 0;

Do

{

Cout <Endl <"Enter the old password :";

Cin> pwd;

If (! Check_passwd (CNSM. get_num (), PWD ))

Times;

Else

Break;

} While (Times <3 );

If (Times = 3)

Lock ();

Int T = 0;

Do

{

Cout <"Enter the new password :";

Cin> pwd;

Cout <"Enter the new password again :";

Cin> repwd;

If (t = strcmp (PWD, repwd ))! = 0)

Cout <"the two passwords you entered are different,

Enter again! "<Endl;

} While (T! = 0 );

CNSM. set_passwd (PWD );

Cout <"the password is successfully modified. Please remember! "<Endl;

}

Void ATM: fetchmoney ()

{

Float m;

Char ch;

Do

{

Cout <Endl <"How much do you need :"

<"/N ___ fckpd ___ 2gt; //" <Endl;

Cin> m;

While (M <= 0)

{

Cout <"enter the correct number! "<Endl;

Cout <"$> //";

Cin> m;

}

If (CNSM. get_money ()-M <0)

{

Cout <"sorry, your balance is insufficient! "

<Endl;

}

Else

{

Cout <Endl <"operation successful. Please collect the money! "

<Endl;

CNSM. set_money (m );

}

Cout <"whether to continue this operation: (y/n )"

<Endl;

Cout <"$> //";

Cin> CH;

While (Ch! = 'N' & Ch! = 'N' & Ch! = 'Y' & Ch! = 'Y ')

{

Cout <"$> //";

Cin> CH;

}

} While (CH = 'y' | CH = 'y ');

}

Void ATM: Information ()

{

Cout <"*********************************" <<Endl;

Cout <"*" <Endl;

Cout <"* User name:" <CNSM. get_name () <Endl;

Cout <"* card number:" <CNSM. get_num () <Endl;

Cout <"* Balance:" <CNSM. get_money () <Endl;

Cout <"*********************************" <<Endl;

}

Void ATM: Lock ()

{

Cout <Endl <"sorry, your operation is incorrect,

Your card has been confiscated! "<Endl;

Exit (1 );

}

Void ATM: exitatm ()

{

Cout <Endl <"thank you for your support for this bank,

Welcome to the next visit! "<Endl;

Cout <"get the card ...... "<Endl;

Exit (0 );

}
//************************************

//**

// * ATM. cpp *

//**

//************************************

# Include <iostream. h>

# Include "function. H"

Void main ()

{

Consumer C1 ("Jim", "12345", 5200.3f, "123 ");

// Construct a user first

ATM (C1 );

ATM. Welcome ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.