SHARE
TWEET

Untitled

a guest Mar 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //P618 C++ - Program 11-6
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. struct InventoryItem
  8. {
  9.     int partNum;                  // Part number
  10.     string description;          // Item description
  11.     int onHand;                   // Units on hand
  12.     double price;                 // Unit price
  13. };
  14.  
  15. // Function Prototypes
  16. void getItem(InventoryItem&);    // Argument passed by reference
  17. void showItem(InventoryItem);    // Argument passed by value
  18.  
  19. int main()
  20. {
  21.     InventoryItem part;
  22.  
  23.     getItem(part);
  24.     showItem(part);
  25.     return 0;
  26. }
  27.  
  28. //***********************************************************
  29. // Definition of function getItem. This function uses       *
  30. // a structure reference variable as its parameter. It asks *
  31. // the user for information to store in the structure.      *
  32. //***********************************************************
  33.  
  34. void getItem(InventoryItem &p)   // Uses a reference parameter
  35. {
  36.     // Get the part number.
  37.     cout << "Enter the part number: ";
  38.     cin >> p.partNum;
  39.  
  40.     // Get the part description.
  41.     cout << "Enter the part description: ";
  42.     cin.ignore();  // Ignore the remaining newline character
  43.     getline(cin, p.description);
  44.  
  45.     // Get the quantity on hand.
  46.     cout << "Enter the quantity on hand: ";
  47.     cin >> p.onHand;
  48.  
  49.     // Get the unit price.
  50.     cout << "Enter the unit price: ";
  51.     cin >> p.price;
  52. }
  53.  
  54. //***********************************************************
  55. // Definition of function showItem. This function accepts   *
  56. // an argument of the InventoryItem structure type. The     *
  57. // contents of the structure is displayed.                  *
  58. //***********************************************************
  59.  
  60. void showItem(InventoryItem p)
  61. {
  62.     cout << fixed << showpoint << setprecision(2);
  63.     cout << "Part Number: " << p.partNum << endl;
  64.     cout << "Description: " << p.description << endl;
  65.     cout << "Units On Hand: " << p.onHand << endl;
  66.     cout << "Price: $" << p.price << endl;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top