Computer Science 1 - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Computer Science 1

Description:

Computer Science 1. 10/16/06. Welcome Back. What linear constructs do you recall? ... Yahtzee: Model rolling five dice until you get a Yahtzee, count how many turns ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 6
Provided by: skps
Category:

less

Transcript and Presenter's Notes

Title: Computer Science 1


1
Computer Science 1
  • 10/16/06

2
Welcome Back
  • What linear constructs do you recall?
  • Decision constructs??
  • Looping constructs???
  • When would use these??
  • Today
  • Review repeat..until
  • Dry run
  • Fix it
  • Work on program from last Tuesday ( Push)

3
Dry run sample
  • program dr10_16
  • var
  • a,b,cinteger
  • begin
  • b2
  • a 10
  • repeat
  • c 3a - 10
  • b b1
  • writeln(a6, b6, c6)
  • a a c div b
  • until (agt25)
  • writeln(a6, b6, c6)
  • end

Write the variable names and how they change and
what shows on the screen.
4
Fix the following
  • \\west\transfer\Smith\ComputerScience1\fixpair.pa
    s
  • program Pairs!
  • This program will count how many rolls it
    takes to
  • get a pair
  • begin
  • writeln('Time to roll for pairs')
  • repeat
  • random(6) 1
  • random(6) 1
  • if roll pair then
  • writeln( pair)
  • end Of the repeat
  • writeln('It took roll ' rolls 'to get a
    pair')
  • end

Open the file from the transfer folder and save
it on your c drive for testing.
5
Program options
  • Guessing game. Implement the guessing game, but
    also include showing how many guesses it took the
    user to guess the number. The computer picks a
    number (1-100) and you guess it. The computer
    needs to tell you if your guess is high or low.
    When you guess it correctly, the computer shows
    how many guesses it took. Push Write a program
    where the computer guesses the number you enter.
  • Ulams conjecture If you take any positive
    integer greater than one. If it is even you
    divide it by two, if it is odd, you multiply it
    by 3 and add 1. When you continue this process,
    you will eventually get down to 1. Write a
    program to verify or disprove this conjecture.
  • Bridge Walker A person is in the middle of an 8
    bridge. They are equally likely to take a 1
    step to the right as they are to take a 1 step
    to the left. Write a program that will model
    this person walking back and forth on the bridge
    until they fall off. Then tell which side of the
    bridge they fell from and how many total steps it
    took.
  • Yahtzee Model rolling five dice until you get a
    Yahtzee, count how many turns it took to get
    Yahtzee on the first roll. (All five dice
    matching)
Write a Comment
User Comments (0)
About PowerShow.com