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