Hands On Arrays 2


Sorting Arrays and 2 dimensional arrays Arrays with Function calls

Step 1

  1. Create a function to enter a list of up to 25 quiz scores in array. A negative number indicates the end.
  2. Create a function to print the grade list back out.
  3. Write a main program to do the two functions above

Step 2

  1. Create a function to remove the low score of an array
  2. Enter the scores
  3. remove the two lowest grades.
  4. Print the reduced list back out.

Step 3

  1. Create a function "void lowest(int a[], int start, int size)" to scan from the ith position in an array to the end of the array, returning the index the lowest entry in the range.
  2. Create a function "void sort(int a[], int size)" to use the lowest function to scan through each element in the array, swapping the ith lowest value into the ith position.
  3. Use the routines from earlier to test the sort function

Step 4

  1. Consider the game Tic Tac Toe. How could a game be represented? Represent as a two dimensional array of char.
  2. Manually create an Tic Tac Toe with the following:
    X O
    X O
    O X
  3. Write a function "void displayBoard(char board[][3])" to display a Tic Tac Toe game state.
  4. Write a function "void nextMove(char player, char board[][3])" to ask a user for the row and column of a move. player will be 'X' or 'Y', and the program will check is the move is legal.
  5. Write a main program to allow two plays to play, starting with a blank board, and alternating between X and O turns.
  6. Write a routine "bool checkDone(char board[][3], char& winner)" to check for winner. Return true if there is a winner, and return winner ("X" or "O") in winner.

This topic: SCMP118 > Main > Fall2017 > HandsOnArray3
Topic revision: r1 - 2017-10-02 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback