OOP class checking account

Hey I'm stuck on this next part of this program. I am to create 3 methods; one to deposit into account, one to withdraw from account, and one more to print updated values.

I searched around for similar problems but I still can't wrap my head around this. I was toying with it and put it under a void BankAccount::deposit() and void BankAccount::withdraw(). Both of these in BankAccount.cpp and of course under public in the header file. Or does it belong in private?

Anyway, here's my code so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 //File:   Bank.cpp
  
#include <string>
#include "BankAccount.h"
using namespace std;
int main() {

	BankAccount first;
	first.setName("John Smith");
	first.setAccNumb(123456);
	first.setBalance(205.35);
	first.printValues();
	cout << endl;
	BankAccount second;
	second.setName("Jane Doe");
	second.setAccNumb(654321);
	second.setBalance(526.85);
	second.printValues();

	return 0;

}


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
//File:   BankAccount.cpp

#include <vector>
#include <string>
#include <iostream>
#include "BankAccount.h"
using namespace std;
BankAccount::BankAccount(){

		name = "";
		acc = 0;
		bal = 0.0;
}
BankAccount::BankAccount(string n, int a, double b){
    name = n;
    acc = a;
    bal = b;
}
string BankAccount::getName(){
    return name;
}
void BankAccount::setName(string n){
    name = n;
}
int BankAccount::getAccNumb(){
    return acc;
}
void BankAccount::setAccNumb(int a){
    acc = a;
}
double BankAccount::getBalance(){
    return bal;
}
void BankAccount::setBalance(double b){
    bal = b;
}
void BankAccount::printValues(){
    cout << "Account holder is: " << getName() << endl;
    cout << "Account number is: " << getAccNumb() << endl;
    cout << "Account balance is: " << getBalance() << endl;
}


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
//File:   BankAccount.h

#ifndef BANKACCOUNT_H_
#define BANKACCOUNT_H_
#include <string>
#include <iostream>
using namespace std;
class BankAccount {
private:
            string name;
            int acc;
            double bal;

public:
            BankAccount();
            BankAccount(string n, int a, double b);
            string getName();
            void setName(string name);
            int getAccNumb();
            void setAccNumb(int acc);
            double getBalance();
            void setBalance(double bal);
            void printValues();

};

#endif /* BANKACCOUNT_H_ */ 
closed account (9j2Cko23)
BankAccount::deposit()
BankAccount::withdraw()

Where are these functions in your code?
Solved.
Last edited on
Solved!!
Last edited on
Topic archived. No new replies allowed.