1 / 10

CMPUT 101 Lab #3

CMPUT 101 Lab #3. September 24, 2007 14:00 – 17:00. Guido: Adding numbers. Today work: A program that lets GvR add two 3-digit numbers using 10 based representation. Follow the step in the lab exercise 3. Step 1. Load worlds: lab_3_one_a.wld -- single digit without carry

Télécharger la présentation

CMPUT 101 Lab #3

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. CMPUT 101Lab #3 September 24, 2007 14:00 – 17:00

  2. Guido: Adding numbers • Today work: • A program that lets GvR add two 3-digit numbers using 10 based representation. • Follow the step in the lab exercise 3

  3. Step 1 • Load worlds: • lab_3_one_a.wld -- single digit without carry • lab_3_one_b.wld – single digit with carry

  4. Step 2 & 3 • Load provided program: • lab_3a.gvr • Make sure the program works • Copy/paste may cause spacing problem • By executing it, the robot will be just turned off • Add your code in the space provided

  5. Step 4 • Program a robot to add two single digit numbers. • Consider to use move_south, move_north, move_east, move_west, and add_digit_to_bag provided in the initial program • Define a new sub routine as: add_two_digits (Suggestion) • Don’t worry about the carry yet – GvR just keeps all beepers in his bag. • Test on the worlds in Step 1. Demo -- lab_3a_4.gvr

  6. Step 5 • Think about the carry  • Adding two numbers always give either 0 or 1 carry --- why ? • Consider in the largest possible • 999 + 999 = 1998 • the largest sum: 9 + 9 + 1 = 19 -- also 1 carry out

  7. Step 6 • After adding two digits, GvR will have some number in the range 0…19 of beepers • Check for carry • try 9 times to drop a beeper • If there is still a beeper in a bag, then there is a carry out. • Otherwise, there is no carry out.

  8. Step 7 • no_carry_out • The sum result should be the right place • No need to do extra steps • So, just move the robot to the next column (1E, 3N, 1E) • carry_out • Pick up all beepers. • Move south to drop 9 beepers in the garbage space. • Move 2 west and 1 north to drop 1 beeper (carry). • Move 2 east back to drop the all beepers in the bag. • Demo lab_3a_7.gvr

  9. Step 8 • Repeat 2 more times to add 3 digits • Be sure to pick up the carry if there is one before computing the next sums. • Demo lab_3a_complete.gvr

  10. Demo • Demo your final program on: • lab_3a.wld: 372 + 863 = 1235 • lab_3b.wld: 30 + 13 = 43 • lab_3c.wld: 823 + 192 = 1015

More Related