Specifying Algorithms - Introduction to Computer Science | CMSI 182, Assignments of Computer Science

Material Type: Assignment; Class: Intro Computer Science; Subject: Computer Science; University: Loyola Marymount University; Term: Fall 2007;

Typology: Assignments

Pre 2010

Uploaded on 08/17/2009

koofers-user-290
koofers-user-290 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSI 182
IN T R O D U C T I O N T O CO M P U T E R SC I E N C E
Fall 2007
Assignment 1108
Alright, time to get our hands dirty with specifying algorithms.
Not for Submission
Read Chapter 5 in the Brookshear book.
For Submission
Specify the following algorithms using pseudocode:
1. The algorithm for converting any number from
0 to 255 into 8-bit binary. This algorithm can
be thought of as:
convertTo8Bit(number)
…where number is the number to be converted,
and the result is that number’s corresponding
8-bit binary representation.
Make sure that the algorithm detects whether
number is within range in the first place (i.e.,
number should range from 0 to 255).
2. An algorithm for “simulating” the three-door
puzzle discussed in class today. The algorithm
can be thought of in this way:
simulateDoorGame(trialCount, switchDoors)
…where trialCount is the number of times that
the game is to be played, and switchDoors indi-
cates whether or not this simulation should
switch doors or not. The result of the algo-
rithm is the number of times that the “player”
chose the winning door.
Submit the pseudocode on hardcopy. Make sure to
format your pseudocode with the right indents so
that structures such as conditionals and repetitions
are easy to see.
Extra Credit
You will receive extra credit if you do next week’s
assignment in advance: convert your pseudocode
into a JavaScript function that can be run using the
JavaScript scratch page on the course Web site.

Partial preview of the text

Download Specifying Algorithms - Introduction to Computer Science | CMSI 182 and more Assignments Computer Science in PDF only on Docsity!

CMSI 182

I N T R O D U C T I O N T O C O M P U T E R S C I E N C E

Fall 2007

Assignment 1108

Alright, time to get our hands dirty with specifying algorithms.

Not for Submission

Read Chapter 5 in the Brookshear book.

For Submission

Specify the following algorithms using pseudocode:

  1. The algorithm for converting any number from 0 to 255 into 8-bit binary. This algorithm can be thought of as: convertTo8Bit(number) …where number is the number to be converted, and the result is that number’s corresponding 8-bit binary representation. Make sure that the algorithm detects whether number is within range in the first place (i.e., number should range from 0 to 255).
  2. An algorithm for “simulating” the three-door puzzle discussed in class today. The algorithm can be thought of in this way: simulateDoorGame(trialCount, switchDoors) …where trialCount is the number of times that the game is to be played, and switchDoors indi- cates whether or not this simulation should switch doors or not. The result of the algo- rithm is the number of times that the “player” chose the winning door. Submit the pseudocode on hardcopy. Make sure to format your pseudocode with the right indents so that structures such as conditionals and repetitions are easy to see.

Extra Credit

You will receive extra credit if you do next week’s assignment in advance: convert your pseudocode into a JavaScript function that can be run using the JavaScript scratch page on the course Web site.