I am trying to write a program but it is not working. I am a beginner :)
Thank you for your help :)
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 6 data members a part number (type string), part description
(type string), a quantity of the item beeing purchased (type int), a
price per item (type int) a value-added tax (VAT) rate as a decimal
(type double) and discount rate as decimal (type double) Your class
should have a constructor that initializes the 6 data members. The
constructor should initialise the first four data members with values
frpm parameters and the last two data members to default values of 0.20
per cent and zero respectively. Provide a set and get functions for each
data member. 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. Have the set data members perform validity
checks on their parameters - if value is not positive it should be left
unchanged. Write a driver program to demonstrate Invoice's capabilities.
I wrote this, but it is not working as it should work:
Header:
#include <string>
class Invoice {
public:
Invoice(std::string partNumber, std::string partDescription, int purchasedQuantity, int itemPrice)
: number(partNumber), description(partDescription),
quantity(purchasedQuantity), price(itemPrice)
{
trate = 0.20;
drate = 0.0;
}
void setNumber(std::string partNumber) {
number = partNumber;
}
std::string getNumber() const {
return number;
}
void setDescription(std::string partDescription) {
description = partDescription;
}
std::string getDescription() const {
return description;
}
void setQuantity(int purchasedQuantity) {
quantity = purchasedQuantity;
}
int getQuantity() const {
return quantity;
}
void setPrice(int itemPrice) {
price = itemPrice;
}
int getPrice() const {
return price;
}
double getTrate() const {
return trate;
}
double getDrate() const {
return drate;
}
void setInvoiceAmount(double iamount) {
iamount = ((quantity*price)*trate) + (quantity*price - drate);
}
double getInvoiceAmount() const {
return iamount;
}
private:
std::string number;
std::string description;
int quantity;
int price;
double trate;
double drate;
};
Main:
#include <iostream>
#include <string>
#include "Header.h"
using namespace std;
int main() {
Invoice invoice1{ "NO134 56", "PCIe SSD", 3, 130, 0.50, 0 };
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();
cout << "\nThe invoice amount is: " << invoice1.getInvoiceAmount() << endl;
}