Lab 7 Solution

$30.00

Category: Tag:

Description

Introduction:

Recall that at the beginning of every C++ program you type the line “int main ()” or something similar. Whether or not you knew it, you’ve been defining a function called main, saying that it will return an int value, and saying that it will not be passed any values. This is because every C++ program must have a main function but they can include many more.

Functions let us separate out small sections of code so that we can invoke those lines with a single name rather than having to retype them. Every function needs 3 things:

  1. A unique name or more accurately a unique signature. It’s possible for two functions to have the same name if they have different parameters but this is something we’ll study more later. For now every function should have a unique name.

  1. A return type. This can be of any variable type or the voidtype which tells the compiler that the function will not return a value. A function can only return one value in C++.

  1. A parameter list. These are values that are given to the function, that it will be able to process. Passing a variable to a function usuallycreates a new instance of that value and does not alter the original variable.

The purpose of today’s lab is to familiarize you with the definition and invocation of functions.

Directions:

1- Launch Code::Blocks and open the provided your_last_name_lab7.cpp. Rename it with the appropriate name.

2-Fill in the standard header for this lab:

//Your Name

//CS1428

//Lab 7

3- Your assignment is to build a simple game of Rock, Paper, Scissors. The rules of the game are:

  1. Both players choose either Rock, Paper, or Scissor.

  1. The winner is chosen by:

    1. Rock beats Scissors

    1. Scissors beat Paper

    1. Paper beats Rock

  1. Winning a round is worth one point.

  1. To make the game more interesting your implementation will not allow a tie.

4- The main function has been provided. Do not make any changes to it. Instead you will fill in the four empty functions:

char pickPlayerMove();

char pickComputerMove(char);

char decideWinner(char, char);

void printScore(int, int);

Specific instructions for each function are in the code comments. Your implementation should be fair and follow the rules of the game.

5- Build and Run your code. Correct any errors. You should see something like this:

11- Submit your .cpp through TRACS. You can leave when you’re done.


error: Content is protected !!