Eecs280f19 - Midterm - Solutions
Eecs280f19 - Midterm - Solutions
Fall 2019
Written Portion SOLUTIONS
This is a closed-book exam. You may use one note sheet, 8.5"x11", double--sided, with your
name on it. This booklet contains space to write you answers for the multiple-choice and written
components of the exam.
Read the entire exam through before you begin working. Work on those problems you find
easiest first. Read each question carefully, and note all that is required of you. Assume all code
is in standard C++11, and use only standard C++11 in your solutions.
Instructions:
● Throughout the exam, assume all necessary #include headers and the using
namespace std; directive are present unless otherwise directed.
● You do not need to verify REQUIRES clauses with assert unless instructed to do so.
● The last several pages include space for scratch work (including the last piece of
paper, which you may tear out).
I have neither given nor received aid on this exam, nor have I concealed any violations of
the Honor Code.
Signature: _________________________________________
Name: _________________________________________
Uniqname: _________________________________________
UMID: _________________________________________
1. ⓣ ⓕ
2. ⓣ ⓕ Should be “int”
3. ⓣ ⓕ
6. ⓣ ⓕ
9. ⓣ ⓕ
10. ⓣ ⓕ
ⓐ ⓑ ⓒ ⓓ ⓔ 1.
ⓐ ⓑ ⓒ ⓓ ⓔ 2.
ⓐ ⓑ ⓒ ⓓ ⓔ 3.
ⓐ ⓑ ⓒ ⓓ ⓔ 4.
ⓐ ⓑ ⓒ ⓓ ⓔ 5.
ⓐ ⓑ ⓒ ⓓ ⓔ 6.
ⓐ ⓑ ⓒ ⓓ ⓔ 7.
ⓐ ⓑ ⓒ ⓓ ⓔ 8.
ⓐ ⓑ ⓒ ⓓ ⓔ 9.
ⓐ ⓑ ⓒ ⓓ ⓔ 10.
int N = atoi(argv[1]);
if(argc == 3) {
ifstream is(argv[2]);
readFromStream(is, N);
} else {
readFromStream(cin, N);
}
return 0;
}
1. 42
2. Undefined
3.
rld
t
2b) (3 points)
3a) (2 points)
p_in->num_songs = 0;
p_in->name = name_in;
3b) (6 points)
4a) (3 points)
if(lowPowerModeOn)
Device:: depletePower(amount/2);
else
Device::depletePower(amount);
4b) (3 points)
int count=0;
for(int i=0; i<devices.size(); i++) {
if(devices[i]->getBatteryPercentage() > 75 &&
devices[i]->getDeviceID() == Phone::DeviceID )
count++;
}
return count;
4d) (8 points)
1. Phone Depleted 2%
Phone Depleted 1%
2. Compile error
4. Compile error
4e) (2 points)