Hello all. I have to write/modify two C++ programs for class, and I am lost on both of them in about the same spot. Hopefully if I can get help with just one of them I will be able to figure out the other, so right now I have to write a program with a header, source file, and a main file. The header has to define a class called Invoice with four data members; Part Number (string), Part Description (string), Price (int), and Quantity (int). There must also be a constructor that initializes the four data members, a set and get function for each data member, and a function called getinvoiceAmount that calculates the total price. I more or less have it done, but when I build and run the program nothing populates from the get functions. The members of type string don't put anything on the screen and the int values are just random numbers. My other program is about the same, just with no int values. Here is the code. Any help would be appreciated.
// Exercise 3.13: Header
// Invoice class definition.
#include <string> // class Invoice uses C++ Standard String Class
// Invoice Class Definition
class Invoice
{
public:
// constructor initializes data members
explicit Invoice(std::string, std::string, int, int);
void setpartNumber(std::string); // sets the partNumber
std::string getpartNumber() const; // gets the partNumber
void setpartDescription(std::string); // sets the partDescription
std::string getpartDescription() const; // gets the partDescription
void setquantity(int); // sets the Quantity
int getquantity(); // gets the Quantity
void setprice(int); // sets the Price
int getprice(); // gets the Price
int getinvoiceAmount(int iquantity, int iprice);
private:
std::string partNumber; // Part Number for this Item
std::string partDescription; // Part Description for this Item
int quantity; // Quantity of this item
int price; // Price of this item
int invoiceAmount; // Total of transaction
}; // end class Invoice
// Exercise 3.13 Source Code
#include <iostream>
#include "Exercise 3.13.h"
// Invoice constructor intializes data members
Invoice::Invoice( std::string partNumber, std::string partDescription, int quantity, int price)
{
// empty body
}
// function to set the PartNumber
void Invoice::setpartNumber(std::string partNumber)
{
partNumber; // store the PartNumber in the object
} // end function setPartNumber
// function to get the PartNumber
std::string Invoice::getpartNumber() const
{
return partNumber; // return object's PartNumber
} // end function getPartNumber
// function to set the PartDescription
void Invoice::setpartDescription(std::string partDescription)
{
partDescription; // store the PartDescription in the object
} // end function setPartDescription
// function to get the PartDescription
std::string Invoice::getpartDescription() const
{
return partDescription; // return object's PartDescription
} // end function getPartDescription
// function to set the Price
void Invoice::setprice(int)
{
if (price > 0)
price = price;
else (price = 0);
} // end function setPrice
// function to get the Price
int Invoice::getprice()
{
return price; // return object's Price
} // end function getPrice
// function to set the Quantity
void Invoice::setquantity(int)
{
if (quantity > 0)
quantity = quantity;
else (quantity = 0);
} // end function setQuantity
// function to get the Quantity
int Invoice::getquantity()
{
return quantity; // return object's Quantity
} // end function getQuantity
// function to get the total
int Invoice::getinvoiceAmount(int iquantity, int iprice)
{
if ((iquantity < 0) || (iprice < 0))
{
std::cout << "Incorrect args!" << std::endl;
}
else
{
invoiceAmount = iquantity * iprice;
}
return invoiceAmount;
}
// Main file to run program
#include <iostream>
#include "Exercise 3.13.h"
usingnamespace std;
int main()
{
string amount;
// Invoice object original quantity
Invoice invoice("B251", "Roofing Hammer", 3, 5);
cout << "Part Information - In Stock\n" << endl;
cout << "Part Number: " << invoice.getpartNumber() << endl;
cout << "Part Description: " << invoice.getpartDescription() << endl;
cout << "Quantity: " << invoice.getquantity() << endl;
cout << "Price: $" << invoice.getprice() << endl;
cout << "\nTotal: $" << invoice.getquantity() * invoice.getprice() << endl;
} // end function display message