Type (do not copy and paste) Program 1 into a program and compile. Run the program

Program 1:

include

using namespace std;

int main(void)
{
int vals[10];
size_t count;
size_t which;

cout << “How many values should be stored in the array? “; cin >> count;

for (size_t i = 0; i < count; i++) {
vals[i] = count – i;
}

cout << “Which value do you wish to retrieve? “; cin >> which;

cout << “Your value is ” << vals[which] << endl;

return 0;
}

Question 1
Describe the results of above program run in step 1?

Question 2
What happens if you type 7 for the first prompt and then 4 for the second prompt?

Question 3
What happens if you type 7 for the first prompt and then 8 for the second prompt?

Question 4
What happens if you type 20 for the first prompt and then 50000 for the second prompt?

Question 5
What happens if you type 20 for the first prompt and then -1 for the second prompt?

Question 6
What happens if you type 10 for the first prompt and then “b” for the second prompt?

Sample Solution

This question has been answered.

Get Answer