I have a question about a couple of lines in this code.
I was just wondering what exactly is the purpose of lines 39-46? Why do we "redefine" (sorry if that's not what it's actually called, I can't for the life of me remember :S ) the terms?
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
class InventoryItem
{
private:
int partNum; // Part number
string description; // Item description
int onHand; // Units on hand
double price; // Unit price
public:
void storeInfo(int p, string d, int oH, double cost); // Prototype
int getPartNum()
{
return partNum;
}
string getDescription()
{
return description;
}
int getOnHand()
{
return onHand;
}
double getPrice()
{
return price;
}
};
// Implementation code for InventoryItem class function storeInfo
void InventoryItem::storeInfo(int p, string d, int oH, double cost)
{
partNum = p;
description = d;
onHand = oH;
price = cost;
}
// Function prototypes for client program
void storeValues(InventoryItem&); // Receives an object by reference
void showValues(InventoryItem); // Receives an object by value
int main()
{
InventoryItem part; // part is an InventoryItem object
storeValues(part);
showValues(part);
system("pause");
return 0;
}
void storeValues(InventoryItem &item)
{
int partNum; // Local variables to hold user input
string description;
int qty;
double price;
// Get the data from the user
cout << "Enter data for the new part number \n";
cout << "Part number: ";
cin >> partNum;
cout << "Description: ";
cin.get(); // Move past the '\n' left in the
// input buffer by the last input
getline(cin, description);
cout << "Quantity on hand: ";
cin >> qty;
cout << "Unit price: ";
cin >> price;
// Store the data in the InventoryItem object
item.storeInfo(partNum, description, qty, price);
}
void showValues(InventoryItem item)
{
cout << fixed << showpoint << setprecision(2) << endl;
cout << "Part Number : " << item.getPartNum() << endl;
cout << "Description : " << item.getDescription() << endl;
cout << "Units On Hand: " << item.getOnHand() << endl;
cout << "Price : $" << item.getPrice() << endl;
}