Implementation Techniques

Practice Questions

Computer Science › Implementation Techniques

Page 1 of 2
10 of 14
1

Consider the following code:

int\[\] vals = {6,1,41,5,1};

int\[\]\[\] newVals = new int\[vals.length\]\[\];

for(int i = 0; i < vals.length; i++) {

newVals\[i\] = new int\[vals\[i\]\];

for(int j = 0; j < vals\[i\];j++) {

newVals\[i\]\[j\] = vals\[i\] * (j+1);

}

}

What does the code above do?

2

Consider the following code:

int\[\] vals = {6,1,41,5,1};

int\[\]\[\] newVals = new int\[vals.length\]\[\];

for(int i = 0; i < vals.length; i++) {

newVals\[i\] = new int\[vals\[i\]\];

for(int j = 0; j < vals\[i\];j++) {

newVals\[i\]\[j\] = vals\[i\] * (j+1);

}

}

What does the code above do?

3

Given a vector of ints called "intVec", write a "ranged for" loop, also sometimes known as a "for each" loop, to double the values fof all elements in a vector. (In C++)

4

Given a vector of ints called "intVec", write a "ranged for" loop, also sometimes known as a "for each" loop, to double the values fof all elements in a vector. (In C++)

5

Consider the following C++ pseudocode:

Class Car {

const int wheels = 4;

float milesPerGallon;

string make;

string model;

}

Car sportscar = new Car;

What is the difference between the class car, and the object sportscar?

6

Consider the following C++ pseudocode:

Class Car {

const int wheels = 4;

float milesPerGallon;

string make;

string model;

}

Car sportscar = new Car;

What is the difference between the class car, and the object sportscar?

7

Class Person {

int height;

float weight;

``

public:

int getHeight();

void setHeight(int);

float getWeight();

void setWeight(float);

};

What is the access level of height and weight?

8

Class Person {

int height;

float weight;

``

public:

int getHeight();

void setHeight(int);

float getWeight();

void setWeight(float);

};

What is the access level of height and weight?

9

Consider the following code:

public static class Clock {

private int seconds;

``

public Clock(int s) {

seconds = s;

}

``

public void setTime(int s) {

seconds = s;

}

``

public void setSeconds(int s) {

int hoursMinutes = seconds - seconds % 60;

seconds = hoursMinutes + s;

}

``

public void setMinutes(int min) {

int hours = seconds / 3600;

int currentSeconds = seconds % 60;

seconds = hours + min * 60 + currentSeconds;

}

}

Which of the following represents a method that returns the minute value of the clock?

10

Consider the following code:

public static class Clock {

private int seconds;

``

public Clock(int s) {

seconds = s;

}

``

public void setTime(int s) {

seconds = s;

}

``

public void setSeconds(int s) {

int hoursMinutes = seconds - seconds % 60;

seconds = hoursMinutes + s;

}

``

public void setMinutes(int min) {

int hours = seconds / 3600;

int currentSeconds = seconds % 60;

seconds = hours + min * 60 + currentSeconds;

}

}

Which of the following represents a method that returns the minute value of the clock?

Page 1 of 2
Return to subject