0% found this document useful (0 votes)
7 views

Knowledge

The document defines an Invoice class with private member variables for part number, description, quantity, and price. It includes public setter and getter methods for each member variable as well as a method to calculate the invoice amount by multiplying quantity and price. The main function creates an Invoice object and outputs its details to the console.

Uploaded by

pilixo7957
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Knowledge

The document defines an Invoice class with private member variables for part number, description, quantity, and price. It includes public setter and getter methods for each member variable as well as a method to calculate the invoice amount by multiplying quantity and price. The main function creates an Invoice object and outputs its details to the console.

Uploaded by

pilixo7957
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Task no 1 :

#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;
}

You might also like