I am trying an exercise in a book and can't find my problem.
I want an invoice class with a seperate implementation file and a file to use it. Below are the three files.
// invoice class
//Invoice.h
#include <string>
using namespace std;
class Invoice
{
public:
Invoice(string,string, int, int);
void setInvoicePartNumber(string);
string getInvoicePartNumber();
void setInvoicePartDescription(string);
string getInvoicePartDescription();
void setInvoiceQuantity(int);
int getInvoiceQuantity();
void setInvoicePrice(int);
int getInvoicePrice();
int getInvoiceAmount();
private:
string invoicePartNumber;
string invoicePartDescription;
int invoiceQuantity;
int invoicePrice;
int invoiceAmount;
}
// invoice implementation
// Invoice.cpp
#include <iostream>
#include <string>
using namespace std;
#include "Invoice.h"
Invoice::Invoice(string partNumber, string partDescription, int quantity, int price)
{
setInvoiceQuantity(quantity);
setInvoicePartDescription(partDescription);
setInvoicePartNumber(partNumber);
setInvoicePrice(price);
}
void Invoice::setInvoicePartNumber(string partNumber)
{
invoicePartNumber=partNumber;
}
void Invoice::setInvoicePartDescription(string partDescription)
{
invoicePartDescription=partDescription;
}
void Invoice::setInvoiceQuantity(int quantity)
{
invoiceQuantity=quantity;
}
void Invoice::setInvoicePrice(int price)
{
invoicePrice=price;
}
string Invoice::getInvoicePartNumber()
{
return invoicePartNumber;
}
string Invoice::getInvoicePartDescription()
{
return invoicePartDescription;
}
int Invoice::getInvoiceQuantity()
{
return invoiceQuantity;
}
int Invoice::getInvoicePrice()
{
return invoicePrice;
}
int Invoice::getInvoiceAmount()
{
invoiceAmount=invoiceQuantity*invoicePrice;
return invoiceAmount;
}
//using invoice class
//test.cpp
#include <iostream>
#include <string>
#include "Invoice.h"
int main()
{
Invoice invoice("500i", "screw", 5, 6);
std::cout<<"Item number " << invoice.getInvoicePartNumber()<< "description: " <<invoice.getInvoicePartDescription()<< " quantity: " <<invoice.getInvoiceQuantity() << "Price: " << invoice.getInvoicePrice() << "for a total of " <<invoice.getInvoiceAmount()<<endl;
return 0;
}
Any help would be appreciated.