1. Create a class called Record that financial institute might use to represent their customer's record. This class should include one data member of type int to represent the account balance.
    Provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, the balance should be set to 0 and the constructor should display an error message indicating that INVALID BALANCE.
    The class should provide three member functions.
    -Member function add, should add an amount to the balance.
    -Member function deduct, should deduct money from the account and ensure that the deduction amount does not exceed the account's balance. If it does, the balance should be left unchanged and the function should print a message indicating "Deduct amount exceeded".
    -Member function getBalance should return the current balance.

Write a main program that creates one Record object and tests the member funtions of class Record.

Recommended Answers

All 2 Replies

I think this should be correct for Header file, but for the rest i am not sure:

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

class Record
{
private: // data members of Record class
    int balance; 
public:
    Record(); //default constructor
    Record (int b); // overloaded constructor
    void addBalance(int); 
    void deductBalance(int); 
    void getBalance(); 
    string addBalance();
    string deductBalance();
    string toString

};

Your header and your function declarations are fine except the last one string toString what do you need this one for?

now just write function definations.

for the constructor

Record::Record (int b){

    if(b < 0)
        balance = 0;
    else
        balance = b;
}

for the void addBalance(int) you have to use void addBalance(unsined int) for adding balance
and use void addBalance(int) for catching the user if he/she entered a negative balance.

Record::addBalance(unsined int newBalance){
    balance += newBalance;
}

Record::addBalance(int newBalance){
    cout<<"The balance should be unsigned"<<endl;
    //use exception handling here
}

And finish the rest by yourself.

Sorry for any mistake if had done i'm still a newbie.

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.