View previous topic :: View next topic |
Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Mar 13, 2011 9:50 pm Post subject: [C++] Composition help |
|
|
This is a bank customer class, which has a savingsAccount (class/object) as one of its data members. Anyways..
Code: |
#include <iostream>
#include <string>
using namespace std;
class SavingsAcc{
public:
SavingsAcc(double argBal = 0, double argInt = 0);
void setBalance(double);
double getBalance(void);
void setIntRate(double);
double getIntRate(void);
void monthlyInterest(void);
private:
double balance;
double intRate;
};
class Customer{
public:
Customer(string argName = "", double argID = 00000, SavingsAcc arg);
void setName(string);
string getName(void);
void setID(double);
double getID(void);
private:
string name;
double ID;
SavingsAcc savAcc;
};
int main(void){
int n;
cout << "How many bank customers would you like?";
cin >> n;
Customer *custArray = new Customer[n];
//Gonna do other shit with this later once I can get it to compile -_-
return(0);
}
// CUSTOMER CLASS IMPLEMENTATION
Customer::Customer(string argName, double argID, SavingsAcc arg){
setName(argName);
setID(argID);
savAcc = arg;
}
void Customer::setName(string argName){
name = argName;
}
string Customer::getName(void){
return name;
}
void Customer::setID(double argID){
ID = argID;
}
double Customer::getID(void){
return ID;
}
// SAVINGS ACCOUNT CLASS IMPLEMENATION
SavingsAcc::SavingsAcc(double argBalance, double argIntRate){
setBalance(argBalance);
setIntRate(argIntRate);
}
void SavingsAcc::setBalance(double argBalance){
if (argBalance < 0)
argBalance = 0;
balance = argBalance;
}
double SavingsAcc::getBalance(void){
return balance;
}
void SavingsAcc::setIntRate(double argIntRate){
if (argIntRate < 0)
argIntRate = 1;
intRate = argIntRate;
}
double SavingsAcc::getIntRate(void){
return intRate;
}
void SavingsAcc::monthlyInterest(void){
setBalance( getBalance()+(getBalance()*(getIntRate()/1200)));
cout << getBalance();
}
|
I'm having this error:
Quote: | 1>myfile.cpp(40): error C2548: 'Customer::Customer' : missing default parameter for parameter 3 |
How do I give it a default parameter beyond what I've already done..?
Kinda hit a wall as far as coming up with ideas to work around this..any help/tips would be greatly appreciated D:
_________________
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Sun Mar 13, 2011 10:00 pm Post subject: |
|
|
You're setting default params for this:
Code: | class Customer{
public:
Customer(string argName = "", double argID = 00000, SavingsAcc arg); |
Anything after the first time you set a default param has to be defaulted as well. Meaning SavingsAcc must be defaulted to something too, such as null in your case.
_________________
- Retired. |
|
Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Mar 13, 2011 10:25 pm Post subject: |
|
|
I sound dumber than I am asking this, but how do I accomplish that?
I dont know how to make the parameter have null values by default without sending it an object I make with null values.
_________________
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Sun Mar 13, 2011 10:46 pm Post subject: |
|
|
Just set the constructor to:
Code: |
Customer(string argName = "", double argID = 00000, SavingsAcc arg = NULL);
|
_________________
- Retired. |
|
Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Mar 13, 2011 11:13 pm Post subject: |
|
|
Wow, I feel pretty dumb now.
Thanks man, makes sense now. Thread over, basically. lol
_________________
|
|
Back to top |
|
 |
|