Multiple Choices (Choose the most appropriate answer) 1. Consider the following
ID: 3568808 • Letter: M
Question
Multiple Choices (Choose the most appropriate answer)
1. Consider the following function definition:
void fillArray(int a[], int arraySize)
{
for (int k = 0; k < arraySize; k++)
a[k]=2*k;
}
Which of the following is an acceptable function call?
int myArray[30]={1, 2, 3}, a;
(a) fillArray (myArray, 20); (b) a = fillArray (myArray, 30);
(c) fillArray (myArray, 40); (d) fillArray (myArray[30],30);
2. What is the output of the following statements?
int linearSearch(int list[], int key, int arraySize)
{
for (int i=0; i<arraySize; i++)
{
if (key == list[i])
return i+1;
}
return -1;
}
Explanation / Answer
1. a
2. a
3. d
4. d since double = functionName(double,int)
5. a
6. b
7.
a) public data member are the variables and functions which can be called directly after intiating the class as object. eg. setData(int r), getData() methods in the Grade class.
b) private data member are the variables and functions which can be used within the class definition and can't be called via its object. eg. int result variable.
8. Output
40
20
50
30
10
9. Corrections highlighted
#include <iostream>
using namespace std;
class Date
{
// missing :
public:
Date()
{
//month = day = 0; --Incorrect line
month=0;
day=0;
}
setDate(int m, int d)
{
month = m;
day = d;
}
// method definition ending with ; incorrect
int getDay()
{
return day
}
// missing :
private:
int month, day;
}
int main()
{
Date d;
//call of setDate without object d. -incorrect
d.setDate(10,20);
//accessing private day variable directly -- incorrect. should be via public method getDay
cout << d.getDay() << endl;
return 0;
}
10. Total number is 3
11 & 12 will be shared shortly.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.