Wednesday, June 1, 2011

June 1!!!

We user defined simple data and string types(last week) this week we are working with arrays.

In Chapter 8, there is a discussion of the "Rock, Paper, Scissors" game. Discuss how this game works, and how a C++ program that models this game will use a variety of types.

(may have done this wrong)

First it defines the object rock, paper, and scissor.
After that the function prototypes are defined.

Displayrules are called upon entering the game and display the Cout statements on page 446. 

Objecttype gets the keystroke that the user entered through a switch structure. It uses both uppercase and lowercase to decide. To passes the object that was selected to gameresults.

Gameresults, this calls winningobject to decide how the game should go; or, the truth table for the game.

After the truth table is found, it proceeds through game results first to see if the game is a tie, then it outputs each player’s choice. It then compares each player’s objects that they chose to the winningobject, via the convertenum function, and outputs the winner.

The convert enum function converts each of the enum defined(rock, paper, scissors) to something that can be recognized by C++(a cout statement)

Display results outputs the number of games played and who many times each player has won a game, the wins for player one is stored in wCount1 and the wins for player 2 is stored in wCount2. The loop for incrementing each counting sequence is in the main body of the program.






comment by instructor: Great job in breaking this down here, with "enum" in this case, would this be a function? How would this be defined?




my response
If I understand your question correctly, no, the:
enum objectType {rock, paper, scissors}
is no a function.

enum does nothing more than create a user defined data type.
So instead of
char rock, paper, scissors;
you have enum ObjecType {rock...ect

This is the reason you have to have a new function to "read" the data in the enum. Which is where the convert enum function comes into play(on page 449)

To define an enum data type use the following code:
enum TypeName {value1, value2, ect}

No comments:

Post a Comment