Class Invoice get functions won't populate

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.

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
 // 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"
using namespace 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 
Oh, and lines 29 and 106 are the start points of the next programs.
Topic archived. No new replies allowed.