Can someone please advise me as to why my assignment is not working? I am doing the exact same thing I did on another assignment and for some reason it wont work.

Assignment
1. You are a programmer that works for a local bank. You are creating classes to be used in the class library for this bank for all of its programs. You will also create a main() to test your new classes.

Talking to the bank manager you find out that your bank keeps track of Accounts and that there are more than one type of Account. There are CheckingAccounts, SavingsAccounts, and CreditCardAccounts.

(Credit card accounts are actually called line of credit accounts in the real world. But, let’s call them this here to make it clearer.)

You learn that all of the accounts are often grouped together and treated the same in many reports. So, they all need to inherit from the account class.

Account Class:
Attributes/data members
number (an integer)
balance (a double)
rate (a double)

Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest()
Note: The ApplyInterest() function needs to be a virtual function. It is going to be overridden in the subclasses.

Constructor(s):
This class must have a constructor that accepts all of the data to create an Account and initializes its data members.

Validation in member functions/ Business Rules:
1) Rates should be between .01 and .18 (it is an interest rate as a decimal)
2) Balances should never be allowed to be set to a negative value.


CheckingAccount Class:
This class inherits from the Account class

Attributes/data members
checknumber (an integer) [representing the last check number written/processed.]
pin (an integer)

Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest(), this function should take the balance and multiply it by the rate to find the interest this period…then add it to the existing balance. Print a message to the user with the amount in this format “2.35 has been added to checking”

Constructor(s):
This class must have a constructor that accepts all of the data to create a CheckingAccount and initializes its data members. (This includes all of the data it needs to pass to the Account class constructor or set directly for the account class from this constructor.)

SavingsAccount Class:
This class inherits from the Account class

Attributes/data members

Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest(), this function should take the balance and multiply it by the rate to find the interest this period…then add it to the existing balance. Print a message to the user with the amount in this format “5.01 has been added to savings”


Constructor(s):
This class must have a constructor that accepts all of the data to create a SavingsAccount and initializes its data members. (This includes all of the data it needs to pass to the Account class constructor or set directly for the account class from this constructor.)


CreditCardAccount Class:
This class inherits from the Account class

Attributes/data members
cardnumber (a string)

Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest(), this function should take the balance and multiply it by the rate to find the interest this period…then add it to the existing balance. Print a message to the user with the amount in this format “5.23 interest has been charged to this credit card on its unpaid balance”

Constructor(s):
This class must have a constructor that accepts all of the data to create a CreditCardAccount and initializes its data members. (This includes all of the data it needs to pass to the Account class constructor or set directly for the account class from this constructor.)


Main()

1) In main for this program create a checking account, savings account, and credit card account for a customer with test data as follows and place them in an array:

(type) account # balance rate checknumber pin cardnumber
(checking) 832443 560.10 .02 5854 123
(savings) 832443 1020.58 .04
(credit card) 832443 78.00 .16 1238201293731133

2) Print out all of the data for the accounts for the user.
3) Use a loop and call the ApplyInterest() method to add interest to the balance and print appropriate messages to the user.
4) Print out all of the data for the accounts for the user.

Account Class

#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;

//Account Class
class Account {
private:

        int number;
    	double balance;
   		double rate;
		double interest;
		double NewBalance;

public:
        Account(); // Constructor
        Account(int, double, double) ;
               void setBalance(double);
                void setRate(double);
				void setNumber(int);

				int getNumber();
                double getBalance();
                double getRate();
				void valid_rate(double);
				virtual void ApplyInterest();
				
				void operator +=( double );
        		void operator -=( double );
       			void operator ++ ();
                };      
//-----------------------------------------------------------------------------
//class definition
        Account::Account() {
                number = 0;
                balance = 0;
                rate = 0;
        }

        Account::Account(int number, double balance, double rate) {
                Account::number = number;
                Account::balance = balance;
                valid_rate(rate);
                }

void Account::setNumber(int number) {
    Account::number = number;
}

void Account::setBalance(double balance) {
    Account::balance = balance;
}

void Account::setRate(double rate) {
        valid_rate(rate);
}

int Account::getNumber() {
    return number;
}
double Account::getBalance() {
    return balance;
}
double Account::getRate() {
    return rate;
}

void Account::valid_rate(double rate) {
        if (rate >=.01 && rate <= .18)
                Account::rate=rate;
        else {
                Account::rate=0;
                cout << "WARNING! You have entered an invalid rate!\n";
        }
}

void Account::operator += ( double dValue ) {
        setBalance( getBalance()+ dValue );
                //return this;
    }
void Account::operator -= ( double dValue ) {
        setBalance( getBalance() - dValue );
                //return this;
    }


#endif

Checking Classk

#ifndef CHECKING_H
#define CHECKING_H

#include "Account.h"

//Checking Class
class Checking {
private:
		Checking myChecking[1]; 
        int CheckNumber;
    	int CheckingPin;



public:
        Checking(); // Constructor
        Checking(int, int) ;
               	void setCheckNumber(int);
				void setCheckingPin(int);

