(Solved) : Specifications Define Struct Item Struct Appropriate Holding Item Information Include Item Q42707173 . . .

Specifications:

Define a struct (Item struct) appropriate for holding iteminformation. This should include an item name (a cstring containing25 characters), quantity (a size_t) and price (an double). You maytypedef this struct to a new name if you wish.

At the start of the program, ask the user for the number of items,and use this number as the initial size of your ShoppingCart.(Hint: for easier testing, use a small number, such as two orthree.)

Allocate an appropriate amount of memory from the heap to create adynamic array (named ShoppingCart) of Item structs, large enough tohold the number of items entered by the user.

Provide a menu that allows the user to choose among the followingoptions:

  • Add an item to ShoppingCart – This will prompt the user toenter information about the item (Name, quantity, and price), andsave this in the next uninitialized element in ShoppingCart.
  • Print the current list of items – This will print all items inthe shopping cart
  • Quit the program

Create a function called “ResizeArray” to be used whenever thenumber of items to be added to ShoppingCart would exceed thecurrent bounds of the array. This function must returnvoid. The user should not be aware that the size of thearray is changing. Rather, s/he should simply be allowed to keepadding items until s/he is done, and ResizeArray should be called(transparently to the user) whenever the number of items to beadded would exceed the bounds of the array so that the user may addas many items as s/he likes. Each call to ResizeArray should doublethe size of the existing ShoppingCart. If by any chance all heapmemory is exhausted, an appropriate error message should be issuedto the user. Make sure you test your function by adding more itemsthan originally requested at the start of your program.

Be sure to include comments within your code that explain inhigh-level terms what the various parts of your code are doing.

Expert Answer


Answer to Specifications: Define a struct (Item struct) appropriate for holding item information. This should include an item name…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us