This what I have from my last assignment on creating a bank account. This is what i have to add for the next assignment and I'm lost. Can someone please help me do this!!

Assignment:
1. Create 3 subclasses that inherit from the bank account class created in homework 3. They are Checking, Savings, and CD.

For Checking:
Override the debit method, there is now a per check fee. When we debit money charge a processing fee each time. Account type is “CH”.

For Savings:
Add a private static member for interest rate. Add a method that will calculate the monthly interest and add it to the balance. Also implement a minimum balance check. This should run the same time as the monthly interest, if the account has less than $250, then there is a $5 maintenance fee that should be deducted from the balance.

For CD:
Add a private static member for the interest rate. Add a member to keep track of the number of debits. This account has a limit of 3 withdrawals per year. After the 3rd withdrawal, there is a 2% transaction fee (min $5) for each withdrawal. Add a method that will rollover the account, which indicates that a year has passed, the CD has reached its term, so we will reset the withdrawal count and apply the annual interest rate.

2. Test the new classes as before, create an array of BankAccount objects, assign the elements of the array to new elements of the different classes that we have. Call all of the methods making use of polymorphic behavior that we have for our debit and credit methods.

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

class BankAccount
{

private:
	static int number; 
    int AcctNumbr;
    string OwnerName;
    string Accounttype;
    double CurrentBalance;
 
public:
	//void BankAccount::withdraw (double amount) 
	BankAccount(void); 
	BankAccount( string , double ) ; 
	void withdraw( double ); 
	double getBalance() const;  

	
};         


int BankAccount::number = 1001;

BankAccount::BankAccount( void )
{

}


BankAccount::BankAccount( string OwnerName, double balance ) // You have an overloaded constructor here but no prototype in class definition
{
    cout << "default constructor."; 
   
	
		
		Accounttype = "GA";
		CurrentBalance = balance;
		this ->OwnerName = OwnerName;


}

void BankAccount::withdraw (double amount) // Good for debit method but where is it in the class definition?
{
    if( amount > 0 && CurrentBalance >= amount )
    {
       CurrentBalance -= amount;
    }
}
 
double BankAccount::getBalance() const  
{
	return CurrentBalance;
}


int main ()
{
	BankAccount bankList[10];
	int nextAcntIndex = 0;
	string name;
	double balance; 
	int Accountnumber;
	int Withdrawl;
 
  cout << " Welcome to World Bank " << endl;
 
	int choice;
 

 

	do { 
  system("cls"); 
   cout << endl;
   cout << " United Bank" << endl;  
   cout << " Select a menu option" << endl;
   cout << " 1. Creating an Account" << endl;
   cout << " 2. Debt" << endl;
   cout << " 3. Current Balance " << endl;
   cout << " 4. credit " << endl;
   cout << " 5.  Exit " << endl;
   cout << endl;
   cout << " Enter your choice by using the numbers -->>  ";
			cin >> choice;
			cin.clear();
			cin.ignore( INT_MAX, '\n' );


			switch( choice ) { 
				case 1: 
				
					system( "cls" );
				cout << "Enter your name: ";
				cin >> name;
				cout << "Enter your balance: ";
				cin >> balance;

				bankList[nextAcntIndex] = BankAccount( name, balance);
				nextAcntIndex++;
									
					break;
				case 2:
					system( "cls" );
					cout << "Enter Account number; ";
					cin >> Accountnumber;
					cout << "Enter Withdrawl; ";
					cin >> Withdrawl;
					bankList [Accountnumber - 10001].withdraw ( Withdrawl );
					
				
					
					break;
				case 3:
					cout << " Enter Account number; ";
					cin >> Accountnumber; 
					cout << "Currentbalance" <<	bankList [Accountnumber - 10001].getBalance ();
					

					break;
				case 4:
					cout << "Enter Account number; ";
					cin >> Accountnumber; 
					cout << "Enter balance; ";
					cin >> balance;
					
					break; 
				case 5:
					
				default:
					cout << "That wasn't a choice";
					break;
			}

		} while( choice !=5 );

		return 0;
}

Well, what have you tried so far?

Im a little confused on where to start. I'm not that good with this programming stuff and just need some help on how to do it.

Do you know how to use inheritance to derive classes? Start by deriving Checking, Savings, and CD classes from BankAccount.

We just learned about that in class. I can see what i can figure out. And I'll try and put something together.

