d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Question
12Next
Add Reply New Topic New Poll
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Nov 11 2012 06:11pm
Hello I'm currently working on a project and it has to do with classes and I'm having a problem

Its variables are

private:
int pizza
int hotdogs
double cost
double totalfoodcost

now say

I have a constructor that sets them all to zero

now I have an overloaded construstor, BUT this constructor is suppose to read the pizza cost and hotdogs in that order

I'm running into the problem that its written int int double double

but

in the overloaded im suppose to read it int double int

It says that I'm suppose to "copy these values to the appropriate member variables"

I don't understand how to read it 1 3 2 if its read in 1 2 3

Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 11 2012 06:30pm
Quote (SlayingWhileInt0xicated @ Nov 11 2012 08:11pm)
Hello I'm currently working on a project and it has to do with classes and I'm having a problem

Its variables are

private:
int pizza
int hotdogs
double cost
double totalfoodcost

now say

I have a constructor that sets them all to zero

now I have an overloaded construstor, BUT this constructor is suppose to read the pizza cost and hotdogs in that order

I'm running into the problem that its written int int double double

but

in the overloaded im suppose to read it int double int

It says that I'm suppose to "copy these values to the appropriate member variables"

I don't understand how to read it 1 3 2 if its read in 1  2 3


can you post the exact wording of your assignment? i think you're misinterpretting it.
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Nov 11 2012 07:07pm
Quote (carteblanche @ Nov 11 2012 07:30pm)
can you post the exact wording of your assignment? i think you're misinterpretting it.


pm'd
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 11 2012 07:08pm
Quote (SlayingWhileInt0xicated @ Nov 11 2012 09:07pm)
pm'd


i dont help via pm, sorry.
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Nov 11 2012 07:17pm
Quote (carteblanche @ Nov 11 2012 08:08pm)
i dont help via pm, sorry.


-_-
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Nov 11 2012 08:29pm

inventoryclient.cpp:56: error: no matching function for call to 'Inventory::setTotalCost()'
inventory.h:30: note: candidates are: void Inventory::setTotalCost(int, double)

anyone know how to get rid of these errors?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 11 2012 08:31pm
Quote (SlayingWhileInt0xicated @ Nov 11 2012 10:29pm)
inventoryclient.cpp:56: error: no matching function for call to 'Inventory::setTotalCost()'
inventory.h:30: note: candidates are: void Inventory::setTotalCost(int, double)

anyone know how to get rid of these errors?


looks like you have a function of 2 parameters and you're not passing any arguments. to fix it, pass two arguments, remove the params, or overload it.
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
Nov 11 2012 08:41pm
My H File

Code
class Inventory
{
private:
int itemNumber;  //Holds the item's item number
int quantity;  //Holds the quantity of the items
double cost;  //Holds the wholesale per-unit cost of the item
double totalCost; //Holds the total inventory cost ( quantity * cost )

public:
//Constructors
Inventory();
Inventory(int inum, int quant, double price);

//Mutators
void setItemNumber(int inum);
void setQuantity(int quant);
void setCost(double price);
void setTotalCost(int quant, double price);

//Accessors
int getItemNumber()
{
 return itemNumber;
}
int getQuantity()
{
 return quantity;
}
double getCost()
{
 return cost;
}
double getTotalCost()
{
 return totalCost;
}
};



My Cpp File

Code
//Sets all the memnber variables to 0
Inventory::Inventory()
{
itemNumber = 0;
quantity = 0;
cost = 0;
totalCost = 0;
}

//Accepts an item's number, cost, and quantity as arguments. The function
//should copy these values to the appropriate member variables and then call
//the setTtotalCost function.
Inventory::Inventory( int inum, int quant, double price )
{
itemNumber = inum;
quantity = quant;
cost = price;
setTotalCost(quant, price);
}

//Accepts an integer argument that is copied to the itemNumber memeber variable
void Inventory::setItemNumber(int inum)
{
if ( inum >= 0 )
 itemNumber = inum;
else
 itemNumber = 0;
}

//Accepts an integer argument that is copied to the quantity member variable.
void Inventory::setQuantity(int quant)
{
if ( quant >= 0 )
 quantity = quant;
else
 quantity = 0;
}

//Accepts a double argument that is copied to the cost member variable
void Inventory::setCost(double price)
{
if ( price >= 0 )
 cost = price;
else
 cost = 0;
}

//Calculates the total inventory cost for the item (quantity * cost) and
//stores the result in totalCost
void Inventory::setTotalCost(int quant, double price)
{
totalCost = quant * price;
}




My Errors

inventoryclient.cpp:40: error: no matching function for call to 'Inventory::setTotalCost()'
inventory.h:30: note: candidates are: void Inventory::setTotalCost(int, double)
inventoryclient.cpp:56: error: no matching function for call to 'Inventory::setTotalCost()'
inventory.h:30: note: candidates are: void Inventory::setTotalCost(int, double)

This post was edited by SlayingWhileInt0xicated on Nov 11 2012 08:54pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 11 2012 08:52pm
did you read what carter posted? the problem is obvious
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 11 2012 08:53pm
i assume the line numbers are 40 and 56? please bold the lines. i assume it's called twice, but i only see the function called once and it has both args. though im not sure why it's a setter in the first place. sounds like it should be a getter

This post was edited by carteblanche on Nov 11 2012 08:55pm
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll