Overview: In this course, you will be responsible for completing a number of programming-based assignments by filling in the missing pieces of code. Learning to program in C++ requires developing an understanding of general programming concepts and learning the syntax of the C++ programming language. These exercises will build on each other and help you cultivate you programming knowledge. It is recommended that students do not limit their practice to just that which is graded. The more you write your own code, the more proficient you will become with the tools and techniques available to you in C++. Prompt: Your submission should include your completed source code. The following critical elements should be addressed in your project submission: • Code Description: A brief explanation of the code and a brief discussion of any issues that you encountered while completing the exercise. • Functioning Code: A source code must meet its specifications and behave as desired. To develop proper code, you should produce fully functioning code (produces no errors) that aligns with accompanying annotations. You should write your code in such a way that the submitted file(s) actually executes, even if it does not produce, the correct output. You will be given credit for partially correct output that can actually be viewed and seen to be partially correct. • Code Results: Properly generated results establishes that your source code: A. Generates accurate output B. Produces results that are streamlined, efficient, and error-free • Annotation / Documentation: All added code should also be well commented. This is a practiced “art” that requires striking a balance between commenting everything, which adds a great deal of unneeded noise to the code, and commenting nothing. Well-annotated code requires you to: A. Explain the purpose of lines or sections of your code detailing the approach and method the programmer took to achieve a specific task in the code B. Document any section of code that is producing errors or incorrect results. • Style and Structure: Part of the lesson to be learned in this course is how to write code that is clearly readable and formatted in an organized manner. To achieve this, you should: A. Develop logically organized code that can be modified and maintained; B. Utilize proper syntax, style, and language conventions/best practices Guidelines for Submission: For each exercise, your submission is the completed source code file containing functioning code and should start with a header comment containing a title (name, course, date, project number) and your discussion of the code.
// TicTacToe.cpp: Follow along with the comments to create a fully functional Tic Tac Toe game
// that uses function calls. Each function will get called multiple times during the execution
// of the code, however, the code itself only needed to be written once. Also notice the use of
// an array to store the contents of the board. The comments marked with a TODO denote where code
// needs to be added.
#include "stdafx.h"
#include <iostream>
using namespace std;
char boardTile[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
//Write the function declarations
bool checkValidMove(int);
void drawBoard();
//TODO: Write the declaration for the function that checks for a winner
int main()
{
int player = 1, i, choice;
char mark;
bool isMoveValid = false;
do
{
//TODO: Call the function that draws the game board
player = (player % 2) ? 1 : 2;
cout << "Player " << player << ", enter a number: ";
cin >> choice;
mark = (player == 1) ? 'X' : 'O';
//TODO: Call the checkValidMove function, make sure to save the return value in one of the variables
if (isMoveValid){
boardTile[choice] = mark;
}
else{
cout << "Invalid move ";
player--;
cin.ignore();
cin.get();
}
i = checkForWinner();
player++;
} while (i == -1);
drawBoard();
if (i == 1)
cout << "==>Player " << --player << " wins!";
else
cout << "==>Game draw";
cin.ignore();
cin.get();
return 0;
}
// Check the board for a winner.
// Returning a -1 is keep playing
// Returning a 0 is a draw (or cat wins)
// Returning a 1 shows a winner
int checkForWinner()
{
//TODO: Read through the code in this function. Based on the commented rules before the function, determine
//what type of return statement belongs in each of the comments below.
if ((boardTile[1] == boardTile[2] && boardTile[2] == boardTile[3])
|| (boardTile[4] == boardTile[5] && boardTile[5] == boardTile[6])
|| (boardTile[7] == boardTile[8] && boardTile[8] == boardTile[9])
|| (boardTile[1] == boardTile[4] && boardTile[4] == boardTile[7])
|| (boardTile[2] == boardTile[5] && boardTile[5] == boardTile[8])
|| (boardTile[3] == boardTile[6] && boardTile[6] == boardTile[9])
|| (boardTile[1] == boardTile[5] && boardTile[5] == boardTile[9])
|| (boardTile[3] == boardTile[5] && boardTile[5] == boardTile[7]))
{
//Insert return statement
}
else if (boardTile[1] != '1' && boardTile[2] != '2' && boardTile[3] != '3'
&& boardTile[4] != '4' && boardTile[5] != '5' && boardTile[6] != '6'
&& boardTile[7] != '7' && boardTile[8] != '8' && boardTile[9] != '9')
{
//Insert return statement
}
else
{
//Insert return statement
}
}
// Draw the board with the player marks
void drawBoard()
{
system("cls");
cout << "\n\n\tTic Tac Toe\n\n";
cout << "Player 1 has 'X' - Player 2 has 'O'" << endl << endl;
cout << endl;
cout << " | | " << endl;
cout << " " << boardTile[1] << " | " << boardTile[2] << " | " << boardTile[3] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << boardTile[4] << " | " << boardTile[5] << " | " << boardTile[6] << endl;
cout << "_____|_____|_____" << endl;
cout << " | | " << endl;
cout << " " << boardTile[7] << " | " << boardTile[8] << " | " << boardTile[9] << endl;
cout << " | | " << endl << endl;
}
//Check if the player's move is valid or if the tile has already been taken
//TODO: Based on the function initiation at the beginning of the program, write the function signature, make sure the variable names are consistent
{
bool isValid = false;
char aChar = '0' + choice;
if (choice > 0 && choice <= 9){
if (boardTile[choice] == aChar){
isValid = true;
}
}
return isValid;
}
The palce where i added the code i put a cooment statement like
"// this is addeded as per the question requirement"
source code:-
#include "stdafx.h"
#include <iostream>
using namespace std;
char boardTile[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8',
'9' };
//Write the function declarations
bool checkValidMove(int);
void drawBoard();
int checkForWinner(); // this was added
//TODO: Write the declaration for the function that checks for a
winner
int main()
{
int player = 1, i, choice;
char mark;
bool isMoveValid = false;
do
{
//TODO: Call the
function that draws the game board
drawBoard(); // this is
addeded as per the question requirement
player = (player % 2) ?
1 : 2;
cout << "Player "
<< player << ", enter a number: ";
cin >>
choice;
mark = (player == 1) ?
'X' : 'O';
//TODO: Call the
checkValidMove function, make sure to save the return value in one
of the variables
// this is addeded as
per the question requirement
checkValidMove(choice);
//bool isMoveValid =
checkValidMove;
cout <<
"checkValidMove is " << std::boolalpha <<
checkValidMove; // TEST
if (isMoveValid) {
boardTile[choice] = mark;
}
else {
cout << "Invalid move ";
player--;
cin.ignore();
cin.get();
}
i =
checkForWinner();
player++;
} while (i == -1);
drawBoard();
if (i == 1)
cout <<
"==>Player " << --player << " wins!";
else
cout <<
"==>Game draw";
cin.ignore();
cin.get();
return 0;
}
// Check the board for a winner.
// Returning a -1 is keep playing
// Returning a 0 is a draw (or cat wins)
// Returning a 1 shows a winner
int checkForWinner()
{
//TODO: Read through the code in this function.
Based on the commented rules before the function, determine
//what type of return statement belongs in each
of the comments below.
if ((boardTile[1] == boardTile[2] &&
boardTile[2] == boardTile[3])
|| (boardTile[4] ==
boardTile[5] && boardTile[5] == boardTile[6])
|| (boardTile[7] ==
boardTile[8] && boardTile[8] == boardTile[9])
|| (boardTile[1] ==
boardTile[4] && boardTile[4] == boardTile[7])
|| (boardTile[2] ==
boardTile[5] && boardTile[5] == boardTile[8])
|| (boardTile[3] ==
boardTile[6] && boardTile[6] == boardTile[9])
|| (boardTile[1] ==
boardTile[5] && boardTile[5] == boardTile[9])
|| (boardTile[3] ==
boardTile[5] && boardTile[5] == boardTile[7]))
{
//Insert return
statement
return 1; // this is
addeded as per the question requirement
}
else if (boardTile[1] != '1' &&
boardTile[2] != '2' && boardTile[3] != '3'
&& boardTile[4]
!= '4' && boardTile[5] != '5' && boardTile[6] !=
'6'
&& boardTile[7]
!= '7' && boardTile[8] != '8' && boardTile[9] !=
'9')
{
//Insert return
statement
return 0; // this is
addeded as per the question requirement
}
else
{
//Insert return
statement
return -1; // this is
addeded as per the question requirement
}
}
// Draw the board with the player marks
// this is addeded as per the question requirement
void drawBoard()
{
system("cls");
cout << "\n\n\tTic Tac Toe\n\n";
cout << "Player 1 has 'X' - Player 2 has
'O'" << endl << endl;
cout << endl;
cout << "
| | " <<
endl;
cout << " " << boardTile[1] <<
" | " << boardTile[2] << " | " << boardTile[3]
<< endl;
cout << "_____|_____|_____" <<
endl;
cout << "
| | " <<
endl;
cout << " " << boardTile[4] <<
" | " << boardTile[5] << " | " << boardTile[6]
<< endl;
cout << "_____|_____|_____" <<
endl;
cout << "
| | " <<
endl;
cout << " " << boardTile[7] <<
" | " << boardTile[8] << " | " << boardTile[9]
<< endl;
cout << "
| | " << endl
<< endl;
}
//Check if the player's move is valid or if the tile has already
been taken
//TODO: Based on the function initiation at the beginning of the
program, write the function signature, make sure the variable names
are consistent
bool checkValidMove(int choice) // this is addeded as per the
question requirement
{
bool isValid = false;
char aChar = '0' + choice;
cout << "TEST checkValidMove " <<
choice; // TEST added this
if (choice > 0 && choice <= 9)
{
if (boardTile[choice] ==
aChar) {
isValid = true;
}
}
return isValid;
}
***********************end of
code*********************************************
Overview: In this course, you will be responsible for completing a number of programming-based assignments by...
I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe the missing portion. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. // TicTacToe.cpp: Follow along with...
The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() { char board[SIZE]; int player, choice, win, count; char mark; count = 0; // number of boxes marked till now initBoard(board); // start the game player = 1; // default player mark = 'X'; // default mark do { displayBoard(board); cout << "Player " << player << "(" << mark...
In the C++ programming language write a program capable of playing 3D Tic-Tac-Toe against the user. Your program should use OOP concepts in its design. Use Inheritance to create a derived class from your Lab #9 Tic-Tac-Toe class. You can use ASCII art to generate and display the 3x3x3 playing board. The program should randomly decide who goes first computer or user. Your program should know and inform the user if an illegal move was made (cell already occupied). The...
Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to cloud9. Do not change the provided complete functions, or the function stub headers / return values. Currently, if the variables provided in main are commented out, the program will compile. Complete the specifications for each function. As you develop the program, implement one function at a time, and test that function. The provided comments provide hints as to what...
Hello, I am working on my final and I am stuck right near the end of the the program. I am making a Tic-Tac-Toe game and I can't seem to figure out how to make the program ask if you would like to play again, and keep the same names for the players that just played, keep track of the player that wins, and display the number of wins said player has, after accepting to keep playing. I am wanting...
Implement a tic-tac-toe game. Currently, if the variables provided in main are commented out, the program will compile. Complete the specifications for each function. As you develop the program, implement one function at a time, and test that function. The provided comments provide hints as to what each function should do and when each should be called. Add variables where you see fit. Implementation Strategies: The template has variables and two global constants for you to utilize. The template has...
I just need a help in replacing player 2 and to make it
unbeatable
here is my code:
#include<iostream>
using namespace std;
const int ROWS=3;
const int COLS=3;
void fillBoard(char [][3]);
void showBoard(char [][3]);
void getChoice(char [][3],bool);
bool gameOver(char [][3]);
int main()
{
char board[ROWS][COLS];
bool playerToggle=false;
fillBoard(board);
showBoard(board);
while(!gameOver(board))
{
getChoice(board,playerToggle);
showBoard(board);
playerToggle=!playerToggle;
}
return 1;
}
void fillBoard(char board[][3])
{
for(int i=0;i<ROWS;i++)
for(int j=0;j<COLS;j++)
board[i][j]='*';
}
void showBoard(char board[][3])
{
cout<<" 1 2 3"<<endl;
for(int i=0;i<ROWS;i++)
{
cout<<(i+1)<<"...
There is a problem with thecode. I get the error messages " 'board' was not declared in this scope", \src\TicTacToe.cpp|7|error: expected unqualified-id before ')' token| \src\TicTacToe.cpp|100|error: expected declaration before '}' token| Here is the code #ifndef TICTACTOE_H #define TICTACTOE_H #include class TicTacToe { private: char board [3][3]; public: TicTacToe () {} void printBoard(); void computerTurn(char ch); bool playerTurn (char ch); char winVerify(); }; ************************************ TicTacToe.cpp #endif // TICTACTOE_H #include "TicTacToe.h" #include #include using namespace std; TicTacToe() { for(int i =...
I've created a functioning program but I can't figure out how to implement class structure into it. I'm currently studying classes and I'm wondering if you could help me recreate my program with classes so I can have a better understanding of how classes work. Thank you. #pragma once #include <iostream> using namespace std; bool DeclareResults(char ch, char gameboard[][3]); bool FilledBoard(char gameboard[][3]); void printGameBoard(char gameboard[][3]); #include "fnt.h"; #include <iostream> using namespace std; int main() { //declare...
Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities: Covert a binary string to corresponding positive integers Convert a positive integer to its binary representation Add two binary numbers, both numbers are represented as a string of 0s and 1s To reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the...