Explore BrainMass


A) Define a class named GroceryItem. Include private fields that hold an item's stock number, price, quantity in stock, and total value. Write three public functions that each set one of the three fields, based on user keyboard input. The function that sets the stock number requires the user to enter exactly four digits; continue to prompt the user until a valid stock number is entered. Include a private function that calculates the GroceryItem's value field (price times quantity in stock) within the same function that accepts the quantity in stock input. Write a function that displays a GroceryItem's values. Finally, write a main() function that declares a GroceryItem object, assigns values to its fields, and uses the display function.

B) Write a main() function that declares an array of 10 GroceryItem objects. Assign values to all 10 items and display them.


Solution Preview

Please try the following program. There are three files including header file, cpp file and the main
file. You have to create a Win32 console application project to run the program. There will be 10 objects of groceryitems, but the item number is always 4 digit number, if 4 digit number is not entered, it will keep asking for item number. For every item there is price and quantity, price is integer value for simplicity and when all 10 items are entered, the program displays 10 items with corresponding item number and total value for particular ...

Solution Summary

Define a class named GroceryItem