Make your own free website on Tripod.com
« May 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 31
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Cash Register
Thursday, 20 March 2008
Cash Register

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

const float PROFIT= .3f;
const float SALES_TAX= .06f;
const int MAX= 3;

class InventoryItem
{
private:
 string description;
 int onHand;
 double cost;
public:
 InventoryItem()
 {
  description = "NULL";
  onHand = 0;
  cost = 0;
 }
 InventoryItem(string desc, int tempamount, double tempcost)
 {
  description = desc;
  onHand = tempamount;
  cost = tempcost;
 }
 void setdescription(string desc)
 {
  description = desc;
 }
 void setunits(int tempamount)
 {
  onHand = tempamount;
 }
 void setcost(double tempcost)
 {
  cost = tempcost;
 }
 string& getdescription()
 {
  return description;
 }
 int getamount()
 {
  return onHand;
 }
 double getcost()
 {
  return cost;
 }

 void updateamount(int useramount)
 {
  onHand = onHand - useramount;
 }
 friend ostream & operator <<(ostream &out, InventoryItem &temp);
};

class cashregister
{
private:
 string item;
 int quantity;
 double unitprice;
 double psubtotal;
 double ptotal;
 double tax;
 int index;
 bool test(string& temp, InventoryItem *tempinven)
 {
  for (int i = 0; i < MAX; i++)
  {
   if (temp == tempinven[i].getdescription())
   {
    index = i;
    return true;
   }
  }
  return false;
 }

public:
 cashregister()
 {
  item = "NULL";
  quantity = 0;
  unitprice = 0;
  psubtotal = 0;
  ptotal = 0;
  tax = 0;
  index = 0;
 }
 void input(InventoryItem *tempinven)
 {
  string str;
  int y = 0;
  do
  {
  cout << "\n   Enter item to Purchase: ";
  cin >> str;
  if(test(str, tempinven) == true)
   y = 1;
  else
  {
   cout << "No such item!"<<endl;
   y = 0;
  }
  }while (y == 0);
  y = 0;  
  do
  {
  cout << "   Enter Quantity: ";
  cin >> quantity;
  cout << endl;
  if(quantity > 0)
   y = 1;
  else
  {
   cout << "Please enter a positive number!"<<endl;
   y = 0;
  }
  }while( y== 0);
 }
 void setunitprice(double cost)
 {
  unitprice = cost + (PROFIT * cost);
 }
 void setpsubtotal()
 {
  psubtotal = unitprice * quantity;
 }
 void setptotal()
 {
  tax = psubtotal * SALES_TAX;
  ptotal = psubtotal + tax;
 }
 friend ostream & operator <<(ostream &out, cashregister &temp);
 int getquantity()
 {
  return quantity;
 }
 int getindex()
 {
  return index;
 }
};
ostream & operator <<(ostream &out, InventoryItem &temp)
 {
  out << "   Item: " << temp.description << "\t";
  out << "   Quantity: " << temp.onHand << "\t";
  out << "   Cost: " << temp.cost << "\t";
  return out;
 }
 ostream & operator <<(ostream &out, cashregister &temp)
 {
  out << "   Subtotal: $" << temp.psubtotal << "\n";
  out << "   Tax: $" << temp.tax << "\n";
  out << "   Total : $" << temp.ptotal << "\n";
  return out;
 }

void Clear_Screen(void);
void Flush(void);

int main()
{
   int amount = 0, location, i = 0;
   double itemcost = 0;
   char response;
   cashregister cash;
   InventoryItem inven[3] = {InventoryItem("Wrench", 100,2.59),InventoryItem("Hammer", 100, 4.59),
   InventoryItem("Screwdriver", 100, 1.59)};
   Clear_Screen();
    do
 {
 cout << "CURRENT INVENTORY\n\n";
 for(i = 0; i < MAX; i++)
 {
  cout << inven[i] << endl;
    }
 i = 0;
 
 cash.input(inven);
 location = cash.getindex();
 itemcost = inven[location].getcost();
 cash.setunitprice(itemcost);
 cash.setpsubtotal();
 cash.setptotal();
 amount = cash.getquantity();
 inven[location].updateamount(amount);
 cout << cash << endl;
 cout << endl;
 Flush();
 cout << "   Press any key to continue" << endl;
 getchar();
 Clear_Screen();
 cout << "\n   Would you like to purchase more items? (Y/N): ";
 cin >> response;
 Clear_Screen();
 }
 while(response == 'Y' || response == 'y');
 Clear_Screen();
    cout << "\n\n   Thank you for using the program!" << endl;
    Flush();
    cout << "\n\n   Press any key to exit" << endl;
    getchar();
    return 0;
}

void Clear_Screen(void)
{
   #ifdef _WIN32
      system("cls");
   #else
      system("clear");
   #endif
}

void Flush(void)
{
   int ch;
   do
   {
      ch = getchar();
   }
   while (ch != EOF && ch != '\n');
   clearerr(stdin);
}


Posted by veronicak5678 at 10:22 PM EDT

Newer | Latest | Older