void AddItem(MyDatabase *DB)
// Function used to add an object to the database.
{
  if(!InputData()) { 
    cout << "No name was entered" << "\n";
    return;
  }

  Grocery grocery;
  grocery.SetName(Keybuffer::buf);

  if(DB->Find(grocery, 0)) {
    cout << "Item: " << Keybuffer::buf << " already exists" << "\n";
    cout << DB->LastErrorMessage() << "\n" << flush;
    return;
  }

  int stock_number;
  double price;

  cout << "Enter the items's stock number: ";
  cin >> stock_number;
  if(cin) {
    grocery.SetStockNumber(stock_number);
    cout << "Enter the items's price:       $";
    cin >> price;
  } 
  else {
void GroceryManager::AddItem( const string& name, float price, int quantity )
{
    Grocery item;
    item.SetName( name );
    item.SetPrice( price );
    item.SetStock( quantity );
    AddItem( item );
}
void DisplayItem(Grocery &grocery, int full = 1)
// Function used to print a grocery list object to the stdout.
{
  cout << "\n";
  cout << "Item's Name  = " << grocery.Name() << "\n";
  if(full) {
    cout << "Stock Number = " << grocery.StockNumber() << "\n";
    cout.setf(ios::showpoint | ios::fixed);
    cout.precision(2);
    cout << "Price        = $" << grocery.Price() << "\n";
    cout << "\n";
  }
}
Beispiel #4
0
int main()
{
	Grocery item; // testing default constructor
	Grocery item2("carrots", 8, false); //testing constructor with perameters
	item2.print();
	cout << endl;
	item.setGrocery("eggs", 5, true); //testing set grocery function
	item.print();
	cout << endl;
	item.changeAmount(-3);//testing changeamt function should work
	item.print();
	cout << endl;
	item.changeAmount(4);//testing changeamt function should work
	item.print();
	cout << endl;
	item.changeAmount(-100);//testing change amt function shouldn't work
	item.print();

	cout << "\nGLIST STUFF\n";
	GList one; // testing default constructor
	one.insert("bacon",12,false); // testing insert fuction
	one.insert(item); 
	one.print(); // testing print function
	one.erase("bacon",false);
	one.print();
	one.updateItem("bacon",12); // test updating item not in list
	one.print();
	one.updateItem("eggs",-1200); //test updating eggs shouldn't work
	one.print();
	one.updateItem("eggs",12); // test updating eggs should work
	one.print();

	one.insert("Ketchup",50,false); //should print under Costco
	one.insert("Kumquat",3,false); //Should print under Safeway
	one.insert("Mustard",50,true); //Should print under Costco
	one.insert("Potato",7,true); //Should print under Whole Foods
	one.printByStore();
}