By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

Assistance using classes

P: n/a
I am stuck on an assignment that uses classes and functions. I am receiving
numerous errors when I try to run a test program to see if I wrote it
correctly. Can someone please point me in the right direction. These are two
of the error messages I am receiving.

error C2660: 'Invoice::setPartNumber' : function does not take 1 arguments

error C3861: 'setItemQuantity': identifier not found

This is the code. Thsnks in advance

#include <string// class Invoice uses C++ standard string class
using std::string;

// Invoice class definition
class Invoice
{
public:
Invoice( string, string, int, int ); // initializing constructors
void setPartNumber(); // function that sets the part number
string getPartNumber(); // function that gets the part number
void setPartDescription(); // function that sets the part description
string getPartDescription(); // function that gets the part description
void setQuantity(); // function that sets the quantity
int getQuantity(); // function that gets the quantity
void setPrice(); // function that sets the price
int getPrice(); // function that gets the price
int getInvoiceAmount(); // function that calculates the invoice amount
private:
string number;
string description;
int quantity;
int price;
}; // end class Invoice

// Invoice member-function definitions. This file contains
// implementations of the member functions prototyped in 313.h.
#include <iostream>
using std::cout;
using std::endl;

#include "313.h" // include definition of class Invoice

// initializing constructors
Invoice::Invoice( string number, string description, int quantity, int
price )
{
setPartNumber( number ); // call set function to initialize partNumber
setPartDescription( description ); // call set function to initialize
partDescription
setItemQuantity( quantity ); // call set function to initialize quantity
setItemPrice( price ); // call set function to initialize price
} // end Invoice constructors

// function to set the part number
void setPartNumber( string number )
{
partNumber = number; // store the part number in the object
} // end function setPartNumber

// function to get the part number
string getPartNumber()
{
return partNumber; // return object's partNumber
} // end function getPartNumber

// function to set the part description
void setPartDescription( string description )
{
partDescription = description; // store the part description in the
object
} // end function setPartDescription

// function to get the part description
string getPartDescripton()
{
return partDescription; // return object's partDescription
} // end function getPartDescription

// function to set the quantity
void setQuantity( int quantity )
{
itemQuantity = quantity; // store the quantity in the object
} // end function setItemQuantity

// function to get the quantity
int getItemQuantity()
{
return itemQuantity; // return object's Quantity
} // end function getItemQuantity

// function to set the price
void setPrice( int price )
{
itemPrice = price; // store the price in the object
} // end function setItemPrice

// function to get the price
int getItemPrice()
{
return itemPrice; // return object's Price
} // end function getItemPrice

// member function that calculates the invoice amount
int getInvoiceAmount(int quantity, int price)
{
if (quantity < 0)
quantity = 0;
if (price < 0)
price = 0;

InvoiceAmount = (quantity*price);
return InvoiceAmount;

} // end function getInvoiceAmount

// invoice.cpp
// Including class Invoice from 313.h for use in main.
#include <iostream>
using std::cout;
using std::endl;

#include "313.h" // include definition of class Invoice

// function main begins program execution
int main()
{
// create Invoice object
Invoice invoice1( "110-2145", "Chainsaw", 4, 12 );

// display initial value of courseName for each GradeBook

invoice1.getInvoiceAmount();
cout << endl;
return 0; // indicate successful termination
} // end main

Jul 2 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a
B Williams posted:

void setPartNumber(); // function that sets the part number

Stare at that line for twenty seconds.

part description void setQuantity(); // function that sets the

Stare at that line for twenty seconds.
The error messages were self-explanatory.

--

Frederick Gotham
Jul 2 '06 #2

P: n/a
* B Williams:
I am stuck on an assignment that uses classes and functions. I am receiving
numerous errors when I try to run a test program to see if I wrote it
correctly. Can someone please point me in the right direction. These are two
of the error messages I am receiving.

error C2660: 'Invoice::setPartNumber' : function does not take 1 arguments
This means you're calling Invoice::setPartNumber with an argument, but
the function either takes no arguments, or more than one.

error C3861: 'setItemQuantity': identifier not found
This means there's no such function.

This is the code. Thsnks in advance

#include <string// class Invoice uses C++ standard string class
using std::string;

