Question
I want to input a number of rows into an Array A. The first 2 numbers, is either 0 or 1 and if first number
I want to input a number of rows into an Array A. The first 2 numbers, is either 0 or 1 and if first number read in is 1 then
printResult should be true, if second number is 1 then printArray should be true. the actual size of the array is read in from the 3rd number of the array and then it will allocate memory. For instance if the input.txt was
1
1
4 // Array size n
4
3
2
1
the Array size should be 4. And the 4 elements that are readin are 4,3,2,1. Plz test the function when you are done.
And post the results here that it is working properly.
The details are written below.
Your program should open the file INPUT.txt for reading. If the file cannot be opened, your program should print out the following error message and stop. Error: cannot open file INPUT.txt Now we assume that your program has successfully opened the file INPUT.txt for reading. For the test cases, the file INPUT.txt will all have the correct format, as described in the following. The file INPUT.txt contains n + 3 integers, for some positive integer n (where n may vary from one test case to another). Two consecutive integers are separated by one or more white spaces, where a white space is one of the following three characters: ' ' (i.e., space), '\t' (i.e., tab), ' ' (i.e., newline). If you are not familiar with this kind of input, you can assume (with a very small penalty) that the n + 3 integers are on the first n + 3 lines of the file, with one integer per line. You can quickly get going, and come back to revisit this issue if you have time. The meaning of the n + 3 integers in INPUT.txt and the corresponding actions of your program are as follows. The first integer is either 0 or 1. It is the value of printResult. If printResult = 1, your program will print out (on a new line) the content of array A after it is sorted, at the end of the program. The format of this line should be as follows. It starts the line with string "A:", followed by the n values of array A, with exactly one space (' ') between tokens. If printResult = 0, your program does not perform the above printing. The second integer is either 0 or 1. It is the value of printArray. If printArray = 1, your program will print out (on a new line) the content of array A each time after it is overwritten in the sorting process. The format of this line should be as follows. It starts the line with string "A:", followed by the n values of array A, with exactly one space (' ') between tokens. If printArray = 0, your program does not perform the above printing. The third integer is a positive integer. It is the value of n, i.e., the number of elements in array A. Once n is read in, your program should dynamically allocate memory for array A. For this project, you will allocate array A for n + 1 integers, so that we can index the array from 1 to n, with A[0] not used. The next n integers are the n values for array A. Your program will read in these integers, one at a time, and write them into A[1], A[2], . . . , A[n]. Once these n + 3 integers are read in, your program should close the file INPUT.txt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started