Q#1: What is the purpose of the given program, and how does it terminate the input from the user?
Answer: The program collects integers from the user and stores them in an array of up to 100 numbers. Input terminates when the user enters -1 or when the array reaches its maximum size of 100.
Q#2: Explain the significance of the loop construct (do-while) used in the program and why it is chosen over other loop constructs.
Answer: The do-while loop is used because it guarantees that the loop body executes at least once, which fits the program’s logic. It continues prompting the user while the input is not -1 and the counter i is less than 100.
Q#3: How does the program determine the total number of positive integers entered by the user, and why is the calculation (i - 1) used?
Answer: The program increments the counter i for each input. After the loop terminates, i has been incremented once more, so (i - 1) gives the accurate count of positive integers entered.
Q#4: How can the program be adapted for practical use, such as calculating the ages of students in a class with an unknown number of students?
Answer: The program can be adapted by declaring an array large enough to accommodate the maximum expected students. Users can enter ages until -1 is input, allowing the program to handle classes of varying sizes.