This is my first time posting to this site, therefore I would appreciate all criticisms in a constructive manner. I am learning to write Object Oriented programming with C++ and decided to make a trivial simulation of an ATM machine that takes in user input and processes it (i.e makeDeposit, checkBalance, etc.).
My Problem: BankAccount method: makeDeposit end up changing the output of getBalance() to prefix with a zero:
for example: makeDeposit(10) will change getBalance() from 0 -> 010.
//BankAccount.h
#ifndef BANK_ACCOUNT_H
#define BANK_ACCOUNT_H
class BankAccount {
private:
float m_accountBalance;
public:
BankAccount ();
float getBalance();
//This was my second attempt to solve the problem, would it make more sense though
//to pass value rather than reference or is it necessary?
void makeDeposit(BankAccount&, int);
};
#endif
#include "BankAccount.h"
#include <iostream>
using namespace std;
//Constructor
BankAccount::BankAccount () {
m_accountBalance = 0;
}
// Accessor
float BankAccount::getBalance() {
return m_accountBalance;
}
//Mutator
void BankAccount::makeDeposit(BankAccount &bao, int deposit_amount) {
bao.m_accountBalance += deposit_amount; //increment balance based on amount
}
int main () {
BankAccount b1;
cout << b1.getBalance(); //returns 0
b1.makeDeposit (b1,1);
cout << b1.getBalance();//returns 01
BankAccount b2;
b2.makeDeposit(b2, 100);
b2.getBalanace(); //returns 0100
return 0;
}
Any tips would also be much appreciated as I am about to take the roughest Data Structures course with little experience with object oriented programming.
Also, could someone explain to me what subversion is and how it is used.

New Topic/Question
Reply




MultiQuote




|