lost how to solve the question (class called invoice)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
using namespace std;
class Invoice
{
public:
Invoice (string, string, int ,int);
void setPartnumber (string)
string getPartnumber();
void setPartDescriotion (string);
string getPartDescription();
void setQuantity (int);
int getQuantity ();
void setPricePerItem();
int getInvoiceAmount ();
private:
string partNumber;
string partDescription;
int quantity;
int pricePerItem;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include "Invoice.h"
using namespace std;
Invoice::invoice(string number, string description,int count, int price)
{
setPartNumber(number);
setPartDescription(description);
setQuantity(count);
setPricePerItem(price);
}
void Invoice::setPartNumber(string number)
{
partNumber=number;
}
string Invoice::getPartNumber()
{
return partNumber;
}
void Invoice::setDescription(string description)
{
partDescription= description;
}
string Invoice::getPartDescription()
{
return partDescription;
}
void Invoice::setQuantity(int count)
{
if (count>0)
quantity=count;
if(count<=0)
{
quantity=0;
}
}
void Invoice::setPricePerItem(int price)
{
if(price>0)
pricePerItem=price;
if(price<=0)
{
pricePerItem=0
}
}
int Invoice::getPricePerItem()
{
return pricePerItem;
}
int Invoice::getInvoiceAmount()
{
return getQuantity()*getPricePerITem();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main()
{
Invoice invoice("4543","screwdriver",200,10);
cout<<"part number:"<<invoice.getPartNumber()<<endl;
cout<<"part Description:"<<invoice.getPartDescription()<<endl;
cout<<"quantity:"<<invoice.getQuantity()<<endl;
cout<<"price per item"<<invoice.getPricePerItem()<<endl;
cout<<"invoice amount:"<<invoice.getInvoiceAmount()<<endl;
invoice.setPartNumber("6543645");
invoice.setPartdescription("dsfs");
invoice.setQuantity(3);
invoice.setPricePerItem(10);
cout<<"part number:"<<invoice.getPartNumber()<<endl;
cout<<"part Description:"<<invoice.getPartDescription()<<endl;
cout<<"quantity:"<<invoice.getQuantity()<<endl;
cout<<"price per item"<<invoice.getPricePerItem()<<endl;
cout<<"invoice amount:"<<invoice.getInvoiceAmount()<<endl;
return 0;
}




[/code]
here is the question
a) 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 data
members—a part number (type string), a part description (type string), a
quantity of the item being purchased (type int) and a price per item (type
double). 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.
b) Write a test program that demonstrates class Invoice’s capabilities as follows:
i. Create two Invoice objects inv1 and inv2. Give suitable initial
values for the attributes of each object.
ii. Display the values of the attributes of each object.
iii. Display the invoice amount of each object.
iv. Set a 15 % increase in price per item for inv1 and a 20 % reduction in
price per item for inv2.
v. Display the invoice amount of each object.
Last edited on
Topic archived. No new replies allowed.