// Invoice class definition
class Invoice
{
public:
Invoice( string, string, int, int ); // initializing constructors
void setPartNumber(); // function that sets the part number
string getPartNumber(); // function that gets the part number
void setPartDescription(); // function that sets the part description
string getPartDescription(); // function that gets the part description
void setQuantity(); // function that sets the quantity
int getQuantity(); // function that gets the quantity
void setPrice(); // function that sets the price
int getPrice(); // function that gets the price
int getInvoiceAmount(); // function that calculates the invoice amount
private:
string number;
string description;
int quantity;
int price;
}; // end class Invoice
This is technically a class, but the only C++ class feature it uses to
advantage is the constructor.

The rest, with setters and getters, is, with one exception, and assuming
you fix the lack of arguments in your setter functions, effectively as
if you'd just done:

struct Invoice
{
Invoice( string, string, int, int );
string number;
string description;
int quantity;
int price;
};

The exception is that simpler version allows referring to data in a
'const' object, whereas your more complicated version doesn't allow that.

At this stage in your education I recommend using the simpler version,
so as not being deluded that the code represents anything class-like:
it's just a collection of data with an initialization helper (the
constructor).

// Invoice member-function definitions. This file contains
// implementations of the member functions prototyped in 313.h.
#include <iostream>
using std::cout;
using std::endl;

#include "313.h" // include definition of class Invoice

// initializing constructors
Invoice::Invoice( string number, string description, int quantity, int
price )
{
setPartNumber( number ); // call set function to initialize partNumber
Here you're providing an argument but the function was declared with no
argument.

setPartDescription( description ); // call set function to initialize
partDescription
setItemQuantity( quantity ); // call set function to initialize quantity
setItemPrice( price ); // call set function to initialize price
} // end Invoice constructors
Read up on initialization lists and use them.
// function to set the part number
void setPartNumber( string number )
{
partNumber = number; // store the part number in the object
} // end function setPartNumber
This is a free-standing function, not a member function: it's not
related to the class and shouldn't compile since it refers to a
non-existent global 'partNumber'.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 2 '06 #3

P: n/a

"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:sd*******************@news.indigo.ie...
>B Williams posted:

> void setPartNumber(); // function that sets the part number


Stare at that line for twenty seconds.

> part description void setQuantity(); // function that sets the


Stare at that line for twenty seconds.
The error messages were self-explanatory.

--

Frederick Gotham
Thank you very much. I have corrected those errors. Now the error I am
having is with the actual function. I have modified it as such.

from 311.h
int getInvoiceAmount(int, int); // function that calculates the invoice
amount"

from 311.cpp
// member function that calculates the invoice amount
int Invoice::getInvoiceAmount(int quantity, int price)
{
int InvoiceAmount = 0;

if (quantity < 0)
quantity = 0;
if (price < 0)
price = 0;

InvoiceAmount = (quantity*price);
return InvoiceAmount;

} // end function getInvoiceAmount

from invoice.cpp
int main()
{
// create Invoice object
Invoice invoice1( "110-2145", "Chainsaw", 4, 12 );

// display invoice

invoice1.getInvoiceAmount();
cout << endl;
error C2660: 'Invoice::getInvoiceAmount' : function does not take 0
arguments

Where am I going wrong?



Jul 2 '06 #4

P: n/a
In article <4g*************@individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
This is the code. Thsnks in advance

#include <string// class Invoice uses C++ standard string class
using std::string;

// Invoice class definition
class Invoice
{
public:
Invoice( string, string, int, int ); // initializing constructors
void setPartNumber(); // function that sets the part number
string getPartNumber(); // function that gets the part number
void setPartDescription(); // function that sets the part description
string getPartDescription(); // function that gets the part description
void setQuantity(); // function that sets the quantity
int getQuantity(); // function that gets the quantity
void setPrice(); // function that sets the price
int getPrice(); // function that gets the price
int getInvoiceAmount(); // function that calculates the invoice amount
private:
string number;
string description;
int quantity;
int price;
}; // end class Invoice

This is technically a class, but the only C++ class feature it uses to
advantage is the constructor.

The rest, with setters and getters, is, with one exception, and assuming
you fix the lack of arguments in your setter functions, effectively as
if you'd just done:

struct Invoice
{
Invoice( string, string, int, int );
string number;
string description;
int quantity;
int price;
};

The exception is that simpler version allows referring to data in a
'const' object, whereas your more complicated version doesn't allow that.

At this stage in your education I recommend using the simpler version,
so as not being deluded that the code represents anything class-like:
it's just a collection of data with an initialization helper (the
constructor).
Although the merit of his class may be at question, equating it with the
struct you show is not correct. His class could be re-implemented to
store all data in a database without any other code needing to be
changed for example, while your struct doesn't have that property.
Jul 2 '06 #5

P: n/a
* Daniel T.:
In article <4g*************@individual.net>,
"Alf P. Steinbach" <al***@start.nowrote:
>>This is the code. Thsnks in advance

#include <string// class Invoice uses C++ standard string class
using std::string;

// Invoice class definition
class Invoice
{
public:
Invoice( string, string, int, int ); // initializing constructors
void setPartNumber(); // function that sets the part number
string getPartNumber(); // function that gets the part number
void setPartDescription(); // function that sets the part description
string getPartDescription(); // function that gets the part description
void setQuantity(); // function that sets the quantity
int getQuantity(); // function that gets the quantity
void setPrice(); // function that sets the price
int getPrice(); // function that gets the price
int getInvoiceAmount(); // function that calculates the invoice amount
private:
string number;
string description;
int quantity;
int price;
}; // end class Invoice
This is technically a class, but the only C++ class feature it uses to
advantage is the constructor.

The rest, with setters and getters, is, with one exception, and assuming
you fix the lack of arguments in your setter functions, effectively as
if you'd just done:

struct Invoice
{
Invoice( string, string, int, int );
string number;
string description;
int quantity;
int price;
};

The exception is that simpler version allows referring to data in a
'const' object, whereas your more complicated version doesn't allow that.

At this stage in your education I recommend using the simpler version,
so as not being deluded that the code represents anything class-like:
it's just a collection of data with an initialization helper (the
constructor).

Although the merit of his class may be at question, equating it with the
struct you show is not correct.
It is correct, in the context indicated.

His class could be re-implemented to
store all data in a database without any other code needing to be
changed for example, while your struct doesn't have that property.
Yes, that's possible in some /other/ context, such as an experienced
programmer; however, when even the syntax is a problem, the likelihood
of a database backend being added is negligible, and the machinery that
allows is that is only an impediment.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 2 '06 #6

P: n/a
In article <wPTpg.58620$9c6.24642@dukeread11>,
"B Williams" <wi*******@hotmail.comwrote:
"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:sd*******************@news.indigo.ie...
B Williams posted:

void setPartNumber(); // function that sets the part number

Stare at that line for twenty seconds.

part description void setQuantity(); // function that sets the

Stare at that line for twenty seconds.
The error messages were self-explanatory.

--

Frederick Gotham

Thank you very much. I have corrected those errors. Now the error I am
having is with the actual function. I have modified it as such.

from 311.h
int getInvoiceAmount(int, int); // function that calculates the invoice
amount"

from 311.cpp
// member function that calculates the invoice amount
int Invoice::getInvoiceAmount(int quantity, int price)
{
int InvoiceAmount = 0;

if (quantity < 0)
quantity = 0;
if (price < 0)
price = 0;

InvoiceAmount = (quantity*price);
return InvoiceAmount;

} // end function getInvoiceAmount

from invoice.cpp
int main()
{
// create Invoice object
Invoice invoice1( "110-2145", "Chainsaw", 4, 12 );

// display invoice

invoice1.getInvoiceAmount();
cout << endl;
error C2660: 'Invoice::getInvoiceAmount' : function does not take 0
arguments

Where am I going wrong?
An 'argument' here means the value or values passed to a function
through its argument list. Here is an example:

void foo(); // takes 0 arguments
void foo(int a); // takes 1 argument
void foo(int a, int b); // takes 2 arguments

Now that you know that what do you think the error means?
Jul 2 '06 #7

P: n/a

"Daniel T." <da******@earthlink.netwrote in message
news:da****************************@news.west.eart hlink.net...
In article <wPTpg.58620$9c6.24642@dukeread11>,
"B Williams" <wi*******@hotmail.comwrote:
>"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:sd*******************@news.indigo.ie...
>B Williams posted:
void setPartNumber(); // function that sets the part number
Stare at that line for twenty seconds.
part description void setQuantity(); // function that sets the
Stare at that line for twenty seconds.
The error messages were self-explanatory.

--

Frederick Gotham

Thank you very much. I have corrected those errors. Now the error I am
having is with the actual function. I have modified it as such.

from 311.h
int getInvoiceAmount(int, int); // function that calculates the invoice
amount"

from 311.cpp
// member function that calculates the invoice amount
int Invoice::getInvoiceAmount(int quantity, int price)
{
int InvoiceAmount = 0;

if (quantity < 0)
quantity = 0;
if (price < 0)
price = 0;

InvoiceAmount = (quantity*price);
return InvoiceAmount;

} // end function getInvoiceAmount

from invoice.cpp
int main()
{
// create Invoice object
Invoice invoice1( "110-2145", "Chainsaw", 4, 12 );

// display invoice

invoice1.getInvoiceAmount();
cout << endl;
error C2660: 'Invoice::getInvoiceAmount' : function does not take 0
arguments

Where am I going wrong?

An 'argument' here means the value or values passed to a function
through its argument list. Here is an example:

void foo(); // takes 0 arguments
void foo(int a); // takes 1 argument
void foo(int a, int b); // takes 2 arguments

Now that you know that what do you think the error means?
This is becoming a little more clear now. I know what the error means. the
function I wrote should take two arguments. I tried to use (int price, int
quantity) as my arguments but I get syntax errors. I am going to flip back
through the functions chapter to see why my function is formatted correctly.
Jul 2 '06 #8

P: n/a
B Williams posted:

>> invoice1.getInvoiceAmount();

Stare at that line for twenty seconds.
--

Frederick Gotham
Jul 2 '06 #9

P: n/a

"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:Xq*******************@news.indigo.ie...
>B Williams posted:

>>> invoice1.getInvoiceAmount();


Stare at that line for twenty seconds.
--

Frederick Gotham
I'm afraid it didn't work this time. What I am attempting to do is have the
function called and the result (InvoiceAmount) displayed when I cout, but I
don't understand how to do it.
Jul 2 '06 #10

P: n/a
B Williams posted:

I'm afraid it didn't work this time. What I am attempting to do is
have the function called and the result (InvoiceAmount) displayed when
I cout, but I don't understand how to do it.

Change:

invoice1.getInvoiceAmount();
to:

invoice1.getInvoiceAmount(first_argument, second_argument);
You're consistently making the mistake of calling functions and supplying
them with the wrong number of arguments.

You'll break that habit soon enough.
--

Frederick Gotham
Jul 2 '06 #11

P: n/a

"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:LL*******************@news.indigo.ie...
>B Williams posted:

>I'm afraid it didn't work this time. What I am attempting to do is
have the function called and the result (InvoiceAmount) displayed when
I cout, but I don't understand how to do it.


Change:

invoice1.getInvoiceAmount();
to:

invoice1.getInvoiceAmount(first_argument, second_argument);
You're consistently making the mistake of calling functions and supplying
them with the wrong number of arguments.

You'll break that habit soon enough.
--

Frederick Gotham
Frederick,
You have been a tremendous help. I have the code working except when I
attempt to print out the invoice amount. This is what I have come up with.
Can you assist me with the line that I am receiving the error with.

from 313.h
int getInvoiceAmount(int, int); // function that calculates the invoice
amount
void displayMessage(); // function that displays a message

from 313.cpp
// member function that calculates the invoice amount
int Invoice::getInvoiceAmount(int quantity, int price)
{
int InvoiceAmount = 0;

if (quantity < 0)
quantity = 0;
if (price < 0)
price = 0;

InvoiceAmount = (quantity*price);
return InvoiceAmount;

} // end function getInvoiceAmount
void Invoice::displayMessage()
{

cout << "The item number is: " << getPartNumber()
<< endl;
cout << "This item is a: " << getPartDescription()
<< endl;
cout << "The quantity purchased is: " << getItemQuantity()
<< endl;
cout << "The price is: $" << getItemPrice()
<< endl;
cout << "The invoice amount is: $" << getInvoiceAmount(InvoiceAmount)
<<-- this is where I have a problem
<< endl;
} // end function displayMessage

from invoice.cpp
int main()
{
// create Invoice object
Invoice invoice1( "110-2145", "Chainsaw", 4, 12 );

// display invoice

invoice1.displayMessage();
cout << endl;
Jul 2 '06 #12

P: n/a
B Williams posted:

cout << "The invoice amount is: $" << getInvoiceAmount
(InvoiceAmount)
><<-- this is where I have a problem
<< endl;

Exactly the same error again.

Your compiler has been giving you intelligible errors, worded akin to the
following:

Function does not have 1 parameter.

If you ever get such an error, then it means you're calling a function
and have supplied it with the wrong number of arguments.

This is the last time I shall respond to a post from you which
contains an error pertaining to calling a function and supplying it with
the wrong number of arguments, as I am beginning to suspect that you are
trolling. My suspicion is based upon:

(1) Extensive repitition of the same error, which has been corrected
for you by others several times. You should be able to cop it yourself by
now.
(2) Intelligible compiler errors which explain in plain English where
your problem is.
--

Frederick Gotham
Jul 2 '06 #13

P: n/a

"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:Jp*******************@news.indigo.ie...
>B Williams posted:

> cout << "The invoice amount is: $" << getInvoiceAmount
(InvoiceAmount)
>><<-- this is where I have a problem
<< endl;


Exactly the same error again.

Your compiler has been giving you intelligible errors, worded akin to the
following:

Function does not have 1 parameter.

If you ever get such an error, then it means you're calling a function
and have supplied it with the wrong number of arguments.

This is the last time I shall respond to a post from you which
contains an error pertaining to calling a function and supplying it with
the wrong number of arguments, as I am beginning to suspect that you are
trolling. My suspicion is based upon:

(1) Extensive repitition of the same error, which has been corrected
for you by others several times. You should be able to cop it yourself by
now.
(2) Intelligible compiler errors which explain in plain English where
your problem is.
--

Frederick Gotham
I don't think I was asking the correct question. I understand the error and
I know I can fix it by simply adding 2 arguments like
getInvoiceAmount(4,12). My question is that I already have assigned quantity
to 4 and price to 12 in this part of the code.

Invoice invoice1( "110-2145", "Chainsaw", 4, 12 );

I want to be able to pull those figures into my function. When I simply type
quantity or price, it doesn't work.

I don't know what Trolling is. I am taking an online programming course thus
I don't have an instructor available to answer questions for me as often or
as quickly as I would like. This is only my first week in this class and
only my second programming class I've attempted. A few other students where
having problems and suggested that we try the newsgroups. You guys have been
tremendously helpful and I appreciate it very much. I don't expect the
answers because that would be cheating and it wouldn't afford me the
opportunity to learn. I ask for help because looking at this code is still
like looking at French for me. I can understand some of it, but I need to
have alot of things translated. Thanks again for your help.
Jul 2 '06 #14

P: n/a

"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:Jp*******************@news.indigo.ie...
>B Williams posted:

> cout << "The invoice amount is: $" << getInvoiceAmount
(InvoiceAmount)
>><<-- this is where I have a problem
<< endl;


Exactly the same error again.

Your compiler has been giving you intelligible errors, worded akin to the
following:

Function does not have 1 parameter.

If you ever get such an error, then it means you're calling a function
and have supplied it with the wrong number of arguments.

This is the last time I shall respond to a post from you which
contains an error pertaining to calling a function and supplying it with
the wrong number of arguments, as I am beginning to suspect that you are
trolling. My suspicion is based upon:

(1) Extensive repitition of the same error, which has been corrected
for you by others several times. You should be able to cop it yourself by
now.
(2) Intelligible compiler errors which explain in plain English where
your problem is.
--

Frederick Gotham
Frederick,
Your line of questioning was very helpful. I figured out what my problem
was. I mistakenly thought that I had to have 2 argument in my function since
I was manipulating the quantity and price, even though I was only looking
for one answer so I removed the arguments and it works. I feel as though I
have accomplished something today. here is my correct code.

from 313.h
int getInvoiceAmount(); // function that calculates the invoice amount

from 313.cpp
// member function that calculates the invoice amount
int Invoice::getInvoiceAmount()
{
int invoiceAmount = 0;
int quantity = itemQuantity;
int price = itemPrice;

if (quantity < 0)
quantity = 0;
if (price < 0)
price = 0;

invoiceAmount = (quantity*price);
return invoiceAmount;

} // end function getInvoiceAmount

void Invoice::displayMessage()
{

cout << "The item number is: " << getPartNumber()
<< endl;
cout << "This item is a: " << getPartDescription()
<< endl;
cout << "The quantity purchased is: " << getItemQuantity()
<< endl;
cout << "The price is: $" << getItemPrice()
<< endl;
cout << "The amount of this invoice is: $" << getInvoiceAmount()
<< endl;

from invoice.cpp
int main()
{
// create Invoice object
Invoice invoice1( "110-2145", "Chainsaw", 4, 12 );

// display invoice

invoice1.displayMessage();
cout << endl;
Jul 2 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.