Hello I write down a bank program and I have a problem. I would be happy if you can help me.
So I have two types of accounts each account in a different class. first one is limited account and yhe secound is over draft account also I have class of original bank account.
I get the user name and what type of account it should and after that I need to create the necessary account.
The problem I encounter is to create the required account. I create a standard account and then I have to create the account thet the user wants but I not figure out how to do it.
I would be happy if you could help me understand how to create the additional account thet the user requests.

Bank main-

#include "BankAccount.h"
#include "LimitedBankAccount.h"
#include "OverDraftAccount.h"

using namespace std;

int main()
{
    int choice = 0, accounts = 0;
    string name;
    string account;

    while (choice != 4)
    {
        cout << "Welcome to Bank," << endl;
        cout << "1. to add new account" << endl;
        cout << "4. to exit" << endl;
        cin >> choice;

        BankAccount node(NULL);
        LimitedBankAccount a(NULL);

        if(choice == 1)
        {
            if(accounts > 1000)
            {
                cout << "You have 1000 account try at another time" << endl;
                exit(0);
            }
            else
            {
                cout << "Enter type of account to create: " << endl;
                cin >> account;
                cout << "Enter name for the account: " << endl;
                cin >> name;

                if(account == "limited account")
                {
                    node.NewBankAccount(name);
                    // here need to be create the LimitedBankAccount
                }
                else
                {

                }
            }
        }
    }

    return 0;
}

bank account .h -

#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H

#include <iostream>
#include <stdio.h>
#include <string>

class BankAccount{

public:

    BankAccount(std::string name);

    std::string getNmae();
    double getBalance();

    void NewBankAccount(std::string name);

protected:

bank account cpp-

#include "BankAccount.h"

BankAccount::BankAccount(std::string name)
{
    _name = name;
    _balance = 0;
}

std::string BankAccount::getNmae()
{
    return _name;
}

double BankAccount::getBalance()
{
    return _balance;
}





    std::string _name;
    double _balance;


private:

    BankAccount* _bank;

};


#endif

Limited Account .h -

#ifndef LIMITEDBANKACCOUNT_H
#define LIMITEDBANKACCOUNT_H

#include <iostream>
#include <string>

#include "BankAccount.h"

class LimitedBankAccount : public BankAccount{

public:

    LimitedBankAccount(double limit);
    double getLimit();

    void NewLimitedAccount();

protected:



private:
    double _limit;
    LimitedBankAccount* node;
};


#endif

Limited Account cpp -

#include "LimitedBankAccount.h"

LimitedBankAccount::LimitedBankAccount(double limit) : BankAccount(_name)
{
    _limit = limit;
}

void LimitedBankAccount::setLimit(double num)
{
    _limit = num;
}

double LimitedBankAccount::getLimit()
{
    return _limit;
}

Over Draft Account .h -

#ifndef OVERDRAFTACCOUNT_H
#define OVERDRAFTACCOUNT_H

#include <iostream>
#include <string>

#include "BankAccount.h"

class OverDraftAccount : BankAccount{

public:

    OverDraftAccount(double max);
    double getMax();

protected:


private:

    double _maxOverDraft;
    OverDraftAccount* node;
};


#endif

Over Draft Account .cpp -

#include "OverDraftAccount.h"

OverDraftAccount::OverDraftAccount(double max) : BankAccount(_name)
{
    _maxOverDraft = max;
}

double OverDraftAccount::getMax()
{
    return _maxOverDraft;
}

Thank you to all who help !!!

Your method, BankAccount::NewBankAccount seems to be strangely named and you haven't included the code for it.

I would more normally expect to see this sort of polymorpic behaviour implemented through a base class pointer

BankAccount* acct = NULL;

if (TypeToCreate == Normal)
{
    acct = new BankAccount(name);
}
else if (TypeToCreate == Limited)
{
    acct = new LimitedAccount(name);
}
else if (TypeToCreate == Overdraft)
{
    acct = new OverDraftAccount(name);
}
else
{
    // error type unknown
}

if (acct != NULL)
{
    // use or store account
}

If you need to use functionality specific to the account type (i.e. for Limited or OverDraft account) then either dynamic_cast to the account type required or use the Visitor Pattern to access it.

You sound like you are trying to create a BankAccount and then convert it to a LimitedAccount which is not a good way to set about doing this.

There are too many fundamental errors in your code to begin commenting on it. You have stuff in your .cpp files that should be in the headers. You are using constructors with values that are not visible in their scope. You are initializing class member variables inside constructor bodies when they should be in the constructor initialization block before the body executes. I could go on. Make another attempt and I'll comment as appropriate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.