Computer Science › Implementation Techniques
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?
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?
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++)
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++)
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
?
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
?
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
?
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
?
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?
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?