C++ Assignment Errors

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#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


Here is the rest of the assignment


Account Header File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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
on accounts line 19 look at the end of the line: you have a { instead of a ;
this is throwing all the other errors I would think as the brace is opening a new scope.
Last edited on
Still getting the same errors! Even when I fix that!
What errors now? all of them?

accounts header on line 109 does not need to end with a }; just a } is fine also you should cut the #endif on line 110 and put it in 33 and , and opposite with Date header, you need a }; instead of a } on line31

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef  // #if not defined SOMECLASS_H
#define SOMECLASS_H

class SomeClass
{
    public: 
        SomeClass();
        SomeClass(string,int);
    private:
        int myVar;
        const static int someSize=5349182;

};   // <-- This is also important to end the header declaration.

#endif // end the declaration now we can do the implementation

SomeClass::SomeClass()
{
    // do nothing....
}
SomeClass::SomeClass(String somestring, int someint)
{
    stringS = somestring;
    intI = someint;
}
// etc .... 
Last edited on
Here is my errors and new code!

Errors

1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
1> Test1.cpp
1>\account.h(36): error C2535: 'Account::Account(void)' : member function already defined or declared
1> \account.h(18) : see declaration of 'Account::Account'
1>\account.h(43): error C2535: 'Account::Account(std::string,int,double,double)' : member function already defined or declared
1> \account.h(19) : see declaration of 'Account::Account'
1>\date.h(7): error C2236: unexpected 'class' 'Date'. Did you forget a ';'?
1>\date.h(7): error C2143: syntax error : missing ';' before '{'
1>\date.h(7): error C2447: '{' : missing function header (old-style formal list?)
1>\account.h(98): error C2064: term does not evaluate to a function taking 0 arguments
1>\account.h(102): error C2064: term does not evaluate to a function taking 0 arguments
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 ==========


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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();
	};
	#endif
//-----------------------------------------------------------------------------
//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);
    }


}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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 
you still haven't fixed the first error I told you about, either that or your copy/pasting and not editing properly.

line 19 of accounts get rid of the { and put a ;

and the dodgy indentation is still there.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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();
	};
	#endif 


should look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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();
};
#endif 
Last edited on
Ok I fixed it sorry!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#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();
	};
	#endif
//-----------------------------------------------------------------------------
//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);
    }


}


1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
1> Test1.cpp
1>\account.h(47): error C3861: 'valid_rate': identifier not found
1>\account.h(62): error C3861: 'valid_rate': identifier not found
1>\account.h(78): error C2039: 'valid_rate' : is not a member of 'Account'
1> \account.h(7) : see declaration of 'Account'
1>\account.h(80): error C2597: illegal reference to non-static member 'Account::rate'
1>\account.h(82): error C2597: illegal reference to non-static member 'Account::rate'
1>\account.h(87): error C2039: 'ApplyIntrest' : is not a member of 'Account'
1> \account.h(7) : see declaration of 'Account'
1>\account.h(88): error C2065: 'intrest' : undeclared identifier
1>\account.h(88): error C2065: 'rate' : undeclared identifier
1>\account.h(88): error C2065: 'balance' : undeclared identifier
1>\account.h(89): error C2065: 'NewBalance' : undeclared identifier
1>\account.h(89): error C2065: 'intrest' : undeclared identifier
1>\account.h(89): error C2065: 'balance' : undeclared identifier
1>\account.h(90): error C2065: 'intrest' : undeclared identifier
1>\account.h(90): error C2065: 'NewBalance' : undeclared identifier
1>\account.h(94): error C2065: 'myCustomer' : undeclared identifier
1>\account.h(97): error C2805: binary 'operator +=' has too few parameters
1>\account.h(98): error C2065: 'balance' : undeclared identifier
1>\account.h(98): 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(98): error C2064: term does not evaluate to a function taking 0 arguments
1>\account.h(98): error C3861: 'setBalance': identifier not found
1>\account.h(101): error C2805: binary 'operator -=' has too few parameters
1>\account.h(102): error C2065: 'balance' : undeclared identifier
1>\account.h(102): 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(102): error C2064: term does not evaluate to a function taking 0 arguments
1>\account.h(102): error C3861: 'setBalance': identifier not found
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 ==========



line 30: void valid_Rate(double);
line 47: valid_rate(rate);

watch your capitalization
Ok I fixed capitalization errors! And here is the new errors!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#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();
	};
	#endif
//-----------------------------------------------------------------------------
//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";
}	



    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);
    }

	Customer& operator [] (int n) {
	return myCustomer[n];
}



1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
1> Test1.cpp
1>\account.h(93): error C2801: 'operator []' must be a non-static member
1>\account.h(94): error C2065: 'myCustomer' : undeclared identifier
1>\account.h(97): error C2805: binary 'operator +=' has too few parameters
1>\account.h(98): error C2065: 'balance' : undeclared identifier
1>\account.h(98): 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(98): error C2064: term does not evaluate to a function taking 0 arguments
1>\account.h(98): error C3861: 'setBalance': identifier not found
1>\account.h(101): error C2805: binary 'operator -=' has too few parameters
1>\account.h(102): error C2065: 'balance' : undeclared identifier
1>\account.h(102): 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(102): error C2064: term does not evaluate to a function taking 0 arguments
1>\account.h(102): error C3861: 'setBalance': identifier not found
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 ==========


