Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // get code.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <time.h>
- #include <stdlib.h>
- #include <iomanip>
- #include <string>
- #ifndef INVENTORYITEM_H
- #define INVENTORYITEM_H
- using namespace std;
- class InventoryItem//==================================fight or enemy/player
- {
- private:
- string description; // The item description========name of enemy
- double cost; // The item cost======================player Health
- int units; // Number of units on hand==============enemy health
- public:
- // Constructor #1
- InventoryItem()//==================================fight or enemy/player
- { // Initialize description, cost, and units.
- description = "";// The item description========name of enemy
- cost = 0.0; // The item cost======================player Health
- units = 0; // Number of units on hand==============enemy health
- }
- // Constructor #2
- InventoryItem(string desc)//==================================fight or enemy/player
- { // Assign the value to description.
- description = desc;// The item description========name of enemy
- // Initialize cost and units.
- cost = 0.0; // The item cost======================player Health
- units = 0; // Number of units on hand==============enemy health
- }
- // Constructor #3
- InventoryItem(string desc, double c, int u)//==================================fight or enemy/player
- { // Assign values to description, cost, and units.
- description = desc;// The item description========name of enemy
- cost = c; // The item cost======================player Health
- units = u; // Number of units on hand==============enemy health
- }
- void setDescription(string d)
- {
- description = d;// The item description========name of enemy
- }
- void setCost(double c)
- {
- cost = c; // The item cost======================player Health
- }
- void setUnits(int u)
- {
- units = u; // Number of units on hand==============enemy health
- }
- // Accessor functions
- string getDescription() const
- {
- return description;// The item description========name of enemy
- }
- double getCost() const
- {
- return cost; // The item cost======================player Health
- }
- int getUnits() const
- {
- return units; // Number of units on hand==============enemy health
- }
- };
- #endif
- int main()
- {
- InventoryItem item1;
- item1.setDescription("Hammer"); // Set the description// The item description========name of enemy
- item1.setCost(6.95); // Set the cost
- item1.setUnits(12); // Set the units // Number of units on hand==============enemy health
- // Create an InventoryItem object and call
- // constructor #2.
- InventoryItem item2("Pliers");// The item description========name of enemy
- // Create an InventoryItem object and call
- // constructor #3.
- InventoryItem item3("Wrench", 8.75, 20);// The item description========name of enemy
- cout << "The following items are in inventory:\n";
- cout << setprecision(2) << fixed << showpoint;
- // Display the data for item 1.
- cout << "Description: " << item1.getDescription() << endl;// The item description========name of enemy
- cout << "Cost: $" << item1.getCost() << endl; // The item cost======================player Health
- cout << "Units on Hand: " << item1.getUnits() << endl << endl; // Number of units on hand==============enemy health
- // Display the data for item 2.
- cout << "Description: " << item2.getDescription() << endl;// The item description========name of enemy
- cout << "Cost: $" << item2.getCost() << endl; // The item cost======================player Health
- cout << "Units on Hand: " << item2.getUnits() << endl << endl; // Number of units on hand==============enemy health
- // Display the data for item 3.
- cout << "Description: " << item3.getDescription() << endl;// The item description========name of enemy
- cout << "Cost: $" << item3.getCost() << endl; // The item cost======================player Health
- cout << "Units on Hand: " << item3.getUnits() << endl; // Number of units on hand==============enemy health
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement