CS320n - PowerPoint PPT Presentation

About This Presentation
Title:

CS320n

Description:

What We Will Do Today. Illustrate a few key points on the assignment and ... 1 two, 3 threes, 7 fours... Assume the next roll is a 4. How does array change? ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 9
Provided by: sco1
Category:
Tags: cs320n | fours

less

Transcript and Presenter's Notes

Title: CS320n


1
CS320n Elements of Visual Programming
  • Assignment Help Session

2
What We Will Do Today
  • Illustrate a few key points on the assignment and
    work on the assignment

3
The Assignment
  • Simulate rolling two 6 sided dice
  • Allow user to input number of times to roll
  • numeric control
  • this will be input to for loop count terminal
  • inside for loop
  • need to simulate rolling dice once
  • need to count up how many times each result
    occurs
  • can use an array to do this

4
Counting Number of Rolls
  • One approach
  • One way of counting number of times each value
    rolled
  • store all results in an array
  • go through array and count number of 2s, then
    number of 3s, then number of 4s
  • A reasonable function would be how many elements
    of an array equal some value, but there is no
    LabVIEW function for this

5
Mapping
  • Another approach
  • A useful technique in programming
  • instead of using an array to hold the results of
    the roll, use an array to count the number of
    times each roll occurs
  • the index of the array is used to map to the
    result of a roll

6
Sample Array
use result of roll as index into array
element indicates how many time that roll has
occurred. 1 two, 3 threes, 7 fours Assume the
next roll is a 4. How does array change?
7
Result is 4
Element at index 4 incremented by 1. Was 7, now
is 8.
8
Using Mapping
  • To use mapping auto indexing is not useful when
    rolling the dice and counting the results
  • Need to use a shift register to pass whole array
    between iterations of the loop
  • need to use the Index Array to get old value of
    element, increment it (add 1), and then use the
    Replace Array Subset function to update the
    element
Write a Comment
User Comments (0)
About PowerShow.com