c++ shell
a) Write a program using 2D array to keep track stationary store inventory. The store sells various items. For each item in the store, the following information is entered: item ID, item name, number of pieces ordered, number of pieces currently in the store, number of pieces sold, manufacturer’s price for the item, and the store’s selling price. At the end of each week, the store manager would like to see a report in the following form:
Happy Stationary Store |
||||||
itemID |
itemName |
pOrdered |
pInStore |
pSold |
manufPrice |
sellingPrice |
1111 |
Pencil |
120 |
180 |
80 |
5.00 |
8.00 |
1112 |
A4 Paper |
150 |
100 |
50 |
10.00 |
14.00 |
: |
|
|
|
|
|
|
: |
|
|
|
|
|
|
Total Inventory: RM #####.## |
|
|
||||
Total number of items in the store: ________________ |
The total inventory is the total selling value of all of the items currently in the store. The total number of items is the sum of the number of pieces of all of the items in the store.
b) In order to use 1D or 2D array, programmer need to become familiar with declaring and manipulating arrays, as well as using arrays as parameters.
- Describe the need for an array when processing items that are the same data type and represent the same conceptual item.
- Discuss the syntax involved in accessing array components. Review the use of the array subscripting operator with the code 2(a).
- Describe some common operations typically performed on arrays.
- Explain the consequences of using an array index that is out of bounds and discuss some common coding errors that can result in an out of bounds array index.
- Explain in more detail why C++ only allows arrays to be passed as reference parameters.
