CS 107 - 7/8/15 Exam 1 on Friday 23 questions Q 1 - 20: Multiple choice - 2 points each Put answers for these on Scantron sheet (Bring a #2 pencil) x = 5; y = 7; z = x + y; x = x * 2; ... x: 5 10 y: 7 z: 12 Topics: types, arithmetic operators and assignment statements ( ) * / % + - relational operator and boolean operators < <= > >= == != && || ! while, if and for statements Q 21, 22, 23 - Write code questions Assume you are within main() - Be sure to declare (and initialize) variables! One questions does ask for array use. you will be asked for looping and selection statements If a while, for, if statement only have one line in the body, curly braces are NOT required. string compares can use the relational operators strcmp() should not be needed for the exam. int val1, val2; int val3 = 0; Multiple choice example: What is the value of z after the following code is finished executing? w=1; x = 0; y = 0; z =0; while ( w < 5 ) { z = x + y + z; x = x + 1; y = y + 2; w = w + 1; } w: 1 2 3 4 5 x: 0 1 2 3 4 y: 0 2 4 6 8 z: 0 0 3 9 18 ==================================================== Functions & Parameters So parameters allow us to perform the functions statements on a new set of data. // function prototype statement; void function1 ( int value1, int value2 ) ; void function1 ( int value1, int value2) { cout << "The first parameter is: " << value1 << endl; cout << "The second parameter is: " << value2 << endl; } int main( ) { // calculate different values int res1, res2; int res3, res4; int value1; ... // display the results function1 ( res1, res2 ); function1 ( res3, res4); Note: a variable name can be reused in a different scope ("part") of a program.