1 / 14

ICS 3U – Test #2

ICS 3U – Test #2. Solutions. Part A – Multiple Choice. C (0+1, 1+1, 2+1, 3+1 = 1, 2, 3, 4) C sum >= 100 (opposite needs the =) B (A needs == … the others are assignment statements)

clovis
Download Presentation

ICS 3U – Test #2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ICS 3U – Test #2 Solutions

  2. Part A – Multiple Choice • C (0+1, 1+1, 2+1, 3+1 = 1, 2, 3, 4) • C sum >= 100 (opposite needs the =) • B (A needs == … the others are assignment statements) • 20 and 20  the third line makes numbers[1] = 20, so in the fourth line 20 is then assigned again to numbers[2] • B 11 times [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) • B i is assigned the value of 11, checks the condition and then exits the loop, so when outputting after the loop it would output 11

  3. Part A – Multiple Choice (con’t) 7. A – index 8. 20 – the index values go from 0 to 19 (loop stops when a = 20) 9. E – cannot be determined – it depends on the random numbers generated 10. D – none of the above (the outside loop is executed 9 times, the inside loop executes 4 times (for every execution of the outside loop) 9 * 4 = 36 … loopy is outputted 36 times!)

  4. Part B – Code Tracing #1a

  5. Part B – Tracing # 1b

  6. Part B – Tracing # 2 This code sorts the student names alphabetically from A to Z It compares the first two names, if the second name is less than (alphabetically first) it switches the two names. Then it compares the second and third names ... Then the third and fourth names, etc.

  7. Part C – Code Writing #1 birthmonth = parseInt(txtInput_text.text); for (i = 0; i <= 20; i++) { if (BirthMonths[i] == birthmonth) { trace(StudentNames[i]); } }

  8. Part C – Code Writing #2 // loop for numbers 1 to 1000 for (num = 1; num <= 1000; num++) { // inside loop need to: // separate number into digits // check divisible by 3 // check prime // if statement to determine output //reset boolean variables }

  9. Part C – Code Writing #2 // separate digits onesdigit = num % 10; tensdigit = num / 10 % 10; hundredsdigit = num / 100; if (onesdigit == 3) || (tensdigit == 3) || hundredsdigit == 3) { contain3 = true }

  10. Part C – Code Writing #2 // divisible by 3 if (num % 3 == 0) { div3 = true; }

  11. Part C – Code Writing #2 // is Prime? numfactors = 0 for (i = 1; i <= num; i ++) { if (num % i == 0) { numfactors ++; } } if (numfactors == 2) { prime = true; }

  12. Part C – Code Writing #2 // output buzz, bizz-buzz or number if (prime && contain3) { trace( “bizz-buzz”); } else if (prime || contain3 || div3) { trace(“buzz”) } else { trace (num) }

  13. Part C – Code Writing #2 // reset boolean variables prime = false; div3 = false; contain3 = false;

More Related