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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
// #ifndef CLASS_INVOICE_HPP
// #define CLASS_INVOICE_HPP
#include <iostream>
#include <string>
// Create a class called Invoice that a hardware store might use to represent
// an invoice for an item sold at the store.
// --> done
class Invoice {
public:
// Your class should have a constructor that initializes the 6 data members.
// --> done
Invoice(std::string part_number,
std::string part_description,
int purchased_quantity,
int item_price,
double tax_rate,
double discount_rate);
// Provide a set and get functions for each data member.
// --> done
void setNumber(std::string partNumber);
std::string getNumber() const;
void setDescription(const std::string& partDescription);
std::string getDescription() const;
void setQuantity(int purchasedQuantity);
int getQuantity() const;
void setPrice(int itemPrice);
int getPrice() const;
double getTrate() const;
double getDrate() const;
void setInvoiceAmount(double iamount);
double getInvoiceAmount() const;
private:
// An invoice should include 6 data members
// 1) a part number (type string), part
// 2) description (type string),
// 3) a quantity of the item beeing purchased (type int),
// 4) a price per item (type int)
// 5) a value-added tax (VAT) rate as a decimal (type double)
// 6) and discount rate as decimal (type double)
// --> done
std::string number; // 1)
std::string description; // 2)
int quantity; // 3)
int price; // 4)
double trate { 0.20 }; // 5)
double drate { 0 }; // 6)
};
// #endif // CLASS_INVOICE_HPP
// The constructor should initialise a) the first four data members with values
// frpm parameters and b) the last two data members to default values of 0.20
// per cent and zero respectively.
// a) --> YET TO BE DONE !!
// b) --> done (but not the way it has been requested)
Invoice::Invoice(std::string part_number,
std::string part_description,
int purchased_quantity,
int item_price,
double tax_rate,
double discount_rate)
: number { part_number }
// something is missing here!!
{
if (tax_rate > 0) {
trate = tax_rate;
}
if (discount_rate > 0) {
drate = discount_rate;
}
}
// Have the set data members perform validity checks on their parameters - if
// value is not positive it should be left unchanged.
// --> YET TO BE DONE !!
void Invoice::setNumber(std::string partNumber) // --> YET TO BE DONE !!
{
number = partNumber;
}
std::string Invoice::getNumber() const
{
return number;
}
void Invoice::setDescription(const std::string& partDescription) // --> YET TO BE DONE !!
{
description = partDescription;
}
std::string Invoice::getDescription() const
{
return description;
}
void Invoice::setQuantity(int purchasedQuantity) // --> YET TO BE DONE !!
{
quantity = purchasedQuantity;
}
int Invoice::getQuantity() const
{
return quantity;
}
void Invoice::setPrice(int itemPrice)// --> YET TO BE DONE !!
{
price = itemPrice;
}
int Invoice::getPrice() const
{
return price;
}
double Invoice::getTrate() const
{
return trate;
}
double Invoice::getDrate() const
{
return drate;
}
void Invoice::setInvoiceAmount(double iamount)
{
iamount = ((quantity*price)*trate) + (quantity*price - drate);
}
// In addition provide a member function named getInvoiceAmount that calculates
// the invoice amount (i.e multiples the quantity by the price per item and
// applies the tax and discounts amouns) then returns the amount.
// --> YET TO BE DONE!!
double Invoice::getInvoiceAmount() const
{
return iamount;
}
// Write a driver program to demonstrate Invoice's capabilities
// YET TO BE DONE!!
int main()
{
// std::string number;
// std::string description;
// int quantity;
// int price;
// double trate { 0.20 };
// double drate { 0 };
Invoice invoice1 { "NO134 56", "PCIe SSD", 3, 130, 0.50, 0 };
std::cout << "Purchased part number: " << invoice1.getNumber()
<< "; description: " << invoice1.getDescription()
<< "; quantity: " << invoice1.getQuantity()
<< "; price per item: " << invoice1.getPrice()
<< "; tax VAT: " << invoice1.getTrate()
<< "; discount rate: " << invoice1.getDrate();
std::cout << "\nThe invoice amount is: " << invoice1.getInvoiceAmount() << '\n';
}
| |