Changed my code and here it is!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#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 ==========


I changed some stuff and here is what I got Please help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#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();
                void operator += (Account&);
                void operator -= (Account&);
                void operator ++ (int);
                };      
//-----------------------------------------------------------------------------
//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 Account::operator += (Account& a) {
        a.setBalance(a.getBalance()+ a.getBalance());
    }
    void Account::operator -= (Account& a) {
        a.setBalance(a.getBalance() - a.getBalance());
    }

    void operator ++ (int n) {
           int temp_savings = Customer::getSavings();
           int temp_checking = Customer::getChecking();
           Account::setBalance(temp_savings  +  temp_checking);
        }

#endif 
1>------ Build started: Project: Test1, Configuration: Debug Win32 ------
1> Test1.cpp
1>\account.h(108): error C2803: 'operator ++' must have at least one formal parameter of class type
1>\account.h(109): error C2352: 'Customer::getSavings' : illegal call of non-static member function
1> \customer.h(40) : see declaration of 'Customer::getSavings'
1>\account.h(110): error C2352: 'Customer::getChecking' : illegal call of non-static member function
1> \customer.h(41) : see declaration of 'Customer::getChecking'
1>\account.h(111): error C2352: 'Account::setBalance' : illegal call of non-static member function
1> \account.h(23) : see declaration of 'Account::setBalance'
1>\date.h(32): fatal error C1070: mismatched #if/#endif pair in file '\date.h'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Anyone got any advice?
Only based on the error and the last few lines of code currently on my screen, I'd say that there's probably a missing Account:: on line 108, for one...

Yeah, operator++( int n ) should be a member, as mentioned above. Then, inside its definition any non-static methods will need to be called with an object not just the class name. The error messages are being very, very helpful.
Last edited on
Here is my current code:


Date.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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 


Customer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#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
    double savings;  // savings account balance
    double checking;  // checking account balance
    double 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(double);
    void setChecking(double);
        void setBalance(double);
        
        void operator +=( double );
        void operator -=( double );
        void operator ++ ();

    string getName();
    string getSSN();
    string getAddress();
    int getBirthDate();
    double getSavings();
    double getChecking();
    double 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(double savings) {
    Customer::savings = savings;
}

void Customer::setChecking(double checking) {
    Customer::checking = checking;
}

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



string Customer::getName() {
    return name;
}

string Customer::getSSN() {
    return ssn;
}

string Customer::getAddress() {
    return address;
}

int Customer::getBirthDate() {
    return birthDate;
}

double Customer::getSavings() {
    return savings;
}

double Customer::getChecking() {
    return checking;
}

double 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();
}
void Customer::operator += ( double dValue ) {
        setBalance( getBalance()+ dValue );
                //return this;
    }
void Customer::operator -= ( double dValue ) {
        setBalance( getBalance() - dValue );
                //return this;
    }

void Customer::operator ++ () {
       
      setBalance(getSavings()  +  getChecking());
 }

#endif


Account.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#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 
Last edited on

Test1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Account.h"
#include "Customer.h"
#include "Date.h"

using namespace std;

int main() {
    int tempInt;
    string tempString;
    Account myAccount, balance;


    for (int i = 0; i<2; i++) {
        cout << "Enter the Name of the Customer: ";
        cin >> tempString;
        myAccount.getCustomer(i).setName(tempString);

        cout << "Enter the Social Security Number of the Customer: ";
        cin >> tempString;
        myAccount.getCustomer(i).setSSN(tempString);

        cout << "Enter the Address of the Customer: ";
        Customer& myCust = myAccount.getCustomer(1);
        myCust.setAddress(tempString);

        cout << "Enter the Birth Date of the Customer: ";
        cin >> tempInt;
       myDate.setDate(tempString);

        cout << "Enter the Savings Account Balance of the Customer: ";
        cin >> tempInt;
       myAccount.getCustomer(i).setSavings(tempInt);

        cout << "Enter the Checking Account Balance of the Customer: ";
        cin >> tempInt;
       myAccount.getCustomer(i).setChecking(tempInt);

       cout << "Enter the Intrest Rate of the Customer: ";
        cin >> tempInt;
       myAccount.getRate(i).setRate(tempInt);





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

    //Reads the Customers
    for(int x=0; x<2; x++) {
        myAccount[x].displayCustomer();
    }

    //Reads the Customers
    for(int x=0; x<2; x++) {
        myAccount[x].ApplyIntrest();
    }


    //Reads the Customers
    for(int x=0; x<2; x++) {
        myAccount[x].displayCustomer();
    }


    return 0;
}


Errors:

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 ==========
Topic archived. No new replies allowed.