Question

Assignment C++: Rock-Scissor-Paper & Tic-Tac-Toe i need you to write two different program for RSP and...

Assignment C++: 
Rock-Scissor-Paper & Tic-Tac-Toe
i need you to write two different program for RSP and TTT:

R-S-P Requirement: 
- write one program that mimics the Rock-Scissor-Paper game. This program will ask user to enter an input (out of R-S-P), and the computer will randomly pick one and print out the result (user wins / computer wins). 
- User's input along with computer's random pick will be encoded in the following format:
-- user's rock:         10
-- user's scissor:      20
-- user's paper:        30
-- comp's rock:         1
-- comp's scissor:      2
-- comp's paper:        3
Then add user's input and computer's pick toghter to for a summation, and use switch statement over the summation to tell the result. For example, 12 (10 + 2: u's rock and c's scissor, user wins), 33 (30 + 3: u's paper and c's paper, draw). 

T-T-T Requirement: 
- write one program that uses two dimensional array to allow two players to play tic-tac-toe. The program asks for moves alternately from player X and player O to enter a number (1 - 9) they wish to makr to play the game.The program displays the game positions as follows: 
1 2 3
4 5 6
7 8 9
After each move, the program displays the changed board, for example: 
X X O
4 5 6
O 8 9
- the program should have following functions: 
-- a function to take in user's input. 
-- a function to print out the board and move. 
-- a function to tell if game is over. 
-- a function to tell who wins (or draw.)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>

#include<cstdlib>

#include<time.h>

using namespace std;

int main()

{

int program_value,totalValue;

int compChoice;

char user_value;

int user_ChoiceValue;

int winCount=0,lostCount=0,tieCount=0;

do

{

srand(0);

compChoice=rand()%3;

while(true)

{

cout<<" Choose: scissor (S),rock(R), paper(P) :";

cin>>user_value;

if(user_value=='R' || user_value=='S' || user_value=='P')

break;

else

cout<<"Bad Code..."<<endl;

}

if(user_value=='R')

user_ChoiceValue=10;

if(user_value=='S')

user_ChoiceValue=20;

if(user_value=='P')

user_ChoiceValue=30;

totalValue=compChoice+user_ChoiceValue;

switch(totalValue)

{

case 11: case 22: case 33:

if(totalValue==11)

cout<<" Computer is Rock. You are Rock Too. It is a tie"<<endl;

else if(totalValue==22)

cout<<" Computer is Scissor. You are Scissor Too. It is a tie"<<endl;

else

cout<<" Computer is Paper. You are Paper Too. It is a tie"<<endl;

break;

case 12:

cout<<" Computer is Scissor. You are Rock. You won because Rock crushes Scissors."<<endl;

break;

case 23:

cout<<" Computer is Paper. You are Scissor. You won because Scissor cuts the Paper."<<endl;

break;

case 31:

cout<<" Computer is Rock. You are Paper. You won because Paper covers Rock."<<endl;

break;

case 21:

cout<<" Computer is Rock. You are Scissor. You lost because Rock crushes Scissors."<<endl;

break;

case 32:

cout<<" Computer is Scissor. You are Paper. You lost because Scissor cuts the Paper."<<endl;

break;

case 13:

cout<<" Computer is Paper. You are Rock. You lost because Paper covers Rock."<<endl;

break;

}

while(true)

{

cout<<" Do you want to continue to play (Y yes and X No): ";

cin>>user_value;

if(user_value=='Y' || user_value=='X')

break;

else

cout<<"Bad Code..."<<endl;

}

}while(user_value!='X');

return 0;

}

ouptut

Tic Tac Toe game

Code

#include <iostream>

using namespace std;

//initialize the board

char borad[3][3] = {{'1','2','3'},

{'4','5','6'},

{'7','8','9'}};

int checkwin();

void board();

int main()

{

int player = 1,i,choice;

char sign;

do

{

board();//prints the bord

player=(player%2)?1:2;//choice of player

//taking numebr from the user

cout << "Player " << player << ", enter a number: ";

cin >> choice;

//specify which sign's turn

sign=(player == 1) ? 'X' : 'O';

//checking the choice and if that position is taken or not

//if postion is not taken and move is valid then place aproprriate sign

if (choice == 1 && borad[0][0] == '1')

borad[0][0] = sign;

else if (choice == 2 && borad[0][1] == '2')

borad[0][1] = sign;

else if (choice == 3 && borad[0][2] == '3')

borad[0][2] = sign;

else if (choice == 4 && borad[1][0] == '4')

borad[1][0] = sign;

else if (choice == 5 && borad[1][1] == '5')

borad[1][1] = sign;

else if (choice == 6 && borad[1][2] == '6')

borad[1][2] = sign;

else if (choice == 7 && borad[2][0] == '7')

borad[2][0] = sign;

else if (choice == 8 && borad[2][1] == '8')

borad[2][1] = sign;

else if (choice == 9 && borad[2][2] == '9')

borad[2][2] = sign;

//otherwise its an invalid move

else

{

cout<<"Invalid move ";

player--;

cin.ignore();

cin.get();

}

//checks for win

i=checkwin();

player++;

}while(i==-1);//loop till i is -1

board();

if(i==1)//if i is 1 then some one wins the game

cout<<"==>aPlayer "<<--player<<" win ";

else

cout<<"==>aGame draw";

cin.ignore();

cin.get();

return 0;

}

