1. Write C++ statements which declare the parkingSpots as a of type two-dimensio
ID: 3891369 • Letter: 1
Question
1. Write C++ statements which declare the parkingSpots as a of type two-dimensional int array, sized NUM_OF_ROWS by NUM_OF_COLS, then write another statement which calls the function from the previous problem with this new array.
2. Write the C++ definition of a void function with a single formal parameter of type two-dimensional int array, sized NUM_OF_ROWS by NUM_OF_COLS. Assume NUM_OF_ROWS and NUM_OF_COLS are defined integer constants. Have the function read from common input in order to fill the contents of the array which is passed in.
3.
3. Given the following C++ code
char name[8];
strcpy(name, " Robert");
mark the following statements as ‘‘Yes’’ if they precisely output Robert. Otherwise, mark the statement as ‘‘No’’ and explain the reason why.
a. cout << name;
Answer:
b. for(int j = 0; j < 5; j++)
cout << name[j];
Answer:
c. int j = 0;
while(name[j] != '')
cout << name[j++];
Answer:
d. for(int j = 0; j < 8; j++)
cout << name[j];
Explanation / Answer
1. int parkingSpots[NUM_OF_ROWS][NUM_OF_COLS]
function call with the array can be
void f(int data[][]); if such is function signature then
calling will be f(parkingSpots);
2. void f(int data[NUM_OF_ROWS][NUM_OF_COLS]);
void f(int data[NUM_OF_ROWS][NUM_OF_COLS]){
for (int i=0; i<NUM_OF_ROWS; i++){
for (int j =0; j<NUM_OF_COLS; j++){
cin >> data[i][j];
}
}
}
3. a True
b False Robert is of length 7 but the loop is going upto 5
c True
d True
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.