Problem: The statement ++Chequebook1; should increment the member variable Balance of
Chequebook1 by R100. Give three different implementations for the overloaded operator ++
to accomplish this:
• using the member function Adjust()
• implementing the overloaded operator ++ as a friend function
• implementing the overloaded operator ++ as a member function

ive been struggling with this one for days, i havent came up with a correct solution but heres my code:
please help me :(

#include <iostream>
#include <string>
using namespace std;

  class Chequebook
        Chequebook(float amountBalance);

        void deposit(float amount);
        void withDraw(float amount);
        float currentBalance() const;
        void adjust();

        friend ostream& operator <<(ostream& outs, const Chequebook& amount);
        friend Chequebook operator++(Chequebook& balance);

        float balance;

  int main()
    float amount;
    cout << "Enter the Account balance: ";
    cin >> amount;
    Chequebook Chequebook1(amount);

    cout << "Account balance: R " << Chequebook1.currentBalance() << endl;
    cout << "Enter amount to deposit:";
    cin >> amount;

    cout << "Balance after deposit: R" << Chequebook1.currentBalance() << endl;
    cout << "Enter amount to withdraw:";
    cin >> amount;

    cout << "Balance after withdrawal: R" << Chequebook1 << endl;
    cout << "Balance after adjusting: R" << Chequebook1;
    return 0;

  //default constructor
    balance = 0;

  //overloaded constructor
  Chequebook::Chequebook(float accountBalance)
    balance = accountBalance;

  //deposit member function
  void Chequebook::deposit(float amount)
    balance += amount;

  //withdraw member function
  void Chequebook::withDraw(float amount)
    balance -=amount;

  float Chequebook::currentBalance() const
     return balance;

  void Chequebook::adjust()
     balance += 100;

  //stream insertion operator
  ostream &operator <<(ostream& outs, const Chequebook& amount)
    outs << "Balance: " << amount;
    return outs;

  // function definition
  Chequebook operator++(Chequebook& balance)
     return balance;
5 Years
Discussion Span
Last Post by np complete

Problem #1: you claim you're struggling with this code.
Problem #2: you give no indication what the struggle is
Problem #3: we are not psychic so have no idea what the struggle is
Solution#1: read the post at the top of the forum titled "Read This Before Posting A Question"
Solution#2: post again

Edited by WaltP


After skimming over your code, i think cout << "Balance after withdrawal: R" << Chequebook1 << endl; should be cout << "Balance after withdrawal: R" << Chequebook1.currentBalance() << endl;
Which is in line 50. Same with line 52.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.