HELP MODIFYING BANKING PROGRAM

Would someone please point me in the right direction on this assignment? I need to help getting started with this banking program that has both deposit method and a withdraw method.after creating the account, the user is prompted to deposit or withdraw an amount of money.the modified account balance needs to be stored into the data file. Any help is greatly appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  #include <iostream>
#include <string>
#include <fstream>
#include "dataStore.hpp"
#include "account.hpp"

using namespace std;

int main()
{
    char more = 'y';
    string accountHolderName= "                          ";
    dataStore *accountStorage;
    account *newAccount;
    string decision="" ;
  
    
    // Create a data storage file object.
    accountStorage = new dataStore();
    
    // Loop on user continuing
    while(more == 'y')
    {
        // ask for account owner's name
        cout << "What is the account holder's name: ";
        cin >> accountHolderName;
        
        //Ask user if they want to deposit or withdraw money
        cout << "Would you like to deposit or withdraw money?";
        cin>> decision;
        
    
        
        // Create an account object
        newAccount = new account(accountHolderName);
        
        
        
        // store the account on the data storage file
        accountStorage->save(newAccount);
        
        // Ask user if any more accounts
        cout << "Any more accounts to create? ";
        cin >> more;
    }
    
    return 0;
}}
#include "account.hpp"
#include <string>

using namespace std;

account::account(string owner)
{
    accountOwnerName = owner;
    balance = 0.00;
}

account::~account(void)
{
    
}

double account::getBalance(void)
{
    return balance;
}

string account::getOwnerName(void)
{
    return accountOwnerName;
}

//The method to deposit
if (decision(void) = "deposit")
{
                     // ask the user how much would they like to deposit
                     // add the deposit amount to the current balance
}


//The method to withdraw
if (decision(void)= "withdraw")
{
                  //ask the user how much they would like to withdraw
                  // subtract the withdraw amount from the current balance
                  //(if statment) --> if the withdraw is more than the current balance you send the user a message that they do not have enough
}
#ifndef accountheaderforaccountclass
#define accountheaderforaccountclass

#include <string>

using namespace std;

class account
{
public:
    account(string);
    ~account(void);
    double getBalance(void);
    string getOwnerName(void);
   // string decision= "" (void);
    double withdraw;
    double deposit;
    
private:
    string accountOwnerName;
    double balance;
};

#endif

#include "dataStore.hpp"
#include <string>

using namespace std;

dataStore::dataStore(void)
{
    store.open("BankAccountData.txt", ios::app);
}

dataStore::~dataStore(void)
{
    store.close();
}

void dataStore::save(account *newAcct)
{
    store << newAcct->getOwnerName() << newAcct->getBalance() << endl;
}

#include "dataStore.hpp"
#include <string>

using namespace std;

dataStore::dataStore(void)
{
    store.open("BankAccountData.txt", ios::app);
}

dataStore::~dataStore(void)
{
    store.close();
}

void dataStore::save(account *newAcct)
{
    store << newAcct->getOwnerName() << newAcct->getBalance() << endl;
}
Last edited on
Hi, fresh716.
How many people have you sent private messages to?

This could be a starting point:
Account.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef ACCOUNTHEADERFORACCOUNTCLASS
#define ACCOUNTHEADERFORACCOUNTCLASS


#include <string>

class Account {
public:
    Account(std::string);
    double getBalance() const;
    std::string getOwnerName() const;
    void deposit(double amount = 0.0);
    void withdraw(double amount = 0.0);

private:
    std::string owner_name;
    double balance;
};


#endif // ACCOUNTHEADERFORACCOUNTCLASS 


Account.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "Account.hpp"
#include <iostream>


Account::Account(std::string owner)
    : owner_name { owner },
      balance    { 0.0 }
{
}


double Account::getBalance() const
{
    return balance;
}


std::string Account::getOwnerName() const
{
    return owner_name;
}


void Account::deposit(double amount)
{
    // if amount == 0.0, prompt the user about how much money
    // increase balance by the proper amount
}


void Account::withdraw(double amount)
{
    // check if there's money on the account?
    // if amount == 0.0, prompt the user about how much money
    // decrease balance by the proper amount
}


DataStore.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef DATASTORE_H
#define DATASTORE_H


#include "Account.hpp"
#include <fstream>
#include <string>

class DataStore {
public:
    DataStore(std::string fname = "BankAccountData.txt");
    ~DataStore();
    void save(const Account & account);
private:
    std::string store_name;
    std::ofstream store;
};


#endif // DATASTORE_H 


DataStore.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "DataStore.hpp"

#include <string>

DataStore::DataStore(std::string fname)
    : store_name { fname }
{
    store.open(fname, std::ios::app);
}


DataStore::~DataStore()
{
    store.close();
}


void DataStore::save(const Account & account)
{
    store << account.getOwnerName() << ": " << account.getBalance() << '\n';
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Would someone please point me in the right direction on this assignment?
// I need to help getting started with this banking program that has both
// deposit method and a withdraw method.
// after creating the account, the user is prompted to deposit or withdraw an
// amount of money.
// the modified account balance needs to be stored into the data file.
// Any help is greatly appreciated 
#include "Account.hpp"
#include "DataStore.hpp"
#include <iostream>
#include <string>

int main()
{
    char more { 'y' };
    while(more == 'y')
    {
        std::cout << "What is the account holder's name: ";
        std::string accountHolderName;
        std::cin >> accountHolderName;

        // Create an account object
        Account account(accountHolderName);

        std::cout << "Your balance is now " << account.getBalance() << '\n';
        //Ask user if they want to deposit or withdraw money
        char decision {};
        do {
            std::cout << "Would you like to (D)eposit or (W)ithdraw money (D/W)? ";
            std::cin >> decision;
        } while(decision != 'D' && decision != 'W');
        
        if(decision == 'D') {
            // call the proper Account method

        // Create a data storage file object.
        DataStore account_storage;

        // store the account on the data storage file
        account_storage.save(account);

        // Ask user if any more accounts
        std::cout << "Any more accounts to create? ";
        std::cin >> more;
    }

    return 0;
}


Please consider ‘forum’ is a Latin word which used to mean just ‘square’, i.e. a place where people could freely meet and talk. When you post on a free forum, you can get a good answer, a bad answer or no answer at all. It happens. Is up to you to make your question interesting.
Topic archived. No new replies allowed.