When I try to compile my code in visual basic 2010 it gives me the error 1903 and when I compile the code in Code::Blocks it opens the standard template library's algorithm.h file and takes me to line 2163 if (*__i < *__first) I don't want to modify anything here, but I can't figure out what its wanting me to do.

How can I fix this problem?

Here is my code for reference:

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
//Template that puts things where they go.
template <class T>
void produceReport(string report, T acctType, int tableRows)
    {
cout << report << endl;
cout << acctType << endl;
cout << tableRows;
};
//Template that adds in an amount of dashes to indicate end of report.
template <class T>
void reportValue(T value, int amount)
    {
    for(int x = 0; x < amount; x++)
        {
    cout << "-";
    }
    cout << "End of report." << endl;
};
//Class that takes care of the exception handling.
class BankAccountException : public runtime_error
    {
    private:
        int bankAccountNum;
    public:
        BankAccountException(int);
        int getAccountNum();
        virtual const char* what();
};
//sets the the bank account number to number for the runtime error
BankAccountException::BankAccountException(int number) : runtime_error("")
    {
    bankAccountNum = number;
}
//returns the bank account number
int BankAccountException::getAccountNum()
    {
    return bankAccountNum;
}
//message to throw to the user when something whent wrong.
const char* BankAccountException::what()
    {
    return "wasn't entered correctly try again.";
}
//A class for a number of bank accounts.
class BankAccount
    {
    friend ostream& operator<<(ostream&, const BankAccount&);
    friend istream& operator>>(istream&, BankAccount&)throw(BankAccountException);
    private:
        int accountNum;
        double accountBal;
    public:
        BankAccount(int = 0,double = 0.0);
        void enterAccountData();
        void displayAccounts();
        void setAccts(int,double);
        int getAcctNum();
        double getAcctBal();
    };
//Sets each attribute of the bank account.
BankAccount::BankAccount(int acctNum, double acctBal)
{
    accountNum = acctNum;
    accountBal = acctBal;
}
//Displays accounts that the user entered into the program
ostream& operator << (ostream& bankInfo, const BankAccount& Accounts)
{
    cout << endl;
    bankInfo << "Account #" << Accounts.accountNum << endl;
    bankInfo << "Account Balance:$" << Accounts.accountBal << endl;
    cout << endl;
return bankInfo;
}
//Takes in information from the user about each bank account
istream& operator >> (istream& bankData, BankAccount& Accounts)
{
    const int HIGHEST = 9999;
    const int LOWEST = 1000;
    cout << "Enter Account # ";
    bankData >> Accounts.accountNum;
    while(Accounts.accountNum < LOWEST || Accounts.accountNum > HIGHEST)
        {
        BankAccountException message(Accounts.accountNum);
        throw(message);
    }
    cout << "Enter Account Balance: $";
    bankData >> Accounts.accountBal;
    cout << endl;
return bankData;
}
//Function that takes in parameters for a bank account when called.
void BankAccount::enterAccountData()
    {
    const int HIGHEST = 9999;
    const int LOWEST = 1000;
    cout << "Enter account number between 1000 and 9999: #";
    cin >> accountNum;
    while(accountNum < LOWEST || accountNum > HIGHEST)
        {
    cout << "You didn't enter a valid account number. Please try again." << endl
        << "#";
    cin >> accountNum;
        }
    cout << endl << "Enter the account balance:$";
    cin >> accountBal;
}
//Displays bank accounts that have been given information from a constructor and/or user.
void BankAccount::displayAccounts()
        {
cout << endl << "Account # " << accountNum << endl;
cout << "Account balance:$" << accountBal << endl;
cout << endl;
}
//Sets account number and balance.
void BankAccount::setAccts(int acctNum, double acctBal)
    {
accountNum = acctNum;
accountBal = acctBal;
}
//Gets the account number.
int BankAccount::getAcctNum()
    {
return accountNum;
}
//Gets the account balance.
double BankAccount::getAcctBal()
    {
return accountBal;
}
//Savings Account that will be used for processing savings information.
class SavingsAccount : public virtual BankAccount
    {
friend ostream& operator<<(ostream&, const SavingsAccount&);
friend istream& operator>>(ostream&, const SavingsAccount&);
    private:
        double interestRate;
    public:
        SavingsAccount(double = 0.0);
        void displaySavAccount();
        void getSavInfo();
};
//Constructor for Savings account
SavingsAccount::SavingsAccount(double rate)
    {
interestRate = rate;
}
//Gets the savings accounts information when needed.
void SavingsAccount::getSavInfo()
    {
cout << "Enter your interest rate below." << endl;
cin >> interestRate;
}
//Displays the information gathered from the user.
ostream& operator<<(ostream& bankInfo, SavingsAccount& aSAccount)
    {
aSAccount.displaySavAccount();
return bankInfo;
}
//Requests data from the user.
istream& operator>>(istream& bankInfo, SavingsAccount& aSAccount)
    {
aSAccount.getSavInfo();
return bankInfo;
}
//Function that displays the information for a savings account.
void SavingsAccount::displaySavAccount()
    {
cout << "-----Savings Information-----" << endl;
cout << "Interest rate is currently: " << interestRate;
cout << " for this account" << endl;
}
//Class made to check and show checking account information.
class CheckingAccount : public virtual BankAccount
    {
    friend ostream& operator<<(ostream& bankInfo, const CheckingAccount& aCheckAcct);
    friend istream& operator>>(istream& bankInfo, const CheckingAccount& aCheckAcct);
private:
    double monthlyFee;
    int checksAllowed;
public:
    CheckingAccount(double = 0,int = 0,int = 0,double = 0);
    void displayCAccount();
    void getCheckInfo();
};
//Constructor that References the Bank account class to share information.
CheckingAccount::CheckingAccount(double fee, int allowed, int num, double bal) 
    : BankAccount(num,bal), monthlyFee(fee), checksAllowed(allowed)
    {

}
//Requested information from the user for checking accounts.
void CheckingAccount::getCheckInfo()
    {
cout << "Enter monthly fee of this checking account. $";
cin >> monthlyFee;
cout << endl << "How many checks are you allowed?" << endl;
cin >> checksAllowed;
}
/*Displays the information used from the 
function that displays checking account information*/
ostream& operator<<(ostream& bankInfo, CheckingAccount& aCAcct)
    {
aCAcct.displayCAccount();
return bankInfo;
}
/*Requests information used within the
function that gets information from the user about
a checking account*/
istream& operator>>(istream& bankInfo, CheckingAccount& aCAcct)
    {
aCAcct.getCheckInfo();
return bankInfo;
}
/*Function that displays information to the user about
the checking account*/
void CheckingAccount::displayCAccount()
    {
cout << "-----Checking Information-----" << endl;
cout << "Monthly fee on the account is:$" << monthlyFee << endl;
cout << "Checks allowed for this account is: " << checksAllowed << endl;
cout << "|---------------------------------------------|";
}
//A Class for a checking account with a set interest.
class CheckingWithInterest 
: public SavingsAccount, public CheckingAccount
    {
    friend ostream& operator<<(ostream& bank_Info_Out, const CheckingWithInterest& wIAcct);
    friend istream& operator>>(istream& bank_Info_In, const CheckingWithInterest& wIAcct);
    public:
    CheckingWithInterest();
    void displayWithInterest();
};
//Default constructor for the special accounts
CheckingWithInterest::CheckingWithInterest() 
: CheckingAccount(0,0,9999,0), SavingsAccount(0.02)
    {

}
// Displays the accounts information
void CheckingWithInterest::displayWithInterest()
    {
BankAccount::displayAccounts();
SavingsAccount::displaySavAccount();
CheckingAccount::displayCAccount();
}
//Displays interest rates on the accounts.
ostream& operator<<(ostream& bank_Info_Out, CheckingWithInterest& wIAcct)
    {
wIAcct.displayWithInterest();
return bank_Info_Out;
}
//Operator that takes in accounts with an interest in the checking account.
istream& operator>>(istream& bank_Info_In, CheckingWithInterest& wIAcct)
    {
wIAcct.enterAccountData();
wIAcct.getCheckInfo();
return bank_Info_In;
}
/*Main function that makes and displays any number of accounts
it is currently set to a Maximum of 2 accounts for ease of logic
error checking. Change the number to make more bank accounts*/
int main()
    {
    unsigned count;
    //Declares the objects and references the classes used above.
    vector<BankAccount>bankAccount;
    BankAccount aBankAcct;
    /*vector<SavingsAccount>savAccount;
    SavingsAccount aSavAcct;
    vector<CheckingAccount>chAccount;
    CheckingAccount aChAcct;
    vector<CheckingWithInterest>withInAccount;
    CheckingWithInterest aWtIntAcct; */
    //Declare Variables to be used
    const int MAX_ACCTS = 4;
    int x = 0;
    const char QUIT = 'n';
    char quitChar = 'y';

    //Ask the user if they would like to enter in information.
    cout << "Would you like to enter in Bank Account information? y or n ";
    cin >> quitChar;

    /*Loops through an amount of bank accounts and allows 
    the user to quit if they want to.*/
    while(quitChar != QUIT && x < MAX_ACCTS)
        {
            try
            {
    aBankAcct.enterAccountData();
    bankAccount.push_back(aBankAcct);
    x++;
    cout << endl << "Would you like to enter in more Bank Accounts? y or n ";
    cout << endl << "The maximum number of Bank Accounts is  " << MAX_ACCTS;
    cout << endl;
    cin >> quitChar;
            }
            catch(BankAccountException message)
            {
                cout << "The #" << message.getAccountNum() << " isn't valid. " << endl;
                bankAccount.pop_back();
                aBankAcct.enterAccountData();
                bankAccount.push_back(aBankAcct);
            }
    }

    //Sorts the Bank Accounts.
    sort(bankAccount.begin(), bankAccount.end());
    for(count = 0; count < bankAccount.size(); ++count)
        {
    cout << (bankAccount.at(count), count);
    cout << endl;
    produceReport("Bank Account information",bankAccount.at(count), bankAccount.size());
    }
    x = 0; /*resets the  variable x to zero, so 
    the other functions work properly as programmed*/
    /*
    cout << "Would you like to enter in Savings Information? y or n";
    cin >> quitChar;

    /*Loops through an amount of savings accounts and allows 
    the user to quit if they want to.
    while(quitChar != QUIT && x < MAX_ACCTS)
        {
    aSavAcct.enterAccountData();
    aSavAcct.getSavInfo();
    savAccount.push_back(aSavAcct);
    cout << endl << "Would you like to enter in more Savings Accounts? y or n";
    cout << endl << "The maximum number of Savings Accounts is  " << MAX_ACCTS;
    cout << endl;
    cin >> quitChar;
    }

    //Sorts the Savings Accounts.
    sort(savAccount.begin(), savAccount.end());
    for(count = 0; count < savAccount.size(); ++count)
        {
    cout << (savAccount.at(count), count);
    cout << endl;
    produceReport("Savings Account information",savAccount.at(count), savAccount.size());
    }
    x = 0;/*resets the  variable x to zero, so 
    the other functions work properly as programmed OLD COMMENT HERE

    cout << endl << "Would you like to enter in Checking Account information? y or n";
    cin >> quitChar;

    /*Loops through an amount of checking accounts and allows 
    the user to quit if they want to. OLD COMMENT HERE
    while(quitChar != QUIT && x < MAX_ACCTS)
        {
    aChAcct.enterAccountData();
    aChAcct.getCheckInfo();
    chAccount.push_back(aChAcct);
    cout << endl << "Would you like to enter in more Checking Accounts? y or n";
    cout << endl << "The maximum number of Checking Accounts is  " << MAX_ACCTS;
    cout << endl;
    cin >> quitChar;
    }

    //Sorts the Checking Accounts.
    sort(chAccount.begin(), chAccount.end());
    for(count = 0; count < chAccount.size(); ++count)
        {
    cout << (chAccount.at(count), count);
    cout << endl;
    produceReport("Checking Account information",chAccount.at(count), chAccount.size());
    }
    x = 0;/*resets the  variable x to zero, so 
    the other functions work properly as programmed OLD COMMENT HERE

    cout << endl << "Would you like to enter in Checking with interest Account information? y or n";
    cin >> quitChar;

    /*Loops through an amount of checking with interest 
    accounts and allows the user to quit if they want to. OLD COMMENT HERE
    while(quitChar != QUIT && x < MAX_ACCTS)
        {
    aWtIntAcct.enterAccountData();
    aWtIntAcct.getSavInfo();
    aWtIntAcct.getCheckInfo();
    withInAccount.push_back(aWtIntAcct);
    cout << endl << "Would you like to enter in more Checking with Interest Accounts? y or n";
    cout << endl << "The maximum number of Checking Accounts is  " << MAX_ACCTS;
    cout << endl;
    cin >> quitChar;
    }

    //Sorts the Checking with Interest Accounts.
    sort(withInAccount.begin(), withInAccount.end());
    for(count = 0; count < withInAccount.size(); ++count)
        {
    cout << (withInAccount.at(count), count);
    cout << endl;
    produceReport("Checking with interest Account information",withInAccount.at(count), withInAccount.size());
    } */

    system("pause");
return 0;
}

