CSCI 261 - Programming Concepts (C++)

Spring 2017 - Lab 07B

Quick Links: Blackboard | Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This lab is due by Tuesday, March 14, 2017 11:59pm.


Yahtzee Dice Sorter



For Friday's lab, checking if a Large Straight exists is certainly more difficult than checking if Chance exists. If we are able to sort our dice into increasing order, then it is much simpler to check if our five dice have values of 1, 2, 3, 4, and 5. For today's lab we will do just that - sort our five dice into ascending order.

To accomplish this task, we are going to write two functions. Find a partner, because today we'll be pair programming.

The first function should be called SwapDice . This function will take two integer parameters both passed by reference. The function returns nothing. The function will then compare the values of the two parameters (we'll call them a & b - you should use a more descriptive name). We need to swap the value of the two parameters so that a will have b's old value and b will have a's old value. Refer back to zyBooks Section 4.6 if you need some tips on swapping two variables.

The second function should be called SortDice . This function will take a five integer array as a parameter. The function returns nothing. We now need to determine the smallest value of the five dice and keep track of which die contains the smallest value. Once we have this information, we will swap the smallest die with die1. This will put the smallest value die into the first position of all our dice. We then repeat this process with the four remaining dice. Find the smallest value of the four dice and swap it with die2. At this point, die1 will be the smallest value and die2 will be the second smallest. Repeat this process for the third smallest and fourth smallest. Whichever die is left in position die5 will be the largest! (Hint: this is the selection sort again)

To test these functions, have the user has enter the values of five dice, call the SortDice function and then print the values of die1, die2, die3, die4, and die5 to verify that they are in ascending order.

We recommend writing out some pseudocode for how you are going to solve these problems - particularly sorting the five dice.


Lab Submission



You will submit your solution to this lab with the rest of Week07. Detailed instructions for doing this are posted in Assignment 07.


This lab is due by Tuesday, March 14, 2017 11:59pm.
Last Updated: 01/01/70 00:00


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0