Hi, i'm one of those annoying students here to ask questions :)

this is what is asked for my assignment

(Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as data membersa part number (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type int). [Note: In subsequent chapters, we'll use numbers that contain decimal points (e.g., 2.75)called floating-point valuesto represent dollar amounts.] Your class should have a constructor that initializes the four data members. Provide a set and a get function for each data member. In addition, provide a member function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as an int value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates class Invoice's capabilities.

& here is what i have so far

#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;

class Invoice
{
      public:
             Invoice (string number, string desc, int amount, int price)
             {
                     set_partNumber (number);
                     set_partDescription (desc);
                     set_quantityPurchased (amount);
                     set_priceItem (price);
             }

             void set_partNumber (string number)
             {number = PN;}
             string get_partNumber()
             {return PN;}

             void set_partDescription (string desc)
             {desc = PD;}
             string get_partDescription()
             {return PD;}

             void set_quantityPurchased (int amount)
             {amount = QP;}
             int get_quantityPurchased()
             {return QP;}

             void set_priceItem (int price)
             {price = PI;}
             int get_priceItem()
             {return PI;}

             void get_invoiceAmount()
             {
                 if (QP < 0)
                 {QP = 0;}
                 if (PI < 0)
                 {PI = 0;}

                 int total = QP*PI;
                 cout << "Producto#: " << PN << "Descripcion: " << 
                 PD << "Cantidad: " << QP <<
                  "Precio: " << PI << "Su total: " << total << endl;
                 }

      private:
              int QP,PI;
              string PN,PD;
};

int main()
{
    Invoice invoice1 ("1", "motor", 1, 200);
    Invoice invoice2 ("2", "cucharas", 50, 3);

    invoice1.get_invoiceAmount();
    invoice2.get_invoiceAmount();

    system ("Pause");
    return 0;
}

do i have to use the get function to get the numbers from the user? (although it doesn't ask for it)
i got the program to run, but not how it's supposed to...i tried using the "get" function in the invoiceAmount function & that doesn't work. also is my constructor made properly?? these books really don't explain much & ask a lot from you. any help greatly appreciated...i thought i was understanding this thing but i'm not getting it at all

>>do i have to use the get function to get the numbers from the user?
No -- get functions return the value of private members to the calling function or class. For example get_invoiceAmount() should be an int function that returns the invoice amount (re-read your instructions on this). With your cryptic variable names I can't tell you how to calculate the invoice amount.

I think getting values from keyboard entry should be done in main(), outside the class.

You should add a default constructor (one with no parameters) and initialize all class variables to 0.

Hi, i'm one of those annoying students here to ask questions :)

Not as annoying as most new members. At least you used CODE tags, and have attempted to format your code. Good job!!! For additional formatting suggestions, see this. By the way, don't use both INLINECODE and CODE, just CODE

do i have to use the get function to get the numbers from the user? (although it doesn't ask for it)

Not necessarily. getline() makes more sense to me because of the way the get... functions work. Then convert the input to the value.


Also, about system ("Pause") , see this.

For example get_invoiceAmount() should be an int function that returns the invoice amount (re-read your instructions on this).

but get_invoiceAmount isn't returning anything...it's working like the displayMessage examples they give in the book
"int get_invoiceAmount" that's what i understand you are telling me to do, am i correct??

With your cryptic variable names I can't tell you how to calculate the invoice amount.

hmmm, i thought it was easy to see
PN - product number
PD - product description
QP - quantity purchased
PI - price of each item

so i have the QP*PI in my get_invoiceAMount, but my data members don't seem to be receiving what i send them in main when i create an object

You should add a default constructor (one with no parameters) and initialize all class variables to 0.

do you mean separating the interface & implementation? putting the constructor into it's own header file?

i'm going to try doing this from the start again cause now i'm getting even more errors lol
BBL

but get_invoiceAmount isn't returning anything...it's working like the displayMessage examples they give in the book

It's not supposed to work like displayMessage() -- read your instructions. displayMessage is not supposed to return anything, get_invoiceAmount() is

"int get_invoiceAmount" that's what i understand you are telling me to do, am i correct??

Yes that is right.

hmmm, i thought it was easy to see
PN - product number
PD - product description
QP - quantity purchased
PI - price of each item

Maybe to you because you wrote it.

so i have the QP*PI in my get_invoiceAMount, but my data members don't seem to be receiving what i send them in main when i create an object

you need to do something like this in main()

int invoiceAmount  = invoice1.get_invoiceAmount();

do you mean separating the interface & implementation? putting the constructor into it's own header file?

No, leave the class where it is an just add another constructor.

class Invoice
{
public:
    Invoice() {QP = 0; PI = 0;}
...
};

i'm going to try doing this from the start again cause now i'm getting even more errors lol
BBL

post code

sorry Ancient Dragon...i tried following your instructions, but couldn't quite get what you were trying to tell me to do. i've been racking my brain over this damn thing. no matter what i try to come up with i always end up with the same code, maybe cause it's my first time doing this class thing. i fixed it up a bit based on the suggestions here, this is what i have now

#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;

class Invoice
{
      public:
             Invoice (string number, string desc, int amount, int price)
             {
                     setPartNumber (number);
                     setPartDescription (desc);
                     setQuantityPurchased (amount);
                     setPriceItem (price);
             }
             
             void setPartNumber (string number)
             {number = product;}
             string getPartNumber()
             {return product;}
             
             void setPartDescription (string desc)
             {desc = description;}
             string getPartDescription()
             {return description;}
             
             void setQuantityPurchased (int amount)
             {if (amount < 0){
                 quantity = 0;
                 }
                 else {
                      amount = quantity;}}
             int getQuantityPurchased()
             {return quantity;}
             
             void setPriceItem (int price)
             {if (price < 0){
                 prices = 0;
                 }
                 else{
                      price = prices;}}
             int getPriceItem()
             {return prices;}
             
             int getInvoiceAmount()
             {
               int total = quantity * prices;
cout << "Producto#: " << getPartNumber() << "Descripcion: " << getPartDescription() << "\nCantidad: " << getQuantityPurchased() << "\nPrecio: " << getPriceItem() << "\nSu total: " << total << endl;
             }
                  
      private:
              int quantity;
              int prices;
              string product;
              string description;
              
              
};


int main()
{
    Invoice invoice1 ("1", "motor", 2, 200);
    Invoice invoice2 ("2", "cucharas", 50, 3);
    
    invoice1.getInvoiceAmount();
    invoice2.getInvoiceAmount();
    //int invoiceAmount  = invoice1.getInvoiceAmount();
    
    
    cin.get();
    return 0;
}

it still doesn't return anything for my string functions & the int functions return weird numbers...i'm all out of ideas

i solved it!!
everything was right from the start cept that i was assigning the values wrong

void setPartNumber (string number)
{number = product;}
string getPartNumber()
{return product;}

number = product is wrong,it should be:
product = number

:D

you bet i was smacking my forehead when i noticed

i solved it!!
everything was right from the start cept that i was assigning the values wrong


number = product is wrong,it should be:
product = number

:D

you bet i was smacking my forehead when i noticed

Happens to all of us. :)

may i know the final code for this one?

commented: 3 years too late the OP is probably long gone -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.