Skip to main content

Exercises 15.15 Exercises

1.

Define an enum called Direction Examine the TEST_CASE to figure out the members it should have and the order they should be defined in.

2.

Write the functions colorToString. It should take a value of the provided Color struct and return a string.

3.

Use the given enumerations to write a function Result getResult(Choice player1, Choice player2) . It should determine the winner of a round of Rock, Paper, Scissors between two players (Rock beats Scissors, Scissors beats Paper and Paper beats Rock). Return WIN if player1 wins, LOSE if player1 loses or DRAW if there is no winner.
Hint.
There are various ways to try to be clever, but the most straightforward approach is to use nested ifs. Use the order of the CHECKS as a guide.

4.

Define a struct named Team. A team is identified by a name (string) and numbers of losses and of wins (ints).

5.

Write the function bool before(const Date& d1, const Date& d2). It should return true if d1 is before d2. Return false if they are the same or d2 comes first.

6.

Write the function midPoint. It should take two Points and return a new Point that is halfway between them.

7.

Write the modifying function flip. It should take a Point and modify it be swapping its x and y values.
Hint.
You probably need a temporary variable to hold one value while you do the swap.

8.

Complete the function maxY. It should return the largest y value of any of the points in the vector it is given.

9.

A player in a word game has a set of tiles. Each tile has a value and a letter. Complete the function bool hasTile(const Player& p, char c) that returns true if the given player has at least one tile with the same letter as c. Otherwise return false.
Hint.
If you are stuck, start by just writing a loop to print out the letter of each tile the player has. Once you have that working, then worry about checking each one to see if it is a match for c.
You have attempted of activities on this page.