Could somebody please help me in this C++ program? I'm a beginner and have no idea doing this tutorial. anyone who could help me would be greatly appreciated. here is the question:

Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit money into their accounts and withdraw money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction.

Create an inheritance hierarchy containing base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include data members like name, gender (male/female), phone number, address and account_balance. The class should 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.0. If not, the balance should be set to 0.0, and the constructor should display an error message, indicating that the initial balance was invalid.

The class should provide three functions. The function Credit() should add an amount to the current balance. The function Debit() should withdraw amount from the account balance and ensure that he debit amount does not exceed the account balance. If it does, the balance should be left unchanged and the function should print the message “Debit amount exceeds account balance”. Function getBalance() should return the current balance.

Derived class SavingsAccount should inherit the functionality of the calss Account, but also include a data member interest-rate of type double indicating the interest rate (percentage). SavingsAccount’s constructor should receive the initial balance, as well as an initial interest_rate for the SavingsAccount. SavingsAccount should provide public method Calculate-Interest() that returns a double value indicating the amount of interest earned by an account. The function CalculateInterest() should determine this amount by multiplying the amount by the interest rate. [Note: the SavingsAccount should inherit the public functions Credit and Debit without redefining them.]

Derived class CheckingAccount should inherit the functionality of the class Account, but also include a data member fee-charged of type double indicating the fee charged per transaction (let’s say RM 0.50 per transaction). CheckingAccount’ s constructor should retrieve the initial balance, as well as a parameter indicating a fee amount. CheckingAccount should provide a public function IsFeeChareged() that returns a Boolean value indicating weather the fee amount is charged or not. If the transaction is successful then only fee must be charged. If the transaction is cancelled then the fee must not be charged. [Note: the CheckingAccount should inherit the public functions Credit and Debit as is without redefining them].

After defining the classes in this hierarchy, write a program that creates objects of each class and tests their functions. Add interest to the SavingsAccount object by first invoking its CalculateInteres() function, then passing the returned interest amount to the object’s Credit function.

THANKS

Whenever you have a "big" assignment like that, its really good to break it down. Here is the first thing your should do :
<quote> Create an inheritance hierarchy containing base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account</quote?

Draw this out on paper. Let a box with a name represent a class.

So a class Account is a abstract base class. Then After you created that,
(don't worry about the method function) then create a Checking and savings account, that inherits from the abstract class, Account.

After you got this done, post, it and we will take it step by step.

Thanks dear. The following is what I have done so far. could you please tell the next part that I have to do and correct the one here. Thanks

//ACCOUNT.h 
#ifndef Account_H
#define Account_H
double credit, debit, balance;

class Account
{
private :
    string name, phone_number, address;
    char gender;

public:
    void setName(string);
    void setGender(char);
    void setphone_number(string);
    void setAddress(string);
    void setCredit(double);
    void setDebit(double);
    void setBalance(double);

    string getName();
    string setphone_number();
    string setAddress();
    char getGender();

    double getCredit();
    double getDebit();
    double getBalance();


};
#endif

SAVINGSACCOUNT.h

#include"Account.h"
class SavingsAcount:public Account

{
private:
    double interest_rate;
public:
     set Interest_rate(double);
     double getInterest_rate();
};

CHECKINGACCOUNT.h

#include"Account.h"
class ChechingAcount:public Account

{
private:
    double Fee_charged;
public:
     set fee_charged(double);
     double getFee_charged();
};

END

Remove the global variable and use code tags :

//ACCOUNT.h 
#ifndef Account_H
#define Account_H
double credit, debit, balance;

class Account
{
private :
string name, phone_number, address;
char gender;

public:
void setName(string);
void setGender(char);
void setphone_number(string);
void setAddress(string);
void setCredit(double);
void setDebit(double);
void setBalance(double);

string getName();
string setphone_number();
string setAddress();
char getGender();

double getCredit();
double getDebit();
double getBalance();


};
#endif
....................................................

//SAVINGSACCOUNT.h

#include"Account.h"
class SavingsAcount:public Account

{
private:
double interest_rate;
public:
set Interest_rate(double);
double getInterest_rate();
};

----------------------------------------------------

//CHECKINGACCOUNT.h

#include"Account.h"
class ChechingAcount:public Account

{
private:
double Fee_charged;
public:
set fee_charged(double);
double getFee_charged();
};

Now you need to do this :

The class should provide a constructor that receives an initial balance and uses it to initialize the data member.

This is towards your Account class.

Thanks firstPerson! here is what I have done so far! I don't understand the constructor???? could you please contribute some ideas with coding???

//BankingSystem.cpp

//-------------------------------

#include<iostream>
#include<string>
#include<windows.h>
using namespace std;
#include"SavingsAccount.h"
#include"CheckingAccount.h"

int main()
{
	
	return 0;
}

//---------------------------------

//Accounts.h

//---------------------------------

#ifndef Account_H
#define Account_H
double credit, debit, balance;

class Account
{
private :
	string name, phone_number, address;
	char gender;
	
public:
	void setName(string);
	void setGender(char);
	void setphone_number(string);
	void setAddress(string);
	void setCredit(double);
	void setDebit(double);
	void setBalance(double);

	string getName();
	string setphone_number();
	string setAddress();
	char getGender();

	double getCredit();
	double getDebit();
	double getBalance();

	
};
#endif


//SavingsAccount.h

//----------------------------------

#include"Account.h"
class SavingsAcount:public Account

{
private:
	double interest_rate;
public:
	 setInterest_rate(double);
	 double getInterest_rate();
};


//CheckingAcount.h

//-----------------------------------

#include"Account.h"
class ChechingAcount:public Account

{
private:
	double Fee_charged;
public:
	 setfee_charged(double);
	 double getFee_charged();
};

Thanks once again.....please help to complete this.

Well first thing is, you don't have any constructors declared anywhere, a constructor is the 'function' that happens when you instantiate an instance of a class. So basically what you would need to add into your header file would be:

class Account
{
private: //what you had here before //

public:
     Account();//default constructor
     Account(int initialBalance){dataMember = initalBalance;};//constructor with parameter
//what you had here before//

};

And what not. Theres a default constructor which takes no arguments, and in your case you would want a constructor that takes an argument which sets the private data member (dataMember) to the parameter (initialBalance)

Just adjust these values to whatever your variables are.

I'd also recommend putting your function defintions for your class in a separate .cpp file. But that's just me.

EDIT: You don't necessarily need to put the default constructor in there if you're not going to use it, but it is usually good practice.

First things first. Even if your code doesn't explicitly need it you should (almost) always have a default constructor in addition to any non-default constructors in your class. If you don't know what the declaration of a constructor looks looks like I suggest looking at your notes or class reference. Once you can write a default constructor a nondefault constructor is an easy next step.

Hi.. I have a homework to submit it tomorrow for this question?? So could you please update correct solution for this problem.. It would be really great... Hope you could update it as soon as possible.. Thanks... Bye..

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.