I can't figure it out. I don't know what to do and the assignment is due tuesday and worth a tonnn of points. Can you please help?

I only have one more day till this assignment is due. Is there anyone that can help me finish it???

You've posted no new code. You have no inheritance in the program and presumably still don't, so presumably you don't understand it yet. You can't do it without it. Your last several posts give no clue about what the problem is, so the only advice one can give is "find a tutorial on inheritance and follow it". Type in "c++ inheritance tutorial". There are lots of them. The only other thing we could do here is simply do it for you and post it, which can't/won't/shouldn't happen.

This is how to do inheritance`:

class BankAccount { ... } //base class
class Savings : pubilc BankAccount { ... } //saving derives from base
class Checking : public BankAccount { ... } //checking derives from base
class CD : public BankAccount { ...}

The interface of BankAccount class would be public , so the outside
world would get to use them.

Now you should implement, the needed functions in checkings,
savings and CD class. The needed functions are described in your
notes in the first post.

Continue from this , let me know how it goes.

Thank you very much firstPerson that helps out a lot. I looked up inheritance but didn't know how to quite do it. Thanks for the example. I will work on putting in the numbers tonight and post what I have. Once again thank you.

FirstPerson how would i change this access modifier so subclasses can inherit?

private: // You need to change this access modifier so subclasses can inherit
static int number;
int AcctNumbr;
string OwnerName;
string AccountType;
double CurrentBalance;

use protected instead of private with those variables. i.e change the keyword private to protected.

FirstPerson how would i change this access modifier so subclasses can inherit?

private: // You need to change this access modifier so subclasses can inherit
static int number;
int AcctNumbr;
string OwnerName;
string AccountType;
double CurrentBalance;

http://www.cplusplus.com/doc/tutorial/inheritance/

There are three levels of access: public, protected, private. If "private" doesn't work, try "protected". If neither work, try "public". In your case, "protected" should work. See the chart in the link.

The key line from this link is:

The protected access specifier is similar to private. Its only difference occurs in fact with inheritance. When a class inherits from another one, the members of the derived class can access the protected members inherited from the base class, but not its private members.

So by changing all these to protected it allows them to be inherited throughout the code?

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

class BankAccount
{

protected: // You need to change this access modifier so subclasses can inherit
    static int number; 
    int AcctNumbr;
    string OwnerName;
    string AccountType;
    double CurrentBalance;

public:
    BankAccount( void ); 
    BankAccount( string , double ) ; 
    virtual void withdraw( double );  // Read about virtual in book
    double getBalance() const;  

};   

// Class Definition for Checking
class Checking : public BankAccount
{

private:
    int AcctNumbr;
    string OwnerName;
    string AccountType;
    double CurrentBalance;  // variables

public:
    Checking( void );
    Checking( string, double );
    virtual void withdraw( double );

};

// Class Definition for Savings
class Savings : public BankAccount
{

private:

    int AcctNumbr;  //variables     
    string OwnerName;
    string AccountType;
    double CurrentBalance;




public:
    Savings( void );
    Savings( string, double );
    MonthlyInterest( void );
    MinimumBalanceCheck( void );
    Monthly( void );

}

// Class Definition for CD
class CD : public BankAccount
{

private:

    int AcctNumbr;  //variables     
    string OwnerName;
    string AccountType;
    double CurrentBalance;



public:
    CD( void );
    CD( string, double );
    virtual void withdraw( double );
    AnnualInterest( void );
    Annual( void );
}

For this part of my assignment I have to use the virtual function. I know I already used it in the public access modifiers. Do I need to use it anywhere else?

So by changing all these to protected it allows them to be inherited throughout the code?

Basically yes. It's a matter of access and what classes have access to what methods and variables. That's done by defining methods and variables as "public", "protected", and "private". If you want to make everything as easy as possible, make everything "public". Your teacher will probably get really mad at you if you turn it in that way and it's considered bad programming practice, but you'll have fewer compiler errors. Basically you have a lot to learn in a very short time frame, two of which are the basic idea of inheritance and the more refined idea of public/protected/private.

You need to define a base class, in your case the BankAccount
class, methods (i.e functions) to be a virtual only if you will
define a same named functions in your derived class.

class A { ...  virtual int prnt(){...} };
class B : public A { ... int prnt(){...} };

Notice that prnt is a virtual function because that class is being
used as a base class. And the derived class also define the same
named function.

so if your base class (BankAccount) has a function of the same name as your derived class then make it virtual.

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.