使用类的C ++小银行程序

时间:2015-12-12 20:41:21

标签: c++

我想用C ++创建一个存储客户信息(可能是文本文件或某种类型)的银行程序,如:

name
account type
account number
account balance
deposit and withdraw functions
edit account
delete account
show all account.
Class bankAccounts
{
   private:
string customerName
char accType
int accountNo
double accBalance
   public:
bankAccounts()
~bankAccounts()
displayAccount()
depositAccount()
withdrawAccount()
deleteAccount()
showAccounts()

我将如何使用构造函数?也许将余额和accountnum设置为0.我怎么能这样做,以及我将如何实现其他功能?

1 个答案:

答案 0 :(得分:0)

这是怎么回事。创建一个Parameterized Constructor并将要分配给对象的值作为参数传递。

#include <iostream>
#include <string>

class bankAccounts
{
private:
    std::string customerName;
    char accType;
    int accountNo;
    double accBalance;

public:
    bankAccounts();

    bankAccounts(std::string cn ,char act, int acno, double accB) //Parameterized constructor
    {
        customerName =cn;
        accType=act;
        accountNo=acno;
        accBalance=accB;
    }

    //Implement your functions inside/ outside the class

    // displayAccount();
    // depositAccount();
    // withdrawAccount();
    // deleteAccount();
    // showAccounts();

};


int main()
{
    std::string customerName;
    char accType;
    int accountNo;
    double accBalance;
    std::cin>>customerName>>accType>>accountNo>>accBalance;//get your data
    bankAccounts B(customerName, accType, accountNo, accBalance);
    //object B has all attributes you wanted

    //Enjoy :)

    return 0;
}