Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Task1 -Tic-Tac-Toe Game : Write a modular program that allows two players to pla

ID: 3759728 • Letter: T

Question

Task1 -Tic-Tac-Toe Game :
Write a modular program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as a game board. Each element of the 2D array should be initialized with an asterisk (*). The program should display the initial board configuration and then start a loop that does the following:

Allow player 1 to select a location on the board for an X by entering a row and column number. Then redisplay the board with an X replacing the * in the chosen location.

If there is no winner yet and the board is not yet full, allow player 2 to select a location on the board for an O by entering a row and column number. Then re-display the board with an O replacing the * in the chosen location.

The loop should continue until a player has won or a tie has occurred.

Player 1 wins when there are three Xs in a row, a column, or a diagonal in the game board.

Player 2 wins when there are three Os in a row, a column, or a diagonal in the game board.

A tie occurs when all of the locations on the board are full, but there is no winner.

The program should display an appropriate message indicating who won, or reporting that a tie occurred. This should also be written to a file.

           

Input validation; only allow legal moves to be entered. The row must be 1, 2, or 3. The column must be 1, 2, or 3. the (row, column) position entered must currently be empty(i.e. still have an asterisk in it).

Task 2-   Garment factory

Problem description :

Design a program for a garment factory that asks for the user’s height, weight, and age, and then computes clothing sizes according to the formulas:

Weight and height are given in kilograms and centimetres respectively

Hat size = weight in pounds divided by height in inches and that multiplied by 2.9. .

Jacket size (chest in inches) = height times weight divided by 288 and then adjusted by adding 1/8 of an inch for each 10 years over age 30. (Note that the adjustment only takes place after a full 10 years. So, there is no adjustment for ages 30 through 39, but 1/8 of an inch is added for age 40.)

Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years. So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)

     Use functions for each calculation. Your program should allow the user to repeat  

     this calculation as often as the user wishes.

     Write a C++ program that tests these functions. (Declare additional variables in the  

     function main, if necessary.)

Explanation / Answer

#include <iostream>
#include <iomanip>
using namespace std;
const int SIZE = 3;
char a[3][3] = {
   {'*','*','*'},
   {'*','*','*'},
   {'*','*','*'}
               };
              
char b = '0';
void draw();
bool getinputP1();
bool getinputP2();
bool checkwinP1();
bool checkwinP2();
int main()
{
   draw();
   cout << "Player one make your move" << endl;
   getinputP1();
   draw();
   cout << "Player two make your move" << endl;
   getinputP2();
   draw();
   for (;;)
   {
       cout << "Player one make your move" << endl;
       getinputP1();
       if(checkwinP1() == 1)
       {
           draw();
           cout << "Player one, you win!" << endl;
           break;
       }
       draw();
       cout << "Player two make your move" << endl;
       getinputP2();
       if(checkwinP2() == 1)
       {
           draw();
           cout << "Player two, you win!" << endl;
           break;
       }
       else
       {
           draw();
           cout << "It's a tie" << endl;
           break;
       }
   }
  
   return 0;
}
void draw()
{
   for (int i = 0; i < SIZE; i++)
   {
       for (int j = 0; j < SIZE; j++)
       {
           cout << setw(5) << a[i][j];
       }
       cout << endl;
   }
}
bool getinputP1()
{
   cout << "Enter your move" << endl;
   cin >> b;
   switch(b)
   {
       case '1' : a[0][0] = 'X'; break;
       case '2' : a[0][1] = 'X'; break;
       case '3' : a[0][2] = 'X'; break;
       case '4' : a[1][0] = 'X'; break;
       case '5' : a[1][1] = 'X'; break;
       case '6' : a[1][2] = 'X'; break;
       case '7' : a[2][0] = 'X'; break;
       case '8' : a[2][1] = 'X'; break;
       case '9' : a[2][2] = 'X'; break;
       default: cout << "Hey!! You have to play by the rules!" << endl;
   }
   return 0;
}
bool getinputP2()
{
   cout << "Enter your move" << endl;
   cin >> b;
   switch(b)
   {
       case '1' : a[0][0] = 'O'; break;
       case '2' : a[0][1] = 'O'; break;
       case '3' : a[0][2] = 'O'; break;
       case '4' : a[1][0] = 'O'; break;
       case '5' : a[1][1] = 'O'; break;
       case '6' : a[1][2] = 'O'; break;
       case '7' : a[2][0] = 'O'; break;
       case '8' : a[2][1] = 'O'; break;
       case '9' : a[2][2] = 'O'; break;
       default: cout << "Hey!! You have to play by the rules!" << endl;
   }
   return 0;
}
   bool checkwinP1()
   {
       if(a[0][0] == 'X' && a[0][1] == 'X' && a[0][2] == 'X') return 1;
       if(a[1][0] == 'X' && a[1][1] == 'X' && a[1][2] == 'X') return 1;
       if(a[2][0] == 'X' && a[2][1] == 'X' && a[2][2] == 'X') return 1;
       if(a[0][0] == 'X' && a[1][0] == 'X' && a[2][0] == 'X') return 1;
       if(a[0][1] == 'X' && a[1][1] == 'X' && a[2][1] == 'X') return 1;
       if(a[0][2] == 'X' && a[1][2] == 'X' && a[2][2] == 'X') return 1;
       if(a[0][0] == 'X' && a[1][1] == 'X' && a[2][2] == 'X') return 1;
       if(a[2][0] == 'X' && a[1][1] == 'X' && a[0][2] == 'X') return 1;
   }
   bool checkwinP2()
   {
       if(a[0][0] == 'O' && a[0][1] == 'O' && a[0][2] == 'O') return 1;
       if(a[1][0] == 'O' && a[1][1] == 'O' && a[1][2] == 'O') return 1;
       if(a[2][0] == 'O' && a[2][1] == 'O' && a[2][2] == 'O') return 1;
       if(a[0][0] == 'O' && a[1][0] == 'O' && a[2][0] == 'O') return 1;
       if(a[0][1] == 'O' && a[1][1] == 'O' && a[2][1] == 'O') return 1;
       if(a[0][2] == 'O' && a[1][2] == 'O' && a[2][2] == 'O') return 1;
       if(a[0][0] == 'O' && a[1][1] == 'O' && a[2][2] == 'O') return 1;
       if(a[2][0] == 'O' && a[1][1] == 'O' && a[0][2] == 'O') return 1;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote