1. Welcome to Tacoma World!

    You are currently viewing as a guest! To get full-access, you need to register for a FREE account.

    As a registered member, you’ll be able to:
    • Participate in all Tacoma discussion topics
    • Communicate privately with other Tacoma owners from around the world
    • Post your own photos in our Members Gallery
    • Access all special features of the site

C++ Assignment help

Discussion in 'Technology' started by tarheelfan_08, Feb 15, 2010.

  1. Feb 15, 2010 at 4:29 PM
    #1
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    I am having trouble with one of my school assignments. If someone can please help me with my errors I would be extremely happy! I will include my assignment, the 3 files(it’s a class) and the errors. If you need me to I can zip these filed and attach them!


    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 the two main problem domain objects (“things” in our system we need to keep track of) are “Accounts” and “Customers”. You find out that customers have accounts, and that a customer can have more than one account (of different types like checking, savings, or overdraft/credit card.) Accounts are thought of as being distinct objects and should never be separated from the Customers that they are a part of.


    Customer Class (20 points):
    Attributes/data members:
    name (a string)
    ssn (a string)
    address (a string)
    birthdate (a Date)
    savings (an Account)
    checking (an Account)

    Behaviors/member functions:
    1) accessor (get) and mutator (set) functions for all attributes.
    2) DisplayCustomer(), this function should show a message on the console with the customer’s name, ssn, and the balances for each account.

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

    Date Class:
    (This class is from your company’s current class library. See separate file for the date class. It is from page 714 in your book.)

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

    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.

    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 .10 (it is an interest rate as a decimal)
    2) Balances should never be allowed to be set to a negative value.


    2. (15 points)Add operator overloading to the Account class to allow the +, -, /, and * operators to be used to do mathematical calculations between two accounts.

    Change the Customer class DisplayCustomer() function to show the consolidated balance as well. Create a temporary account and set it equal to savings + checking (using the overloaded + operator), then report its balance as the consolidated balance (or total balance if you prefer to call it this.)

    3. (9 points)Create statements in main() to test your new classes.

    1) Create two new customers in your program (with all their data.)

    2) Display the customer information for your two customers using the DisplayCustomer() function.

    3) Call the ApplyInterest() function to apply the interest for the current period.

    4) Display the customer information for your two customers again using the DisplayCustomer() function.


    Customer Header File

    Code:
    #ifndef CUSTOMER_H
    #define CUSTOMER_H
    
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <functional>
    #include <algorithm>
    #include <string>
    #include <cstdlib>
    #include <sstream>
    using namespace std;
    
    //Customer Class
    class Customer {
    private:
        string name;  //name of customer
        string ssn; // social security number
        string address;  // address
        int birthDate;    //birth date
        int    savings;  // savings account balance
        int checking;  // checking account balance
        int balance;    // Consoldated Balance
    
    public:
        Customer(); //constructor
        Customer(string, string, string, int ,int, int, int);
        void setName(string);
        void setSSN(string);
        void setAddress(string);
        void setBirthDate(int);
        void setSavings(int);
        void setChecking(int);
        void setBalance(int);
    
        string getName();
        string getSSN();
        string getAddress();
        int getBirthDate();
        int getSavings();
        int getChecking();
        int getBalance();
    
        void displayCustomer();
        string string_displayCustomer();
    };
    
    
    //-----------------------------------------------------------------------------
    //class definition
    Customer::Customer() {
        name = " ";
        ssn = " ";
        address = " ";
        birthDate = 0;
        savings = 0;
        checking = 0;
        balance = 0;
    }
    
    Customer::Customer(string name, string ssn, string address, int birthDate, int savings, int checking, int balance) {
        Customer::name =  name;
        Customer::ssn = ssn;
        Customer::address = address;
        Customer::birthDate = birthDate;
        Customer::savings = savings;
        Customer::checking = checking;
        Customer::balance = balance;
    }
    
    void Customer::setName(string name) {
        Customer::name = name;
    }
    
    void Customer::setSSN(string ssn) {
        Customer::ssn = ssn;
    }
    
    void Customer::setAddress(string address) {
        Customer::address = address;
    }
    
    void Customer::setBirthDate(int birthDate) {
        Customer::birthDate = birthDate;
    }
    
    void Customer::setSavings(int savings) {
        Customer::savings = savings;
    }
    
    void Customer::setChecking(int checking) {
        Customer::checking = checking;
    }
    
    void Customer::setBalance(int balance) {
        Customer::balance = balance;
    }
    
    
    
    string Customer::getName() {
        return name;
    }
    
    string Customer::getSSN() {
        return ssn;
    }
    
    string Customer::getAddress() {
        return address;
    }
    
    int Customer::getBirthDate() {
        return birthDate;
    }
    
    int Customer::getSavings() {
        return savings;
    }
    
    int Customer::getChecking() {
        return checking;
    }
    
    int Customer::getBalance() {
        return balance;
    
    }
    
    void Customer::displayCustomer() {
        cout << "The current customer is " << name << ", their address is " << address << ", and their Social Security Number is "
            << ssn << ".  "  << name << "'s Saving Account Ballance is:" << savings << ".  The Checking Account Balance is:" << checking << ".\n";
        cout << "The consolidated balance is: $" << balance << ".\n";
    }
    
    string Customer::string_displayCustomer() {
        stringstream buf;
        cout << "The current customer is " << name << ", their address is " << address << ", and their Social Security Number is "
        << ssn << ".  "  << name << "'s Saving Account Ballance is:" << savings << ".  The Checking Account Balance is:" << checking << ".\n";
        cout << "The consolidated balance is: $" << balance << ".\n";
        return buf.str();
    }
    #endif
    
    
    Account Header File

    Code:
    #ifndef ACCOUNT_H
    #define ACCOUNT_H
    
    #include "Customer.h"
    
    //Account Class
    class Account {
    private:
        Customer myCustomer[2];
        string type;
        int number;
        double balance;
        double rate;
        double intrest;
        double NewBalance;
    
    public:
        Account(); // Constructor
        Account(string, int, double, double) {
            void setType(string);
            void setNumber(int);
            void setBalance(double);
            void setRate(double);
    
            string getType();
            int getNumber();
            double getBalance();
            double getRate();
    
            void valid_Rate(double);
            void ApplyInterest();
        };
    //-----------------------------------------------------------------------------
    //class definition
        Account::Account() {
            type = " ";
            number = 0;
            balance = 0;
            rate = 0;
        }
    
        Account::Account(string type, int number, double balance, double rate) {
            Account::type = type;
            Account::number = number;
            Account::balance = balance;
            valid_rate(rate);
            }
    void Account::setType(string type) {
        Account::type = type;
    }
    
    void Account::setNumber(int number) {
        Account::number = number;
    }
    
    void Account::setBalance(double balance) {
        Account::balance = balance;
    }
    
    void Account::setRate(double rate) {
        valid_rate(rate);
    }
    
    string Account::getType() {
        return type;
    }
    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 <= .1)
            Account::rate=rate;
        else {
            Account::rate=0;
            cout << "WARNING! You have entered an invalid rate!\n";
        }
    }
    
    void Account::ApplyIntrest() {
            intrest = rate * balance;
            NewBalance = intrest + balance;
            cout << "The amount of intrest for the Customer is: $" << intrest << " and the account balance is: $" << NewBalance << ".\n";
    }    
    
    Customer& getCustomer(int n) {
        return myCustomer[n];
    }
    
        void operator += (Account& a) {
            setBalance(balance + a.balance());
        }
    
        void operator -= (Account& a) {
            setBalance(balance - a.balance());
        }
    
        void operator ++ (int n) {
            Customer::balance(Customer::savings + Customer::checking);
        }
    
    
    };
    #endif
    
    
    
    Date Header File

    Code:
    #ifndef DATE_H
    #define DATE_H
    
    #include "Customer.h"
    //Date class
    class Date
    {
    private:
       string month;
       int day;
       int year;
    public:
       void setDate(string month, int day, int year)
       {
         this->month = month;
         this->day = day;
         this->year = year;
       }
       Date(string month, int day, int year)
       {
          setDate(month, day, year);
       }
       Date()
       {
          setDate("January", 1, 1900);
       }
       string getMonth() { return month; }
       int getDay() { return day; }
       int getYear() { return year; }
    
    }
    
    #endif
    
    Errors

    1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
    1> Test1.cpp
    \account.h(35): error C2535: 'Account::Account(void)' : member function already defined or declared
    1> \account.h(18) : see declaration of 'Account::Account'
    \account.h(42): error C2535: 'Account::Account(std::string,int,double,double)' : member function already defined or declared
    1> \account.h(19) : see declaration of 'Account::Account'
    \account.h(97): error C2064: term does not evaluate to a function taking 0 arguments
    \account.h(101): error C2064: term does not evaluate to a function taking 0 arguments
    \account.h(105): error C2597: illegal reference to non-static member 'Customer::balance'
    \account.h(105): error C2597: illegal reference to non-static member 'Customer::savings'
    \account.h(105): error C3867: 'Customer::savings': function call missing argument list; use '&Customer::savings' to create a pointer to member
    \account.h(105): error C2597: illegal reference to non-static member 'Customer::checking'
    \account.h(105): error C3867: 'Customer::checking': function call missing argument list; use '&Customer::checking' to create a pointer to member
    \account.h(105): error C2568: '+' : unable to resolve function overload
    1> unable to recover from previous error(s); stopping compilation
     
  2. Feb 15, 2010 at 4:33 PM
    #2
    oldtacomaguy

    oldtacomaguy four forty four

    Joined:
    Dec 11, 2006
    Member:
    #444
    Messages:
    10,032
    Gender:
    Male
    First Name:
    Dave
    SE Conn.
    Vehicle:
    08 SR-5 4WD Impulse Red Pearl
    Alpine deck and amp, Polk speakers front and rear, Kenwood subwoofer, windows tinted to 20%, Sockmonkey decals, TSB, Eibach springs and Bilstein 5100's
    I don't know about anyone else, but this makes my head hurt! Good luck.
     
  3. Feb 15, 2010 at 4:38 PM
    #3
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    i dont think that you can overload constructors, but you can set defaults for variables in the parameter list.
     
  4. Feb 15, 2010 at 4:41 PM
    #4
    topgun155

    topgun155 Well-Known Member

    Joined:
    Dec 18, 2008
    Member:
    #11728
    Messages:
    2,789
    Gender:
    Male
    First Name:
    Zack
    Richmond, TX
    Vehicle:
    2018 F-150 5.0
    RIP to my 08 Prerunner DC
    x2
     
  5. Feb 15, 2010 at 4:44 PM
    #5
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    add default values for your parameters in a single constructor like this:

    Code:
     
    public:
        Account(string, int, double, double) {
            void setType(string);
            void setNumber(int);
            void setBalance(double);
            void setRate(double);
            string getType();
            int getNumber();
            double getBalance();
            double getRate();
            void valid_Rate(double);
            void ApplyInterest();
        };
    //-----------------------------------------------------------------------------
    //class definition
        Account::Account(string type = "", int number = 0, double balance = 0, double rate = 0) 
    {
            Account::type = type;
            Account::number = number;
            Account::balance = balance;
            valid_rate(rate);
    }
    
    test it by not assigning any values to the constuctor call... just to be sure :)
     
  6. Feb 15, 2010 at 4:53 PM
    #6
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    oh wait...duh... you can overload constructors, but you dont need to define the default constructor in your definition list. only define the constructors that take parameters.

    here is an example:
    http://www2.cs.uregina.ca/~saxton/CS115/Notes/Overloading/overload.html

    like this:

    Code:
     
    //Account Class
    class Account {
    private:
        Customer myCustomer[2];
        string type = "";
        int number = 0;
        double balance = 0;
        double rate = 0;
        double intrest;
        double NewBalance;
    public:
        Account(); // Default Constructor
        Account(string, int, double, double) {
            void setType(string);
            void setNumber(int);
            void setBalance(double);
            void setRate(double);
            string getType();
            int getNumber();
            double getBalance();
            double getRate();
            void valid_Rate(double);
            void ApplyInterest();
        };
    //-----------------------------------------------------------------------------
    //class definition
        Account::Account(string type, int number, double balance, double rate) 
    {
            Account::type = type;
            Account::number = number;
            Account::balance = balance;
            valid_rate(rate);
     }
    
     
  7. Feb 15, 2010 at 5:13 PM
    #7
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    Here is my new code and the new errors!

    Code:
    #ifndef ACCOUNT_H
    #define ACCOUNT_H
    
    #include "Customer.h"
    
    //Account Class
    class Account {
    private:
        Customer myCustomer[2];
        string type = "";
        int number = 0;
        double balance = 0;
        double rate = 0;
        double intrest;
        double NewBalance;
    public:
        Account(); // Default Constructor
        Account(string, int, double, double) {
            void setType(string);
            void setNumber(int);
            void setBalance(double);
            void setRate(double);
            string getType();
            int getNumber();
            double getBalance();
            double getRate();
            void valid_Rate(double);
            void ApplyInterest();
        };
    //-----------------------------------------------------------------------------
    //class definition
        Account::Account(string type, int number, double balance, double rate) 
    {
            Account::type = type;
            Account::number = number;
            Account::balance = balance;
            valid_rate(rate);
     }
    void Account::setType(string type) {
        Account::type = type;
    }
    
    void Account::setNumber(int number) {
        Account::number = number;
    }
    
    void Account::setBalance(double balance) {
        Account::balance = balance;
    }
    
    void Account::setRate(double rate) {
        valid_rate(rate);
    }
    
    string Account::getType() {
        return type;
    }
    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 <= .1)
            Account::rate=rate;
        else {
            Account::rate=0;
            cout << "WARNING! You have entered an invalid rate!\n";
        }
    }
    
    void Account::ApplyIntrest() {
            intrest = rate * balance;
            NewBalance = intrest + balance;
            cout << "The amount of intrest for the Customer is: $" << intrest << " and the account balance is: $" << NewBalance << ".\n";
    }    
    
    Customer& getCustomer(int n) {
        return myCustomer[n];
    }
    
        void operator += (Account& a) {
            setBalance(balance + a.balance());
        }
    
        void operator -= (Account& a) {
            setBalance(balance - a.balance());
        }
    
        void operator ++ (int n) {
            Customer::balance(Customer::savings + Customer::checking);
        }
    
    
    };
    #endif
    
    
    1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
    1> Test1.cpp
    1>\account.h(10): error C2864: 'Account::type' : only static const integral data members can be initialized within a class
    1>\account.h(11): error C2864: 'Account::number' : only static const integral data members can be initialized within a class
    1>\account.h(12): error C2864: 'Account::balance' : only static const integral data members can be initialized within a class
    1>\account.h(13): error C2864: 'Account::rate' : only static const integral data members can be initialized within a class
    1>\account.h(33): error C2535: 'Account::Account(std::string,int,double,double)' : member function already defined or declared
    1> \account.h(18) : see declaration of 'Account::Account'
    1>\account.h(88): error C2064: term does not evaluate to a function taking 0 arguments
    1>\account.h(92): error C2064: term does not evaluate to a function taking 0 arguments
    1>\account.h(96): error C2597: illegal reference to non-static member 'Customer::balance'
    1>\account.h(96): error C2597: illegal reference to non-static member 'Customer::savings'
    1>\account.h(96): error C3867: 'Customer::savings': function call missing argument list; use '&Customer::savings' to create a pointer to member
    1>\account.h(96): error C2597: illegal reference to non-static member 'Customer::checking'
    1>\account.h(96): error C3867: 'Customer::checking': function call missing argument list; use '&Customer::checking' to create a pointer to member
    1>\account.h(96): error C2568: '+' : unable to resolve function overload
    1> unable to recover from previous error(s); stopping compilation
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
     
  8. Feb 15, 2010 at 5:51 PM
    #8
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    i think i might have led you astray.

    in your public declaration of Account, you were actually defining the constructor. thats why you were getting the "already defined" errors.

    try this:

    Code:
     
    //Account Class
    class Account {
    private:
        Customer myCustomer[2];
        string type;
        int number;
        double balance;
        double rate;
        double intrest;
        double NewBalance;
     
    public:
        Account(); // Constructor
        Account(string, int, double, double); 
     
        void setType(string);
        void setNumber(int);
        void setBalance(double);
        void setRate(double);
     
        string getType();
        int getNumber();
        double getBalance();
        double getRate();
     
        void valid_Rate(double);
        void ApplyInterest();
    };
    //-----------------------------------------------------------------------------
    //class definition
        Account::Account() 
    {
            type = " ";
            number = 0;
            balance = 0;
            rate = 0;
     }
     
        Account::Account(string type, int number, double balance, double rate) 
    {
            Account::type = type;
            Account::number = number;
            Account::balance = balance;
            valid_rate(rate);
    }
     
    
     
  9. Feb 15, 2010 at 6:12 PM
    #9
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    Ok man I made your changes you told me and I got a ton of errors!

    Code:
    #ifndef ACCOUNT_H
    #define ACCOUNT_H
    
    #include "Customer.h"
    
    //Account Class
    class Account {
    private:
        Customer myCustomer[2];
        string type;
        int number;
        double balance;
        double rate;
        double intrest;
        double NewBalance;
     
    public:
        Account(); // Constructor
        Account(string, int, double, double); 
     
        void setType(string);
        void setNumber(int);
        void setBalance(double);
        void setRate(double);
     
        string getType();
        int getNumber();
        double getBalance();
        double getRate();
     
        void valid_Rate(double);
        void ApplyInterest();
    };
    //-----------------------------------------------------------------------------
    //class definition
        Account::Account() 
    {
            type = " ";
            number = 0;
            balance = 0;
            rate = 0;
     }
     
        Account::Account(string type, int number, double balance, double rate) 
    {
            Account::type = type;
            Account::number = number;
            Account::balance = balance;
            valid_rate(rate);
    }
    void Account::setType(string type) {
        Account::type = type;
    }
    
    void Account::setNumber(int number) {
        Account::number = number;
    }
    
    void Account::setBalance(double balance) {
        Account::balance = balance;
    }
    
    void Account::setRate(double rate) {
        valid_rate(rate);
    }
    
    string Account::getType() {
        return type;
    }
    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 <= .1)
            Account::rate=rate;
        else {
            Account::rate=0;
            cout << "WARNING! You have entered an invalid rate!\n";
        }
    }
    
    void Account::ApplyIntrest() {
            intrest = rate * balance;
            NewBalance = intrest + balance;
            cout << "The amount of intrest for the Customer is: $" << intrest << " and the account balance is: $" << NewBalance << ".\n";
    }    
    
    Customer& getCustomer(int n) {
        return myCustomer[n];
    }
    
        void operator += (Account& a) {
            setBalance(balance + a.balance());
        }
    
        void operator -= (Account& a) {
            setBalance(balance - a.balance());
        }
    
        void operator ++ (int n) {
            Customer::balance(Customer::savings + Customer::checking);
        }
    
    
    };
    #endif
    
    
    1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
    1> Test1.cpp
    1>\account.h(49): error C3861: 'valid_rate': identifier not found
    1>\account.h(64): error C3861: 'valid_rate': identifier not found
    1>\account.h(80): error C2039: 'valid_rate' : is not a member of 'Account'
    1> \account.h(7) : see declaration of 'Account'
    1>\account.h(82): error C2597: illegal reference to non-static member 'Account::rate'
    1>\account.h(84): error C2597: illegal reference to non-static member 'Account::rate'
    1>\account.h(89): error C2039: 'ApplyIntrest' : is not a member of 'Account'
    1> \account.h(7) : see declaration of 'Account'
    1>\account.h(90): error C2065: 'intrest' : undeclared identifier
    1>\account.h(90): error C2065: 'rate' : undeclared identifier
    1>\account.h(90): error C2065: 'balance' : undeclared identifier
    1>\account.h(91): error C2065: 'NewBalance' : undeclared identifier
    1>\account.h(91): error C2065: 'intrest' : undeclared identifier
    1>\account.h(91): error C2065: 'balance' : undeclared identifier
    1>\account.h(92): error C2065: 'intrest' : undeclared identifier
    1>\account.h(92): error C2065: 'NewBalance' : undeclared identifier
    1>\account.h(96): error C2065: 'myCustomer' : undeclared identifier
    1>\account.h(99): error C2805: binary 'operator +=' has too few parameters
    1>\account.h(100): error C2065: 'balance' : undeclared identifier
    1>\account.h(100): error C2248: 'Account::balance' : cannot access private member declared in class 'Account'
    1> \account.h(12) : see declaration of 'Account::balance'
    1> \account.h(7) : see declaration of 'Account'
    1>\account.h(100): error C2064: term does not evaluate to a function taking 0 arguments
    1>\account.h(100): error C3861: 'setBalance': identifier not found
    1>\account.h(103): error C2805: binary 'operator -=' has too few parameters
    1>\account.h(104): error C2065: 'balance' : undeclared identifier
    1>\account.h(104): error C2248: 'Account::balance' : cannot access private member declared in class 'Account'
    1> \account.h(12) : see declaration of 'Account::balance'
    1> \account.h(7) : see declaration of 'Account'
    1>\account.h(104): error C2064: term does not evaluate to a function taking 0 arguments
    1>\account.h(104): error C3861: 'setBalance': identifier not found
    1>\account.h(107): error C2803: 'operator ++' must have at least one formal parameter of class type
    1>\account.h(108): error C2597: illegal reference to non-static member 'Customer::balance'
    1>\account.h(108): error C2597: illegal reference to non-static member 'Customer::savings'
    1>\account.h(108): error C3867: 'Customer::savings': function call missing argument list; use '&Customer::savings' to create a pointer to member
    1>\account.h(108): error C2597: illegal reference to non-static member 'Customer::checking'
    1>\account.h(108): error C3867: 'Customer::checking': function call missing argument list; use '&Customer::checking' to create a pointer to member
    1>\account.h(108): error C2568: '+' : unable to resolve function overload
    1> unable to recover from previous error(s); stopping compilation
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
     
  10. Feb 15, 2010 at 6:46 PM
    #10
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    ok... you have alot of typos.

    see the problems? this is just a few of them.

    Code:
     
    void valid_Rate(double);
     
    Account::Account(string type, int number, double balance, double rate) 
    {
        Account::type = type;
        Account::number = number;
        Account::balance = balance;
        valid_rate(rate);
    }
    

    Code:
     
    void ApplyInterest();
     
    void Account::ApplyIntrest() {
       intrest = rate * balance;
       NewBalance = intrest + balance;
       cout << "The amount of intrest for the Customer is: $" Account::interest << " and the account balance is: $" << Account::NewBalance << ".\n";
    } 
    

    Code:
     
    double intrest;
     
    void Account::ApplyIntrest() {
       intrest = rate * balance;
       NewBalance = intrest + balance;
       cout << "The amount of intrest for the Customer is: $" << interest << " and the account balance is: $" << NewBalance << ".\n";
    } 
    
     
  11. Feb 15, 2010 at 6:58 PM
    #11
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    Ah I see!

    Code:
    #ifndef ACCOUNT_H
    #define ACCOUNT_H
    
    #include "Customer.h"
    
    //Account Class
    class Account {
    private:
        Customer myCustomer[2];
        string type;
        int number;
        double balance;
        double rate;
        double intrest;
        double NewBalance;
     
    public:
        Account(); // Constructor
        Account(string, int, double, double); 
     
        void setType(string);
        void setNumber(int);
        void setBalance(double);
        void setRate(double);
     
        string getType();
        int getNumber();
        double getBalance();
        double getRate();
     
        void valid_rate(double);
        void ApplyInterest();
    };
    //-----------------------------------------------------------------------------
    //class definition
        Account::Account() 
    {
            type = " ";
            number = 0;
            balance = 0;
            rate = 0;
     }
     
        Account::Account(string type, int number, double balance, double rate) 
    {
            Account::type = type;
            Account::number = number;
            Account::balance = balance;
            valid_rate(rate);
    }
    void Account::setType(string type) {
        Account::type = type;
    }
    
    void Account::setNumber(int number) {
        Account::number = number;
    }
    
    void Account::setBalance(double balance) {
        Account::balance = balance;
    }
    
    void Account::setRate(double rate) {
        valid_rate(rate);
    }
    
    string Account::getType() {
        return type;
    }
    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 <= .1)
            Account::rate=rate;
        else {
            Account::rate=0;
            cout << "WARNING! You have entered an invalid rate!\n";
        }
    }
    
    void Account::ApplyInterest() {
            intrest = rate * balance;
            NewBalance = intrest + balance;
            cout << "The amount of intrest for the Customer is: $" << intrest << " and the account balance is: $" << NewBalance << ".\n";
    }    
    
    Customer& getCustomer(int n) {
        return myCustomer[n];
    }
    
        void operator += (Account& a) {
            setBalance(balance + a.balance());
        }
    
        void operator -= (Account& a) {
            setBalance(balance - a.balance());
        }
    
        void operator ++ (int n) {
            Customer::balance(Customer::savings + Customer::checking);
        }
    
    
    };
    #endif
    
    
    1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
    1> Test1.cpp
    1>\account.h(96): error C2065: 'myCustomer' : undeclared identifier
    1>\account.h(99): error C2805: binary 'operator +=' has too few parameters
    1>\account.h(100): error C2065: 'balance' : undeclared identifier
    1>\account.h(100): error C2248: 'Account::balance' : cannot access private member declared in class 'Account'
    1> \account.h(12) : see declaration of 'Account::balance'
    1> \account.h(7) : see declaration of 'Account'
    1>\account.h(100): error C2064: term does not evaluate to a function taking 0 arguments
    1>\account.h(100): error C3861: 'setBalance': identifier not found
    1>\account.h(103): error C2805: binary 'operator -=' has too few parameters
    1>\account.h(104): error C2065: 'balance' : undeclared identifier
    1>\account.h(104): error C2248: 'Account::balance' : cannot access private member declared in class 'Account'
    1> \account.h(12) : see declaration of 'Account::balance'
    1> \account.h(7) : see declaration of 'Account'
    1>\account.h(104): error C2064: term does not evaluate to a function taking 0 arguments
    1>\account.h(104): error C3861: 'setBalance': identifier not found
    1>\account.h(107): error C2803: 'operator ++' must have at least one formal parameter of class type
    1>\account.h(108): error C2597: illegal reference to non-static member 'Customer::balance'
    1>\account.h(108): error C2597: illegal reference to non-static member 'Customer::savings'
    1>\account.h(108): error C3867: 'Customer::savings': function call missing argument list; use '&Customer::savings' to create a pointer to member
    1>\account.h(108): error C2597: illegal reference to non-static member 'Customer::checking'
    1>\account.h(108): error C3867: 'Customer::checking': function call missing argument list; use '&Customer::checking' to create a pointer to member
    1>\account.h(108): error C2568: '+' : unable to resolve function overload
    1> unable to recover from previous error(s); stopping compilation
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
     
  12. Feb 15, 2010 at 7:17 PM
    #12
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    your overloaded increment and decrement functions dont have protopyes in your class definition.

    also, your overlaoded functions are referencing variables that have not been declared in the class definition.
     
  13. Feb 15, 2010 at 7:23 PM
    #13
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    huh?? I am knew to this! You are going to have to give me an example. The teacher gave us the code with no comments so its hard to tell what everything does!
     
  14. Feb 15, 2010 at 7:33 PM
    #14
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    these definitions need to be declared in your class:

    Code:
     
        void operator += (Account& a) {
            setBalance(balance + a.balance());
        }
        void operator -= (Account& a) {
            setBalance(balance - a.balance());
        }
        void operator ++ (int n) {
            Customer::balance(Customer::savings + Customer::checking);
        }
    

    the variables (savings and checking) are not declared in your class.

    here is an example of overloading operators:
    http://www.cprogramming.com/tutorial/operator_overloading.html
     
  15. Feb 15, 2010 at 7:34 PM
    #15
    fletch aka

    fletch aka www.BeLikeBrit.org

    Joined:
    Jan 4, 2009
    Member:
    #12223
    Messages:
    7,080
    Gender:
    Male
    First Name:
    Gary
    Left Coast
    Vehicle:
    09 Magnetic Gray TRD OffRoad
    TRD cat back exhaust, TRD Cold Air Intake, differential breather mod' Hellwig rear sway bar, 16x8 TRD Ivan Stewart's, Michelin LTX A/T2, DTRL Stealth Mode Mod, custom "Texas Edition" shift knob, Sock's "Classic" bedside decals, MetalMiller custom grill emblem, 20% front tinted windows, tinted taillights, Viper alarm, ScanGauge II, Flyzeye Designs V2W Tacoma Interior LED lighting, de-mud flapped, de-badged, extra D-rings under bed bolts, WeatherTech ED floor mats, G4 Elite Fold a Cover ,Toyota bed mat, tailgate theft deterrent device and absolutely no plasti-dip!
    :violent:
    :goingcrazy:
     
  16. Feb 15, 2010 at 8:03 PM
    #16
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    Changed my code and here it is!

    Code:
    #ifndef ACCOUNT_H
    #define ACCOUNT_H
    
    #include "Customer.h"
    
    //Account Class
    class Account {
    private:
            Customer myCustomer[2];
            string type;
            int number;
        double balance;
        double rate;
            double intrest;
            double NewBalance;
    
    public:
            Account(); // Constructor
            Account(string, int, double, double) ;
                    void setType(string);
                    void setNumber(int);
                    void setBalance(double);
                    void setRate(double);
    
                    string getType();
                    int getNumber();
                    double getBalance();
                    double getRate();
                    Customer& getCustomer ( int );
                    void valid_rate(double);
                    void ApplyInterest();
                    };       
    //-----------------------------------------------------------------------------
    //class definition
            Account::Account() {
                    type = " ";
                    number = 0;
                    balance = 0;
                    rate = 0;
            }
    
            Account::Account(string type, int number, double balance, double rate) {
                    Account::type = type;
                    Account::number = number;
                    Account::balance = balance;
                    valid_rate(rate);
                    }
    void Account::setType(string type) {
        Account::type = type;
    }
    
    void Account::setNumber(int number) {
        Account::number = number;
    }
    
    void Account::setBalance(double balance) {
        Account::balance = balance;
    }
    
    void Account::setRate(double rate) {
            valid_rate(rate);
    }
    
    string Account::getType() {
        return type;
    }
    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 <= .1)
                    Account::rate=rate;
            else {
                    Account::rate=0;
                    cout << "WARNING! You have entered an invalid rate!\n";
            }
    }
    
    void Account::ApplyInterest() {
                    intrest = rate * balance;
                    NewBalance = intrest + balance;
                    cout << "The amount of intrest for the Customer is: $" << intrest << " and the account balance is: $" << NewBalance << ".\n";
    }       
    
    
    Customer& Account::getCustomer(int n) {
            return myCustomer[n];
    }
    
        void operator += (Account& a) {
            a.setBalance(a.getBalance()+ a.getBalance());
        }
    
        void operator -= (Account& a) {
            a.setBalance(a.getBalance() - a.getBalance());
        }
    //MOST OF THE LEFT ERRORS ARE HERE--------------------------------------
        void operator ++ (int n, ) {
                    Customer::balance(Customer::savings + Customer::checking);
        }
    
    #endif
    
    1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
    1> Test1.cpp
    1>\account.h(97): error C2805: binary 'operator +=' has too few parameters
    1>\account.h(101): error C2805: binary 'operator -=' has too few parameters
    1>\account.h(105): error C2059: syntax error : ')'
    1>\account.h(105): error C2143: syntax error : missing ')' before '{'
    1>\account.h(105): error C2803: 'operator ++' must have at least one formal parameter of class type
    1>\account.h(106): error C2597: illegal reference to non-static member 'Customer::balance'
    1>\account.h(106): error C2597: illegal reference to non-static member 'Customer::savings'
    1>\account.h(106): error C3867: 'Customer::savings': function call missing argument list; use '&Customer::savings' to create a pointer to member
    1>\account.h(106): error C2597: illegal reference to non-static member 'Customer::checking'
    1>\account.h(106): error C3867: 'Customer::checking': function call missing argument list; use '&Customer::checking' to create a pointer to member
    1>\account.h(106): error C2568: '+' : unable to resolve function overload
    1> unable to recover from previous error(s); stopping compilation
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
     
  17. Feb 15, 2010 at 8:13 PM
    #17
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    I thought I had balance balance and checking and savings declared??
     
  18. Feb 15, 2010 at 8:14 PM
    #18
    tarheelfan_08

    tarheelfan_08 [OP] Carolina Alliance

    Joined:
    Jan 4, 2008
    Member:
    #4098
    Messages:
    2,944
    Gender:
    Male
    First Name:
    Justin
    North Carolina
    Vehicle:
    2010 White 4x4 Double Cab Tacoma Short Bed
    Chrome Grill, Chrome accessories(door handles and mirror covers), LEER Super White Cover, Mirrors with Turn Signals, Window Vent Visors, Step Rails, WeatherTech Digital Floor Mats, Mini Maglight Holder, Chrome Bull Bar
    And sorry if I am making stupid decisions and mistakes, but this program is due in 45 min and i got to have it done!
     
  19. Feb 15, 2010 at 8:23 PM
    #19
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    i dont see the variables checking or savings declared here:

    Code:
     
    //Account Class
    class Account {
    private:
            Customer myCustomer[2];
            string type;
            int number;
          double balance;
          double rate;
            double intrest;
            double NewBalance;
     
    ......
    ......
     
    };
    

    you also need to add these declarations to your public class definition:
    void operator += (Account&);
    void operator -= (Account&);
    void operator ++ (int);


    also take out the comma in the parameter list here:
    Code:
     
        void operator ++ (int n, ) {
                    Customer::balance(Customer::savings + Customer::checking);
        }
    
     
  20. Feb 15, 2010 at 8:24 PM
    #20
    NetMonkey

    NetMonkey Well-Known Member

    Joined:
    Aug 14, 2008
    Member:
    #8536
    Messages:
    1,734
    Gender:
    Male
    Geogetown, TX
    Vehicle:
    2010, 4x4, DC, off-road, shortbed, automatic
    Toytec Ultimate Lift @ 3", Mickey Thompson MTZ's 285/75/16, Moto Metal 955b, rear 2" ALL, Marlin Crawler sliders
    i think you may need to start your projects sooner and maybe seek help sooner :)
     

Products Discussed in

To Top