Recommended Answers

All 7 Replies

When I try to compile my code in visual basic 2010 it gives me the error 1903

I think you meant to say Visual C++ 2010

Error 1903 just means there were too many previous errors and the compiler gave up. Usually the first error is the most relevent.

Looks like the problem is repeatValue() template. Why is that a template?

If you mean the reportValue() template I was trying to have it just repeat itself a certain amount of times that was equal to the amount of accounts that were listed.

The problem is that you are trying to sort BankAccount objects, but that class does not have a less-than comparison operator. The standard sort algorithm (unless otherwise specified) will use the less-than < operator to order to values. You need to overload that operator to be able to use the sort function. Here is a start:

bool operator<(const BankAccount& lhs, const BankAccount& rhs) {
  // insert code here that returns true if 'lhs' is less than 'rhs'.
};

So within the BankAccount class make a bool operator that will have two different objects that are compared to see which way they should be ordered?

Yes, you can either define the operator as a member of the class or as a free function.

As a member function, you do it as follows:

//A class for a number of bank accounts.
class BankAccount
    {
    friend ostream& operator<<(ostream&, const BankAccount&);
    friend istream& operator>>(istream&, BankAccount&);
    private:
        int accountNum;
        double accountBal;
    public:
        BankAccount(int = 0,double = 0.0);
        void enterAccountData();
        void displayAccounts() const;
        void setAccts(int,double);
        int getAcctNum() const;
        double getAcctBal() const;

        // Add the less-than operator:
        bool operator<(const BankAccount& rhs) const;
    };

//..

bool BankAccount::operator<(const BankAccount& rhs) const {
  // insert code here, to compare 'this' with 'rhs'
  // for example, this:
  return this->accountNum < rhs.accountNum;
};

And as a normal (free) function, you would do:

//A class for a number of bank accounts.
class BankAccount
    {
    friend ostream& operator<<(ostream&, const BankAccount&);
    friend istream& operator>>(istream&, BankAccount&);
    private:
        int accountNum;
        double accountBal;
    public:
        BankAccount(int = 0,double = 0.0);
        void enterAccountData();
        void displayAccounts() const;
        void setAccts(int,double);
        int getAcctNum() const;
        double getAcctBal() const;
    };

//..

bool operator<(const BankAccount& lhs, const BankAccount& rhs) {
  // insert code here, to compare 'lhs' with 'rhs'
  // for example, this:
  return lhs.getAcctNum() < rhs.getAcctNum();
};

It is generally preferrable to use free-functions for operator overloading.

Thanks a lot that fixed the issue. It's crazy to me that it did fix it and the function doesn't even have to be within main or called within main in order for it to work.

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.