Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

14.41 Homework 3 You need to write a C++ program to implement a variable-length 2-dimension array of integer. You can think about a 2-dimension array

image text in transcribedimage text in transcribedimage text in transcribed

14.41 Homework 3 You need to write a C++ program to implement a variable-length 2-dimension array of integer. You can think about a 2-dimension array is an array of arrays. I want you to dynamically allocate the memory for the second dimension arrays (for each row). Your program should allow the user to query the elements of this data structure by providing two values (indices of the arrays) where the first number indicates the row and the second number indicates the column. Also, your program should prompt the user if the input is out of bound. For instance, if the structure has 3 rows, the user input of 3 should return an out of bounds error (remember that the indices start from 0 and hence, 3 rows would have indices 0, 1, and 2). The same boundary check should be applied for each row. For instance, if a row has size 4, the user input 6 should have out of bound prompt for the user. Input To build such a 2-dimension array, you need to get the dimension and input information from a file named "input.txt". The "input.txt" file has the following format, and generates a 2-dimension array as shown in Figure: 4 5912 117 6 1390 122 21 8 8 16 9 12 90 122 8 16 21 8 The first number in the input indicates the number of rows (number of horizontal arrays that should be defined dynamically). After that the first row, you will have a row of one number indicating the size of each row following by the element of that row. Output When the structure is populated, you should allow the user to query the elements. In the above example, query 0 0 should return 5 and query 3 1 should return 8. Meanwhile, queries 3 4 and 4 1 should prompt out of bound. The program should terminate with the user input -1-1. Be careful to release the allocated memory. LAB ACTIVITY 14.41.1: Homework 3 0/1000 Downloadable files input.txt Download main.cpp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

4. Explain why strategic planning is important to all managers.

Answered: 1 week ago