Knowledge
Knowledge
#include <iostream>
#include <string>
using namespace std;
class Invoice {
private:
string partNumber;
string partDescription;
int quantity;
int pricePerItem;
public:
Invoice(string pn, string pd, int q, int p) {
setPartNumber(pn);
setPartDescription(pd);
setQuantity(q);
setPricePerItem(p);
}
void setPartNumber(string pn) {
partNumber = pn;
}
void setPartDescription(string pd) {
partDescription = pd;
}
void setQuantity(int q) {
if (q > 0) {
quantity = q;
} else {
quantity = 0;
}
}
void setPricePerItem(int p) {
if (p > 0) {
pricePerItem = p;
} else {
pricePerItem = 0;
}
}
string getPartNumber() {
return partNumber;
}
std::string getPartDescription() {
return partDescription;
}
int getQuantity() {
return quantity;
}
int getPricePerItem() {
return pricePerItem;
}
int getInvoiceAmount() {
return quantity * pricePerItem;
}
};
int main() {
Invoice invoice("PN123", "Hammer", 2, 19.99);
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;
}