21xrx.com
2024-11-25 06:01:21 Monday
登录
文章检索 我的文章 写文章
C++编写ATM机存取款系统源代码
2023-07-06 11:19:19 深夜i     --     --
C++ ATM机 存取款系统 源代码 编写

ATM机存取款系统是现代银行系统中不可或缺的一部分。C++作为一种高效的面向对象编程语言,被广泛应用于ATM机存取款系统的开发之中。以下是一份简单的ATM机存取款系统的 C++源代码,旨在帮助初学者们更好地理解和实践C++编程的基本概念和技能。


#include<iostream>

#include<conio.h>

using namespace std;

class bank_account

{

  private:

  int acc_num;

  string name;

  int balance;

  public:

  void assign(int account_number,string acc_name,int acc_balance)

  

    acc_num=account_number;

    name=acc_name;

    balance=acc_balance;

  

  int avail_balance()

  

    return balance;

  

  void deposit(int amount)

  {

    balance+=amount;

  }

  void withdraw(int amount)

  

    balance-=amount;

  

};

int main()

{

  bank_account user;

  int choice;

  int amount;

  int account_number;

  string account_name;

  int account_balance;

  while(true) //This makes the program continuous till the choice is exited from the menu.

  {

    cout<<"\n\n ATm MACHINE";

    cout<<"\n1.Create Account";

    cout<<"\n2.Availability Balance";

    cout<<"\n3.Deposit Money";

    cout<<"\n4.Withdraw Money";

    cout<<"\n5.Exit";

    cout<<"\n\n Enter Your Choice: ";

    cin>>choice;

    switch(choice)

    {

      case 1:

      {

        cout<<"\n Enter Account Number: ";

        cin>>account_number;

        cout<<"\n Enter Account Holder's Name: ";

        cin>>account_name;

        cout<<"\n Enter Account Balance: ";

        cin>>account_balance;

        user.assign(account_number,account_name,account_balance);

        cout<<"\n Congrats! Your Account has been created!!";

        break;

      }

      case 2:

      {

        cout<<"\n Your Available Balance is: "<<user.avail_balance();

        break;

      }

      case 3:

      {

        cout<<"\n Enter the Deposit Amount: ";

        cin>>amount;

        user.deposit(amount);

        cout<<"\n The Amount Has Been Deposited Successfully!!";

        break;

      }

      case 4:

      {

        cout<<"\n Enter the Amount You'd Like to Withdraw: ";

        cin>>amount;

        if(amount>user.avail_balance()){

          cout<<"\n Cannot Withdraw the Amount!\n Balance is Insufficient.";

        }else{

          user.withdraw(amount);

          cout<<"\n The Amount Has Been Withdrawn Successfully!!";

        }

        break;

      }

      case 5:

      {

        cout<<"\n Quitting the System....";

        exit(0);

      }

      default:

      {

        cout<<"\n Invalid Choice: Please Try Again!!\n\n";

      }

    }

    getch(); //This waits for the next input from the user.

  }

  return 0;

}

此代码涵盖了ATM机存取款系统的主要功能,例如创建帐户,提供余额,存款和提款。使用这种简单的代码,初学者可以在C++中编写自己的ATM机存取款系统,以增强自己的编程技能。

尽管这份源代码看起来不是很复杂,但是这应该是一个很好的起点,尤其是对于刚刚开始学习C++的初学者。通过研究此代码,他们可以更好地了解面向对象编程的概念,例如类、对象和访问权限。通过在这份源代码的基础上不断深入,他们可以编写更加复杂的ATM机存取款系统,同时也能够更好地理解C++编程语言的精髓。

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复