				int getCheckNumber();
                int getCheckingPin();

                };      
//-----------------------------------------------------------------------------
//class definition
        Checking::Checking() {
                CheckNumber = 0;
                CheckingPin = 0;
                
        }

        Checking::Checking(int CheckNumber, int CheckingPin) {
                Checking::CheckNumber = CheckNumber;
                Checking::CheckingPin = CheckingPin;
                
                }

void Checking::setCheckNumber(int CheckNumber) {
    Checking::CheckNumber = CheckNumber;
}

void Checking::CheckingPin(int CheckingPin) {
    Checking::CheckingPin = CheckingPin;
}


int Checking::getCheckNumber() {
    return CheckNumber;
}
int Checking::getCheckingPin() {
    return CheckingPin;
}

void Account::ApplyInterest() {
                interest = rate * balance;
                NewBalance = interest + balance;
                cout << interest << " has been added to checking.\n\n";
}

#endif

Credit Class

#ifndef CHECKING_H
#define CHECKING_H

#include "Account.h"
//Checking Class
class Credit {
private:

    Credit myCredit[1];    
	string CardNumber;

public:
        Credit(); // Constructor
        Credit(string) ;
               	void setCardNumber(string);

				string getCardNumber();


                };      
//-----------------------------------------------------------------------------
//class definition
        Credit::Credit() {
                CardNumber = " ";
                                
        }

        Credit::Credit(string CardNumber) {
                Credit::CardNumber = CardNumber;
                                
                }

void Credit::setCardNumber(string CardNumber) {
    Credit::CardNumber = CardNumber;
}


string Credit::getCardNumber() {
    return CardNumber;
}


void Account::ApplyInterest() {
                interest = rate * balance;
                NewBalance = interest + balance;
                cout << interest << " 23 interest has been charged to this credit card on its unpaid balance.\n\n";
}

#endif

Saving Class

#ifndef SAVING_H
#define SAVING_H

//Customer Class
class Saving {
private:
Saving mySaving[1]; 
public:
                };      

void Account::ApplyInterest() {
                interest = rate * balance;
                NewBalance = interest + balance;
                cout << interest << " has been added to checking.\n\n";

}
#endif

Main

#include "Account.h"
#include "Checking.h"
#include "Saving.h"
#include "Credit.h"
using namespace std;

int main() {

	int current_cust=0;
	Checking *myChecking[1];
	Saving *mySaving[1];
	Credit *myCredit[1];

	Checking myRate;
		myChecking[0] = new Checking(832443, 560.10, .02, 5);
		mySaving[0] = new Saving(832243, 1020.58, .04);
		myCredit[0] = new Credit(832443, 78.00, .16, 1238201293731133); 

	cout << "__________________________________________________________\n"<< endl;

	for (int c=0; c<1; c++)
		myChecking[c]->ApplyInterest();

		cout << "__________________________________________________________\n"<< endl;

	for (int s=0; s<1; s++)
		mySaving[s]->ApplyInterest();

		cout << "__________________________________________________________\n"<< endl;

	for (int x=0; x<1; x++)
		myCredit[x]->ApplyInterest();

	cout << "__________________________________________________________\n"<< endl;

        return 0;
}

Recommended Answers

All 6 Replies

Can you clearly and concisely state your problem?

Here are my errors!

1>------ Build started: Project: TestTwo, Configuration: Debug Win32 ------
1> Main.cpp
1>\checking.h(9): error C2148: total size of array must not exceed 0x7fffffff bytes
1>\checking.h(9): error C2079: 'Checking::myChecking' uses undefined class 'Checking'
1>\checking.h(27): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

You need to forward declare the Checking class.

Ok guys I appreciate your help on my stupid mistakes. But on further review of classes I was making dumb mistakes and I changed a lot! I have gotten my compiler down to 3 errors and I am unsure of what they mean, can someone please assist me!

Here is my updated code:

Account

#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;

//Account Class
class Account {
protected:
        int number;
    	double balance;
   		double rate;
		double interest;
		double NewBalance;

public:
        Account(); // Constructor
        Account(int, double, double) ;
               void setBalance(double);
                void setRate(double);
				void setNumber(int);

				int getNumber();
                double getBalance();
                double getRate();
				void valid_rate(double);

				//Virtual Function
				virtual void applyInterest() {
				}
				
				void operator +=( double );
        		void operator -=( double );
       			void operator ++ ();
                };      
//-----------------------------------------------------------------------------
//class definition
        Account::Account() {
                number = 0;
                balance = 0;
                rate = 0;
        }

        Account::Account(int number, double balance, double rate) {
                Account::number = number;
                Account::balance = balance;
                valid_rate(rate);
                }

void Account::setNumber(int number) {
    Account::number = number;
}

void Account::setBalance(double balance) {
    Account::balance = balance;
}

void Account::setRate(double rate) {
        valid_rate(rate);
}

