Computer Science – 12.3 Program Testing and Maintenance | e-Consult
12.3 Program Testing and Maintenance (1 questions)
Analysis: The fixed-size array has several limitations. It limits the number of items that can be stored, leading to potential overflow issues. Resizing the array is a complex operation that can be time-consuming and error-prone. Directly storing item information within the array elements violates good programming practices and makes the code less maintainable. The lack of dynamic resizing makes the system inflexible.
Alternative Data Structure: Use a std::vector from the C++ Standard Template Library (STL). A std::vector is a dynamic array that can automatically resize as needed. This overcomes the limitations of the fixed-size array. The std::vector can store Item objects, where each Item object contains the item's name, quantity, and price. This provides better data encapsulation and organization. The use of a std::vector also simplifies the code and makes it more efficient, as it avoids the need for manual memory management.
Example Table (Illustrative):
| Item Name | Quantity | Price |
| Laptop | 10 | 1200 |
| Mouse | 50 | 25 |