Midterm 0 Review Lecture 10 – Fall 2017
Midterm Prep • Review Session • Tomorrow (Wednesday) at 5pm in GSB G100 • Different material than today's lecture
• Extra Practice Problems • Posted on comp110.com
• Worksheets • Worksheet 2 Graded & Returned -- We're working on WS3! • Understanding what you missed on worksheets is important. • Have questions? Come see us!
Office Hours & Small Review Sessions • No Office Hours or Review Sessions on Thursday/Friday
Exam Day • You only need • Pencil & Eraser • ONECard / Photo ID
• Randomized Seating Assignments • Posted to COMP110.com home tomorrow night in the "Welcome to COMP110" box.
• Format • Similar question types to those on worksheets & practice problems • Hard stop at 1 hour 10 minutes
ARS & Excused Absences • Taking with Accessibility Resource & Services (ARS)? • Register to take on Thursday and they will have the exam for you. • We request they send a scan and we will also pick-up the physical copy from SASB.
• If you have a university excused absence, please e-mail me a scanned copy of your medical/deans note (scan like gradescope) • The make-up exam date and time is Monday at 5pm
1. What are the values of a and b after this code runs? A) a: true, b: true let a: boolean = false; let b: boolean = true; b = a === b;
B) a: true, b: false C) a: false, b: true
D) a: false, b: false
2. What are the values of c and d after this program completes? A) c: true, d: true
let uncScore: number = 76; let northernIowaScore: number = 45; let royThrowsJacket: boolean = true; let a: boolean = uncScore > northernIowaScore; let b: boolean = !royThrowsJacket; let c: boolean = !b && a; let d: boolean = b || a;
B) c: true, d: false C) c: false, d: true
D) c: false, d: false
3. What is printed when the following code runs?
function a(): void { print("a"); print(b()); } function b(): string { print("b"); let s: string = c(); print("b"); return s; } function c(): string { print("c"); return "c"; } a();
4. After the following code runs, what are the values of x and y? let x: number = 10; let y: number = 0;
A) x: 10, y: 0 B) x: 0, y: 10
x = y; y = x;
C) x: 10, y: 10
D) x: 0, y: 0
if (input > 10) { if (input === 10) { print("GO");
5. When input is 100, what is printed?
} else { print("HEELS");
} } else { if (input === 100) { print("BEAT"); } else { if (input < 5) { print("GT"); } else { print("!!!"); }
} }
A. B. C. D. E.
GO HEELS BEAT GT !!!
if (input > 10) { if (input === 10) { print("GO"); } else { print("HEELS");
6. Which of the print statements is logically unreachable no matter what input's value is?
} } else { if (input === 100) { print("BEAT"); } else { if (input < 5) { print("GT"); } else { print("!!!"); }
} }
A. B. C. D. E. F.
HEELS GO !!! BEAT GO and BEAT HEELS and !!!
7. After the following code runs, what are the values of x and y? let x: number = 10; let y: number = 0;
A) x: 10, y: 0 B) x: 0, y: 10
let temp: number = x; y = temp; x = y;
C) x: 10, y: 10
D) x: 0, y: 0
8. What are the elements of array b after the following code runs? let a: number[] = [10, 20, 30]; let b: number[] = []; let i: number = 0; while (i < a.length) { b[i] = a[a.length - (i + 1)]; i++; }
A. B. C. D.
10, 10, 30, 20,
20, 10, 20, 20,
30 10 10 20
9. Given the filter function to the left, which of the following definitions of test is correct? function filter(a: number[]): number[] { let match: number[] = []; let i: number = 0; while (i < a.length) { let element: number = a[i]; if ( test(element) ) { match[match.length] = a[i]; } i++; } return match; }
// A function test(e: number): void {/*...*/} // B function test(e: string): boolean {/*...*/}
// C function test(e: number): boolean {/*...*/} // D function test(e: boolean): number {/*...*/}
10. Write a function named compare that takes two numbers as parameters. If the first number is smaller than the second, return -1, if they are equal, return 0, otherwise return 1.