Advertisement
Guest User

mememememme

a guest
Apr 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. // get code.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <iomanip>
  9. #include <string>
  10. #ifndef INVENTORYITEM_H
  11. #define INVENTORYITEM_H
  12.  
  13. using namespace std;
  14. class InventoryItem//==================================fight or enemy/player
  15. {
  16. private:
  17. string description; // The item description========name of enemy
  18. double cost; // The item cost======================player Health
  19. int units; // Number of units on hand==============enemy health
  20. public:
  21. // Constructor #1
  22. InventoryItem()//==================================fight or enemy/player
  23. { // Initialize description, cost, and units.
  24. description = "";// The item description========name of enemy
  25. cost = 0.0; // The item cost======================player Health
  26. units = 0; // Number of units on hand==============enemy health
  27. }
  28.  
  29. // Constructor #2
  30. InventoryItem(string desc)//==================================fight or enemy/player
  31. { // Assign the value to description.
  32. description = desc;// The item description========name of enemy
  33.  
  34. // Initialize cost and units.
  35. cost = 0.0; // The item cost======================player Health
  36. units = 0; // Number of units on hand==============enemy health
  37. }
  38.  
  39. // Constructor #3
  40. InventoryItem(string desc, double c, int u)//==================================fight or enemy/player
  41. { // Assign values to description, cost, and units.
  42. description = desc;// The item description========name of enemy
  43. cost = c; // The item cost======================player Health
  44. units = u; // Number of units on hand==============enemy health
  45. }
  46. void setDescription(string d)
  47. {
  48. description = d;// The item description========name of enemy
  49. }
  50.  
  51. void setCost(double c)
  52. {
  53. cost = c; // The item cost======================player Health
  54. }
  55.  
  56. void setUnits(int u)
  57. {
  58. units = u; // Number of units on hand==============enemy health
  59. }
  60.  
  61. // Accessor functions
  62. string getDescription() const
  63. {
  64. return description;// The item description========name of enemy
  65. }
  66.  
  67. double getCost() const
  68. {
  69. return cost; // The item cost======================player Health
  70. }
  71.  
  72. int getUnits() const
  73. {
  74. return units; // Number of units on hand==============enemy health
  75. }
  76. };
  77. #endif
  78. int main()
  79. {
  80. InventoryItem item1;
  81. item1.setDescription("Hammer"); // Set the description// The item description========name of enemy
  82. item1.setCost(6.95); // Set the cost
  83. item1.setUnits(12); // Set the units // Number of units on hand==============enemy health
  84.  
  85. // Create an InventoryItem object and call
  86. // constructor #2.
  87. InventoryItem item2("Pliers");// The item description========name of enemy
  88.  
  89. // Create an InventoryItem object and call
  90. // constructor #3.
  91. InventoryItem item3("Wrench", 8.75, 20);// The item description========name of enemy
  92.  
  93. cout << "The following items are in inventory:\n";
  94. cout << setprecision(2) << fixed << showpoint;
  95. // Display the data for item 1.
  96. cout << "Description: " << item1.getDescription() << endl;// The item description========name of enemy
  97. cout << "Cost: $" << item1.getCost() << endl; // The item cost======================player Health
  98. cout << "Units on Hand: " << item1.getUnits() << endl << endl; // Number of units on hand==============enemy health
  99.  
  100. // Display the data for item 2.
  101. cout << "Description: " << item2.getDescription() << endl;// The item description========name of enemy
  102. cout << "Cost: $" << item2.getCost() << endl; // The item cost======================player Health
  103. cout << "Units on Hand: " << item2.getUnits() << endl << endl; // Number of units on hand==============enemy health
  104.  
  105. // Display the data for item 3.
  106. cout << "Description: " << item3.getDescription() << endl;// The item description========name of enemy
  107. cout << "Cost: $" << item3.getCost() << endl; // The item cost======================player Health
  108. cout << "Units on Hand: " << item3.getUnits() << endl; // Number of units on hand==============enemy health
  109.  
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement