CS228 QUIZ 1 SOLUTION --------------------- 1. correct answer 3 pts correct tree 2 pts(approximately correct 1pt) Answer: (i) - / \ + / / \ / \ % * 6 2 / \ / \ 3 2 5 2 (ii) 8 2. basic structure 3 pts "break" 1 pt syntax 1 pt Answer: ... switch(n){ case 1: cout << "You are number ONE\n"; break; case 2: cout << "You are number TWO\n"; break; default: cout << "You did not win the contest\n"; break; } 3. "include" 1 pt while loop 2 pts for loop 2 pts declare, init... 2 pts correctness 3 pts Answer: #include int main() { int num = 0, sum = 0; cout << "Enter number to be summed(1 to num, negative to quit)\n"; cin >> num; while(num >= 0){ sum = 0; for(int i = 0; i <= num; i++) sum += i; cout << "The sum of the numbers from 0 to " << num << "is equal to " << sum << endl; cout << "Enter next number, negative to quit"; cin >> num; } cout << "BYE!" << endl; return 0; } 4. how many times 2 pts output 3 pts Answer: times: 6 output: IENLPA