Screenshot

Program
#include <iostream>
#include<string>
using namespace std;
#define ROWS 3
#define COLS 3
//Function prototypes
int getMenu();
void playGuessGame();
void playTicTacToe();
void getChoice(char[ROWS][COLS], bool);
void fillBoard(char[ROWS][COLS]);
void showBoard(char[ROWS][COLS]);
bool gameOver(char[ROWS][COLS]);
void checkPalindrome();
bool checkPalindrome(string);
string reverse(string);
string removeOther(string);
int main()
{
//Get option
int opt = getMenu();
//Loop until user prefer
while (opt != 0) {
if (opt == 1) {
playGuessGame();
}
else if (opt == 2) {
playTicTacToe();
}
else if (opt == 3) {
checkPalindrome();
}
cout << endl;
opt = getMenu();
}
}
/*
Function: getMenu
Param In: None
Param Out: opt, user choice;
Description: Display 3 different games and exit
option
Read user choice , check correctness and return option
*/
int getMenu() {
int opt;
cout << "1436 Gamee Menu\n";
cout << "----------------\n";
cout << "1. HI/LO Guessing \n2. Tic Tac Toe\n3.
Palindrome Checker\n0. Quit\n";
cout << "Enter your choice: ";
cin >> opt;
while (opt < 0 || opt>3) {
cout << "Error!!!Option
should be 0-3!!\n";
cout << "Enter your choice:
";
cin >> opt;
}
return opt;
}
/*
Function: playGuessGame
ParamIn: none
Param Out: none
Description: Prompt for user a number 1-100
If it correct congradulate
Otherwise mension low or high
*/
void playGuessGame() {
int num, secretNum = rand() % 100 + 1;
cout << "\nGuess the secret number between
1-100: ";
cin >> num;
if (num == secretNum) {
cout <<
"CONGRADULATIONS!!!YOUR GUESS IS CORRECT!!!\n";
}
else if (num <secretNum) {
cout << "OOPS!!!YOUR GUESS IS
LOW!!!\n";
}
else {
cout << "OOPS!!!YOUR GUESS IS
HIGH!!!\n";
}
}
/*
Function: playTicTacToe
Param In: none
ParamOut: none
Description: Create a 3*3 charcter board
Loop until a winner or tie happen
*/
void playTicTacToe() {
char board[3][3];
bool playerToggle = false;
fillBoard(board);
showBoard(board);
while (!gameOver(board))
{
getChoice(board,
playerToggle);
showBoard(board);
playerToggle = !playerToggle;
}
}
/*
Function: fillBoard
ParamIn: board
ParamOut: none
Description: Fill the array with stars
*/
void fillBoard(char gameboard[ROWS][COLS]) {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++)
{
gameboard[i][j]
= '*';
}
}
}
/*
Function: showBoard
ParamIn: board
ParamOut: None
Description: Display board details
*/
void showBoard(char board[ROWS][COLS]) {
cout << " ";
for (int i = 0; i < COLS; i++) {
cout << i + 1 << "
";
}
cout << endl;
for (int i = 0; i < ROWS; i++) {
cout << i + 1 << "
";
for (int j = 0; j < COLS; j++)
{
cout <<
board[i][j] << " ";
}
cout << endl;
}
};
/*
Function: getChoice
Paramin: board and bool value
ParamOut: None
Desription: Get player choice row and col
Check availability and add into board
*/
void getChoice(char gameBoard[ROWS][COLS], bool playerToggle)
{
string player;
char c;
int row, col;
if (playerToggle == false) {
player = "player 1";
c = 'X';
}
else {
player = "player 2";
c = 'O';
}
do
{
do
{
cout <<
player << ", " << "Row: ";
cin >>
row;
} while (!(row >= 1 && row <= 3));
do
{
cout <<
player << ", " << "Column: ";
cin >>
col;
} while (!(col >= 1 &&
col <= 3));
} while ((gameBoard[row - 1][col - 1] == 'X' ||
gameBoard[row - 1][col - 1] == 'O'));
gameBoard[row - 1][col - 1] = c;
}
/*
Function: gameOver
Paramin: board
Param out: winner
Description: check the rowwise or column sie or diagonal match of
player character
If match foundreturn true otherwise false
*/
bool gameOver(char gameBoard[ROWS][COLS])
{
bool gameOver = false;
bool asterisk = false;
bool xWin = false;
bool oWin = false;
bool Tie = false;
//xwin check
if (gameBoard[0][0] == 'X' && gameBoard[0][1]
== 'X' && gameBoard[0][2] == 'X')
{
xWin = true;
}
else if (gameBoard[1][0] == 'X' &&
gameBoard[1][1] == 'X' && gameBoard[1][2] == 'X') {
xWin = true;
}
else if (gameBoard[2][0] == 'X' &&
gameBoard[2][1] == 'X' && gameBoard[2][2] == 'X') {
xWin = true;
}
else if (gameBoard[0][0] == 'X' &&
gameBoard[1][0] == 'X' && gameBoard[2][0] == 'X') {
xWin = true;
}
else if (gameBoard[0][1] == 'X' &&
gameBoard[1][1] == 'X' && gameBoard[2][1] == 'X') {
xWin = true;
}
else if (gameBoard[0][2] == 'X' &&
gameBoard[1][2] == 'X' && gameBoard[2][2] == 'X') {
xWin = true;
}
else if (gameBoard[0][0] == 'X' &&
gameBoard[1][1] == 'X' && gameBoard[2][2] == 'X') {
xWin = true;
}
else if (gameBoard[0][2] == 'X' &&
gameBoard[1][1] == 'X' && gameBoard[2][0] == 'X') {
xWin = true;
}
//owin check
if (gameBoard[0][0] == 'O' && gameBoard[0][1]
== 'O' && gameBoard[0][2] == 'O')
{
oWin = true;
}
else if (gameBoard[1][0] == 'O' &&
gameBoard[1][1] == 'O' && gameBoard[1][2] == 'O') {
oWin = true;
}
else if (gameBoard[2][0] == 'O' &&
gameBoard[2][1] == 'O' && gameBoard[2][2] == 'O') {
oWin = true;
cout << "Player 2
wins!";
}
else if (gameBoard[0][0] == 'O' &&
gameBoard[1][0] == 'O' && gameBoard[2][0] == 'O') {
oWin = true;
}
else if (gameBoard[0][1] == 'O' &&
gameBoard[1][1] == 'O' && gameBoard[2][1] == 'O') {
oWin = true;
}
else if (gameBoard[0][2] == 'O' &&
gameBoard[1][2] == 'O' && gameBoard[2][2] == 'O') {
oWin = true;
}
else if (gameBoard[0][0] == 'O' &&
gameBoard[1][1] == 'O' && gameBoard[2][2] == 'O') {
oWin = true;
}
else if (gameBoard[0][2] == 'O' &&
gameBoard[1][1] == 'O' && gameBoard[2][0] == 'O') {
oWin = true;
}
if (xWin == true) {
cout << "Player 1
wins!";
}
if (oWin == true) {
cout << "Player 2
wins!";
}
else // Otherwise both are tie!!!
{
for (int i = 0; i < ROWS;
i++) {
for (int j = 0;
j < COLS; j++) {
if (gameBoard[i][j] == '*') {
asterisk = true;
}
}
}
Tie = !asterisk;
if (Tie) {
cout <<
"Tie!";
}
}
gameOver = Tie || xWin || oWin;
return gameOver;
}
/*
Function: checkPalindrome
ParamIn: none
ParamOut: None
Description: Prompt for a word or phrase
Display palindrome or not
*/
void checkPalindrome() {
string word;
cin.ignore();
cout << "\n a word or phrase to check
palindrome(or q to quit): ";
getline(cin, word);
//If palindrome
if (checkPalindrome(word)) {
cout << word << " is
palindrome!!" << endl;
}
//Otherwise
else {
cout << word << " is
not palindrome!!" << endl;
}
}
/*
Function to check palindrome
Param In: word, string to check
Param Out: True/False
*/
bool checkPalindrome(string word) {
if (removeOther(word) == removeOther(reverse(word)))
{
return true;
}
return false;
}
/*
Function to reverse a string
Param In: word, String to reverse
Param Out: reversed string
*/
string reverse(string word) {
string reverseString = "";
for (int i = word.length() - 1; i >= 0; i--)
{
reverseString += word[i];
}
return reverseString;
}
/*
Function: removeOther
Param In: Stringto rempve
ParamOut: removed string
Description: Function to remove all characters other than letters
and numbers
and change all alphabets into lowercase
*/
string removeOther(string word) {
string temp = "";
for (int i = 0; i < word.length(); i++) {
if (isalpha(word[i])) {
temp +=
tolower(word[i]);
}
else if (isdigit(word[i])) {
temp +=
tolower(word[i]);
}
}
return temp;
}
Output
1436 Gamee Menu
----------------
1. HI/LO Guessing
2. Tic Tac Toe
3. Palindrome Checker
0. Quit
Enter your choice: 1
Guess the secret number between 1-100: 24
OOPS!!!YOUR GUESS IS LOW!!!
1436 Gamee Menu
----------------
1. HI/LO Guessing
2. Tic Tac Toe
3. Palindrome Checker
0. Quit
Enter your choice: 2
1 2 3
1 * * *
2 * * *
3 * * *
player 1, Row: 1
player 1, Column: 1
1 2 3
1 X * *
2 * * *
3 * * *
player 2, Row: 2
player 2, Column: 1
1 2 3
1 X * *
2 O * *
3 * * *
player 1, Row: 1
player 1, Column: 2
1 2 3
1 X X *
2 O * *
3 * * *
player 2, Row: 2
player 2, Column: 2
1 2 3
1 X X *
2 O O *
3 * * *
player 1, Row: 1
player 1, Column: 3
1 2 3
1 X X X
2 O O *
3 * * *
Player 1 wins!
1436 Gamee Menu
----------------
1. HI/LO Guessing
2. Tic Tac Toe
3. Palindrome Checker
0. Quit
Enter your choice: 3
a word or phrase to check palindrome(or q to quit):
Malayalam
Malayalam is palindrome!!
1436 Gamee Menu
----------------
1. HI/LO Guessing
2. Tic Tac Toe
3. Palindrome Checker
0. Quit
Enter your choice: 4
Error!!!Option should be 0-3!!
Enter your choice: 0
in c++ please Page 1 of 3 (PRO) Project Assignment Instructions Last Charged: 6/1/2020 Read and...
CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...
Help please, write code in c++. The assignment is about making a hangman game. Instructions: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This...
I need help writing these 2 programs please include all the indents :) In this programming challenge you are to create two Python programs: randomwrite.py andrandomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program...
The purpose of this assignment is to get experience with an
array, do while loop and read and write file operations.
Your goal is to create a program that reads the exam.txt file
with 10 scores. After that, the user can select from a 4 choice
menu that handles the user’s choices as described in the details
below. The program should display the menu until the user selects
the menu option quit.
The project requirements:
It is an important part...
Project Lists and Object-oriented Programming Note: using c++ This project is an individual assignment that focuses on object-oriented programming and lists. The list will be a doubly-linked list and it will be implemented using nodes and pointers. The data contained in the list will be objects from a class. Project data: You will choose one of the following classes to define: Boat, Earthquake, Game, Sport, State, Website, House, Phone, Activist, Plant, Fish, Parrot, and Course. Your class code will include...
For this assignment you are to create two programming projects. The first should have a project directory with Lab02-2WriteNumbers and the second should have a project directory with Lab02-2ReadNumbers. Lab02-03WriteNumbers – Write a program that asks the user to enter five numbers. Use a double data type to hold the numbers. The program should create a file and save all five numbers to the file. Enter a number (1 of 5): 45 Enter a number (2 0f 5): 23 Enter...
FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...
COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning Outcome #2: Create and utilize arrays to store lists of related data Programming Problem You have been hired to create a C++ program to simulate the lottery. Your program allows users to see how often their lottery number choices match a randomly generated set of numbers used to pick lottery winners. The company, "How Lucky Are You?, Inc." wants a modular, professional and user-friendly...
Please help with this exercises in c++ language
Thanks
Lab Activity #5-More Functions/FILES Exercise# Write a program that will generate 1000 random numbers (all of which are between 10 and 20) and then write all of the even numbers (from those 1000 numbers) to a new file called "myEvenRandoms.txt Exercise #2 (DO ONLY IF WE COVERED ARRAYS OF CHARACT Write a program that will ask the user to enter a sentence. Then create a separate function that will count the...
For this assignment you are to create two programming projects. The first should have a project directory with Lab02-2WriteNumbers and the second should have a project directory with Lab02-2ReadNumbers. Lab02-03WriteNumbers – Write a program that asks the user to enter five numbers. Use a double data type to hold the numbers. The program should create a file and save all five numbers to the file. Enter a number (1 of 5): 45 Enter a number (2 0f 5): 23 Enter...