int Account::getNumber() {
    return number;
}
double Account::getBalance() {
    return balance;
}
double Account::getRate() {
    return rate;
}

void Account::valid_rate(double rate) {
        if (rate >=.01 && rate <= .18)
                Account::rate=rate;
        else {
                Account::rate=0;
                cout << "WARNING! You have entered an invalid rate!\n";
        }
}

void Account::operator += ( double dValue ) {
        setBalance( getBalance()+ dValue );
                //return this;
    }
void Account::operator -= ( double dValue ) {
        setBalance( getBalance() - dValue );
                //return this;
    };


#endif

Checking

#ifndef CHECKING_H
#define CHECKING_H

#include "Account.h"

//Checking Class
class Checking:public Account
{
private:
		int CheckNumber;
    	int CheckingPin;

public:
        Checking(); // Constructor
        Checking(int, int) ;
		Checking(int, double, double, int);
               	void setCheckNumber(int);
				void setCheckingPin(int);
				void applyInterest();
				int getCheckNumber();
                int getCheckingPin();

};      
//-----------------------------------------------------------------------------
//class definition
        Checking::Checking() {
                CheckNumber = 0;
                CheckingPin = 0;
                
        }

        Checking::Checking(int CheckNumber, int CheckingPin) {
                Checking::CheckNumber = CheckNumber;
                Checking::CheckingPin = CheckingPin;
                
                }

void Checking::setCheckNumber(int CheckNumber) {
    Checking::CheckNumber = CheckNumber;
}

void Checking::setCheckingPin(int CheckingPin) {
    Checking::CheckingPin = CheckingPin;
}


int Checking::getCheckNumber() {
    return CheckNumber;
}
int Checking::getCheckingPin() {
    return CheckingPin;
}

void Checking::applyInterest() {
                interest = rate * balance;
                NewBalance = interest + balance;
                cout << interest << " has been added to checking.\n\n";
};

#endif

Credit

#ifndef CREDIT_H
#define CREDIT_H

#include "Account.h"
//Checking Class
class Credit:public Account
{
private:   
	string CardNumber;

public:
        Credit(); // Constructor
        Credit(string);
		Credit(int, double, double, string);
               	void setCardNumber(string);
				string getCardNumber();
				void applyInterest();

};      
//-----------------------------------------------------------------------------
//class definition
        Credit::Credit() {
                CardNumber = " ";
                                
        }

        Credit::Credit(string CardNumber) {
                Credit::CardNumber = CardNumber;
                                
                }

void Credit::setCardNumber(string CardNumber) {
    Credit::CardNumber = CardNumber;
}


string Credit::getCardNumber() {
    return CardNumber;
}


void Credit::applyInterest() {
                interest = rate * balance;
                NewBalance = interest + balance;
                cout << interest << " interest has been charged to this credit card on its unpaid balance.\n\n";
};

#endif

Saving

#ifndef SAVING_H
#define SAVING_H

//Customer Class
class Saving:public Account
{
private:

public:
Saving(int, double, double);
void applyInterest(); 
};

void Saving::applyInterest() {
				interest = rate * balance;
                NewBalance = interest + balance;
				cout << interest << " 23 interest has been charged to this credit card on its unpaid balance.\n\n";
};
#endif

Main.cpp

#include "Account.h"
#include "Checking.h"
#include "Saving.h"
#include "Credit.h"
using namespace std;

int main() {

	int current_cust=0;
	Checking *myChecking[1];
	Saving *mySaving[1];
	Credit *myCredit[1];

	Checking myRate;
		myChecking[0] = new Checking(832443, 560.10, .02, 5);
		mySaving[0] = new Saving(832243, 1020.58, .04);
		myCredit[0] = new Credit(832443, 78.00, .16, "1238201293731133"); 

	cout << "__________________________________________________________\n"<< endl;

	for (int c=0; c<1; c++)
		myChecking[c]->applyInterest();

		cout << "__________________________________________________________\n"<< endl;

	for (int s=0; s<1; s++)
		mySaving[s]->applyInterest();

		cout << "__________________________________________________________\n"<< endl;

	for (int x=0; x<1; x++)
		myCredit[x]->applyInterest();

	cout << "__________________________________________________________\n"<< endl;

        return 0;
}

ERRORS:

1>------ Build started: Project: TestTwo, Configuration: Debug Win32 ------
1> Main.cpp
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Credit::Credit(int,double,double,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Credit@@QAE@HNNV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Saving::Saving(int,double,double)" (??0Saving@@QAE@HNN@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Checking::Checking(int,double,double,int)" (??0Checking@@QAE@HNNH@Z) referenced in function _main
1>\TestTwo.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Quick question. Have you ever included files before ? If no then I think
for some reason the header files in the main class are not getting included. That is why, when you call the constructor of the classes defined in those files you are getting an error.

You are getting these linker errors, since the constructors given in the error cannot be found by the linker.

Try implementing them.

Credit(int, double, double, string);
Saving(int, double, double);
Checking(int, double, double, int);
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.