//FUNCTION TO RETURN GAME STATUS

//1 FOR GAME IS OVER WITH RESULT

//-1 FOR GAME IS IN PROGRESS

//O GAME IS OVER AND NO RESULT

int checkwin()

{

//cheks for same row or cloumn or sma diagonal

if (borad[0][0] == borad[0][1] && borad[0][1] == borad[0][2])

return 1;

else if (borad[1][0] == borad[1][1] && borad[1][1] == borad[1][2])

return 1;

else if (borad[2][0] == borad[2][1] && borad[2][1] == borad[2][2])

return 1;

else if (borad[0][0] == borad[1][0] && borad[1][0] == borad[2][0])

return 1;

else if (borad[0][1] == borad[1][1] && borad[1][1] == borad[2][1])

return 1;

else if (borad[0][2] == borad[1][2] && borad[1][2] == borad[2][2])

return 1;

else if (borad[0][0] == borad[1][1] && borad[1][1] == borad[2][2])

return 1;

else if (borad[0][2] == borad[1][1] && borad[1][1] == borad[2][0])

return 1;

else if (borad[0][0] != '1' && borad[0][1] != '2' && borad[0][2] != '3'

&& borad[1][0] != '4' && borad[1][1] != '5' && borad[1][2] != '6'

&& borad[2][0] != '7' && borad[2][1] != '8' && borad[2][2] != '9')

return 0;

else

return -1;

}

//FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS sign

void board()

{

system("cls");

cout << " Tic Tac Toe ";

cout << "Player 1 (X) - Player 2 (O)" << endl << endl;

cout << endl;

cout << " | | " << endl;

cout << " " << borad[0][0] << " | " << borad[0][1] << " | " << borad[0][2] << endl;

cout << "_____|_____|_____" << endl;

cout << " | | " << endl;

cout << " " << borad[1][0] << " | " << borad[1][1] << " | " << borad[1][2] << endl;

cout << "_____|_____|_____" << endl;

cout << " | | " << endl;

cout << " " << borad[2][0] << " | " << borad[2][1] << " | " << borad[2][2] << endl;

cout << " | | " << endl << endl;

}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Assignment C++: Rock-Scissor-Paper & Tic-Tac-Toe i need you to write two different program for RSP and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use di...

    18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Write . Displays the contents of the board array. . Allows player 1 to select a location on the board for an X. The program should ask the...

  • I need screenshots for this solution done in Flowgorithm. Thank you. Tic-Tac-Toe Game Design a program...

    I need screenshots for this solution done in Flowgorithm. Thank you. Tic-Tac-Toe Game Design a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional String array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: a. Displays the contents of the board array. b. Allows player 1 to select a location...

  • Write a program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a...

    Write a program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws. Here are sample runs: Enter your selection: scissor (0),...

  • I need to create a Tic Tac Toe program in C++. These are the requirements Write...

    I need to create a Tic Tac Toe program in C++. These are the requirements Write a program that allows the computer to play TicTacToe against a human player or allow two human players to play one another. Implement the following conditions: The player that wins the current game goes first in the next round, and their symbol is X. The other player will be O. Keep track of the number of games played, wins, and draws for each player....

  • (Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe....

    (Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enumeration to represent the value in each cell of the array. The enumeration’s constants should be named X, O and EMPTY (for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Allow two human players. Wherever the first player moves, place an X...

  • Please make this into one class. JAVA Please: Tic Tac Toe class - Write a fifth...

    Please make this into one class. JAVA Please: Tic Tac Toe class - Write a fifth game program that can play Tic Tac Toe. This game displays the lines of the Tic Tac Toe game and prompts the player to choose a move. The move is recorded on the screen and the computer picks his move from those that are left. The player then picks his next move. The program should allow only legal moves. The program should indicate when...

  • Write a java program that plays the popular scissor-rock-paper game. (A scissor can cut a paper,...

    Write a java program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a rock can break a scissor, and a paper can cover a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws. Allow the user to continue playing or quit.

  • I need help developing this app using java in android studio Assignment: Tic-Tac-Toe app User interface...

    I need help developing this app using java in android studio Assignment: Tic-Tac-Toe app User interface Operation The app allows the user to play a game of Tic-Tac-Toe. The user can click the New Game button at any time to start a new game. The app displays other messages to the user as the game progresses such as (1) whose turn it is, (2) if a player wins, and (3) if the game ends in a tie. Specifications The app...

  • Write a program to Simulate a game of tic tac toe in c#

    Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1)    ...

  • (Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an...

    (Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an available cell in a grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has achieved a win. Create...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT