Create Presentation
Download Presentation

Download Presentation
## CS320n – Elements of Visual Programming

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**CS320n – Elements of Visual Programming**Assignment Help Session**What We Will Do Today**• Illustrate a few key points on the assignment and work on the assignment Assignment Help Session**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 Assignment Help Session**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 Assignment Help Session**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 Assignment Help Session**Index 0 1 2 3 4 5 6 7**Element 0 0 1 3 7 8 12 40 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? Assignment Help Session**Index 0 1 2 3 4 5 6 7**Element 0 0 1 3 8 8 12 40 Result is 4 Element at index 4 incremented by 1. Was 7, now is 8. Assignment Help Session**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 Assignment Help Session