« November 2018 »
S M T W T F S
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
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Ch 13 PC 6 Inventory Class
Sunday, 2 March 2008
Inventory Class

#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;

class Inventory{
      private:
              string name;
              int itemNumber;
              int quantity;
              double cost;
              double totalCost;
      public:
             Inventory (string Name)
             {
                       name=Name;
                       cout<<"\nEnter Item Number for: " << Name << endl;
                       cin>>itemNumber;
                       cout<<"\nEnter quantity of: " << Name << endl;
                       cin>>quantity;
                       cout<<"\nEnter the cost of one: " << Name << endl;
                       cin>> cost;
                       totalCost = getTotalCost();
             }
             Inventory ( int n, double c, int q )
             {
                       itemNumber = n;
                       quantity = q;
                       cost = c;
                       totalCost = getTotalCost();
             }
             void Inventory::setItemNumber ( int name )
             {
                  itemNumber= name;
             }
             void Inventory::setQuantity ( int q )
             {
                  quantity=q;
             }
             void Inventory::setCost (double c )
             {
                  cost=c;
             }
             int getItemNumber () const
             {
                 return itemNumber;
             }
             int getQuantity () const
             {
                 return quantity;
             }
             double getCost () const
             {
                  return cost;
             }
             double getTotalCost ()
             {
                    totalCost = quantity * cost;
                    return totalCost;
             }
};
void Clear_Screen(void);
int main()
{
          Inventory hammer("hammer"),wrench("wrench"),saw("saw");
          Clear_Screen();
          cout<<"________Item Number_______Quantity_______Cost___________Total Cost___________" << endl << endl;
          cout<< setw(14) <<hammer.getItemNumber() << setw(16) << hammer.getQuantity() << setw(15)
          << hammer.getCost()
          << setw(20) << hammer.getTotalCost()<< endl;
          cout << endl;
          cout<< setw(14) <<wrench.getItemNumber() << setw(16) << wrench.getQuantity() << setw(15)
          << wrench.getCost() << setw(20) << wrench.getTotalCost()<< endl;
          cout << endl;
          cout<< setw(14) <<saw.getItemNumber() << setw(16) << saw.getQuantity() << setw(15)
          << saw.getCost() << setw(20) << saw.getTotalCost()<< endl;
          cin.get(); cin.get();
          cout << "\n\n Thank you for using the program!" << endl;
          cout << "\n\n Press any key to exit" << endl;
          getchar();
          return 0;
}
void Clear_Screen(void)
{
         #ifdef _WIN32
         system("cls");
         #else
         system("clear");
         #endif
}


Posted by veronicak5678 at 1:01 PM EST
Updated: Wednesday, 5 March 2008 8:38 PM EST

Newer | Latest | Older