"Alf P. Steinbach" <alfps@start.no> wrote:
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).
struct you show is not correct. His class could be re-implemented to