1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mars1129 [50]
3 years ago
6

computer language C++ (Connect 4 game)( this is all the info that was givin no input or solution) I used the most recent version

of Microsoft visual studio for this program)Your solution must have these classes and at least these fields / methods. Your program must use the methods described in a meaningful fashion. You can create additional fields or methods but these the below should be core methods in your solution.Checkers classfields:colormethods:Constructorint getColor()string toString() - returns an attractive string representation of itselfBoard classfields:2D array of checkers - represents the game board (6 row by 7 column)methods:Constructorstring toString() - returns an attractive string representation of itselfThis needs to be an attractive table representation of the game board with aligned rows / columns with characters representing blank cells, cells with a red checkers in it and cells with a gold checkers in it.int dropChecker(Checker, int) - drops a checker object down a particular slot. Returns an int indicating success or not.int isWinner() - returns code number representing no winner or player number of winnerPlayer classfields:namecolormethods:Constructorget / set methods for fieldsstring toString() - string representation of itself.Example String representation of the board (X means blank, R means red checker, G means gold checker)X X X X X X XX X X X X X XX X X X X G XX X X X X R XX X X X X R XX R G G G R GMainYour program should create two Players and a Board. It should represent the initial Board to the screen.You should then alternate between player 1 and player 2 and randomly drop checkers down slots in the board. You should represent the board after each checker drop.This should stop if there is a winner or if the board fills up.You should be turning in a Checker.h, Checker.cpp, Board.h, Board.cpp, Player.h, Player.cpp and a main.cpp
Engineering
1 answer:
Mariana [72]3 years ago
4 0

Answer:

C++ code explained below

Explanation:

#include "hw6.h"

//---------------------------------------------------

// Constructor function

//---------------------------------------------------

Connect4::Connect4()

{

ClearBoard();

}

//---------------------------------------------------

// Destructor function

//---------------------------------------------------

Connect4::~Connect4()

{

// Intentionally empty

}

//---------------------------------------------------

// Clear the Connect4 board

//---------------------------------------------------

void Connect4::ClearBoard()

{

// Initialize Connect4 board

for (int c = 0; c < COLS; c++)

for (int r = 0; r < ROWS; r++)

board[r][c] = ' ';

// Initialize column counters

for (int c = 0; c < COLS; c++)

count[c] = 0;

}

//---------------------------------------------------

// Add player's piece to specified column in board

//---------------------------------------------------

bool Connect4::MakeMove(int col, char player)

{

// Error checking

if ((col < 0) || (col >= COLS) || (count[col] >= ROWS))

return false;

// Make move

int row = count[col];

board[row][col] = player;

count[col]++;

return true;

}

//---------------------------------------------------

// Check to see if player has won the game

//---------------------------------------------------

bool Connect4::CheckWin(char player)

{

// Loop over all starting positions

for (int c = 0; c < COLS; c++)

for (int r = 0; r < ROWS; r++)

if (board[r][c] == player)

{

// Check row

int count = 0;

for (int d = 0; d < WIN; d++)

if ((r+d < ROWS) &&

(board[r+d][c] == player)) count++;

if (count == WIN) return true;

 

// Check column

count = 0;

for (int d = 0; d < WIN; d++)

if ((c+d < COLS) &&

(board[r][c+d] == player)) count++;

if (count == WIN) return true;

 

// Check first diagonal

count = 0;

for (int d = 0; d < WIN; d++)

if ((r+d < ROWS) && (c+d < COLS) &&

(board[r+d][c+d] == player)) count++;

if (count == WIN) return true;

 

// Check second diagonal

count = 0;

for (int d = 0; d < WIN; d++)

if ((r-d >= 0) && (c+d < COLS) &&

(board[r-d][c+d] == player)) count++;

if (count == WIN) return true;

}

return false;

}

//---------------------------------------------------

// Print the Connect4 board

//---------------------------------------------------

void Connect4::PrintBoard()

{

// Print the Connect4 board

for (int r = ROWS-1; r >= 0; r--)

{

// Draw dashed line

cout << "+";

for (int c = 0; c < COLS; c++)

cout << "---+";

cout << "\n";

// Draw board contents

cout << "| ";

for (int c = 0; c < COLS; c++)

cout << board[r][c] << " | ";

cout << "\n";

}

// Draw dashed line

cout << "+";

for (int c = 0; c < COLS; c++)

cout << "---+";

cout << "\n";

// Draw column numbers

cout << " ";

for (int c = 0; c < COLS; c++)

cout << c << " ";

cout << "\n\n";

}

//---------------------------------------------------

// Main program to play Connect4 game

//---------------------------------------------------

int main()

{

  int choice;

  int counter = 0;

  srand (time(NULL));

  Connect4 board;

  cout << "Welcome to Connect 4!" << endl << "Your Pieces will be labeled 'H' for human. While the computer's will be labeled 'C'" << endl;

  board.PrintBoard();

  cout << "Where would you like to make your first move? (0-6)";

  cin >> choice;

  while (board.MakeMove(choice,'H') == false){

  cin >> choice;

  }

  counter++;

  while (board.CheckWin('C') == false && board.CheckWin('H') == false && counter != 21){

  while (board.MakeMove(rand() % 7, 'C') == false){}

  board.PrintBoard();

  cout << "Where would you like to make your next move?" << endl;

  cin >> choice;

  board.MakeMove(choice,'H');

  while (board.MakeMove(choice,'H') == false){

  cin >> choice;

  }

  counter++;

  }

 

  if (board.CheckWin('C')){

  cout << "Computer Wins!" << endl;}

  else if (counter == 21){cout << "Tie Game!" << endl;}

  else {cout << "Human Wins!" << endl;}

  board.PrintBoard();

}

You might be interested in
A light bulb is switched on and within a few minutes its temperature becomes constant. Is it at equilibrium or steady state.
EleoNora [17]

Answer:

The temperature attains equilibrium with the surroundings.  

Explanation:

When the light bulb is lighted we know that it's temperature will go on increasing as the filament of the bulb has to  constantly dissipates energy during the time in which it is on. Now this energy is dissipated as heat as we know it, this heat energy is absorbed by the material of the bulb which is usually made up of glass, increasing it's temperature. Now we know that any object with temperature above absolute zero has to dissipate energy in form of radiations.

Thus we conclude that the bulb absorbs as well as dissipates it's absorbed thermal energy. we know that this rate is dependent on the temperature of the bulb thus it the temperature of the bulb does not change we can infer that an equilibrium has been reached in the above 2 processes i.e the rate of energy absorption equals the rate of energy dissipation.

Steady state is the condition when the condition does not change with time no matter whatever the surrounding conditions are.

6 0
3 years ago
Someone has suggested that the air-standard Otto cycle is more accurate if the two polytropic processes are replaced with isentr
omeli [17]

Answer:

q_net,in = 585.8 KJ/kg

q_net,out = 304 KJ/kg

n = 0.481

Explanation:

Given:

- The compression ratio r = 8

- The pressure at state 1, P_1 = 95 KPa

- The minimum temperature at state 1, T_L = 15 C

- The maximum temperature T_H = 900 C

- Poly tropic index n = 1.3

Find:

a) Determine the heat transferred to and rejected from this cycle

b) cycle’s thermal efficiency

Solution:

- For process 1-2, heat is rejected to sink throughout. The Amount of heat rejected q_1,2, can be computed by performing a Energy balance as follows:

                                   W_out - Q_out = Δ u_1,2

- Assuming air to be an ideal gas, and the poly-tropic compression process is isentropic:

                         c_v*(T_2 - T_L) = R*(T_2 - T_L)/n-1 - q_1,2

- Using polytropic relation we will convert T_2 = T_L*r^(n-1):

                  c_v*(T_L*r^(n-1) - T_L) = R*(T_1*r^(n-1) - T_L)/n-1 - q_1,2

- Hence, we have:

                             q_1,2 = T_L *(r^(n-1) - 1)* ( (R/n-1) - c_v)

- Plug in the values:

                             q_1,2 = 288 *(8^(1.3-1) - 1)* ( (0.287/1.3-1) - 0.718)

                            q_1,2= 60 KJ/kg

- For process 2-3, heat is transferred into the system. The Amount of heat added q_2,3, can be computed by performing a Energy balance as follows:

                                          Q_in = Δ u_2,3

                                         q_2,3 = u_3 - u_2

                                         q_2,3 = c_v*(T_H - T_2)  

- Again, using polytropic relation we will convert T_2 = T_L*r^(n-1):

                                         q_2,3 = c_v*(T_H - T_L*r^(n-1) )    

                                         q_2,3 = 0.718*(1173-288*8(1.3-1) )

                                        q_2,3 = 456 KJ/kg

- For process 3-4, heat is transferred into the system. The Amount of heat added q_2,3, can be computed by performing a Energy balance as follows:

                                     q_3,4 - w_in = Δ u_3,4

- Assuming air to be an ideal gas, and the poly-tropic compression process is isentropic:

                           c_v*(T_4 - T_H) = - R*(T_4 - T_H)/1-n +  q_3,4

- Using polytropic relation we will convert T_4 = T_H*r^(1-n):

                  c_v*(T_H*r^(1-n) - T_H) = -R*(T_H*r^(1-n) - T_H)/n-1 + q_3,4

- Hence, we have:

                             q_3,4 = T_H *(r^(1-n) - 1)* ( (R/1-n) + c_v)

- Plug in the values:

                             q_3,4 = 1173 *(8^(1-1.3) - 1)* ( (0.287/1-1.3) - 0.718)

                            q_3,4= 129.8 KJ/kg

- For process 4-1, heat is lost from the system. The Amount of heat rejected q_4,1, can be computed by performing a Energy balance as follows:

                                          Q_out = Δ u_4,1

                                         q_4,1 = u_4 - u_1

                                         q_4,1 = c_v*(T_4 - T_L)  

- Again, using polytropic relation we will convert T_4 = T_H*r^(1-n):

                                         q_4,1 = c_v*(T_H*r^(1-n) - T_L )    

                                         q_4,1 = 0.718*(1173*8^(1-1.3) - 288 )

                                        q_4,1 = 244 KJ/kg

- The net gain in heat can be determined from process q_3,4 & q_2,3:

                                         q_net,in = q_3,4+q_2,3

                                         q_net,in = 129.8+456

                                         q_net,in = 585.8 KJ/kg

- The net loss of heat can be determined from process q_1,2 & q_4,1:

                                         q_net,out = q_4,1+q_1,2

                                         q_net,out = 244+60

                                         q_net,out = 304 KJ/kg

- The thermal Efficiency of a Otto Cycle can be calculated:

                                         n = 1 - q_net,out / q_net,in

                                         n = 1 - 304/585.8

                                         n = 0.481

6 0
3 years ago
A 132mm diameter solid circular section​
Ganezh [65]

Answer:

not sure if this helps but

5 0
3 years ago
A drilling operation is performed on a steel part using a 12.7 mm diameter twist drill with a point angle of 118 degrees. The ho
Masteriza [31]

Answer:

a. Rotational speed of the drill  = 375.96 rev/min

b. Feed rate  = 75 mm/min

c. Approach allowance  = 3.815 mm

d. Cutting time  = 0.67 minutes

e. Metal removal rate after the drill bit reaches full diameter. = 9525 mm³/min

Explanation:

Here we have

a. N = v/(πD) = 15/(0.0127·π) = 375.96 rev/min

b. Feed rate = fr = Nf = 375.96 × 0.2 = 75 mm/min

c. Approach allowance = tan 118/2 = (12.7/2)/tan 118/2 = 3.815 mm

d. Approach allowance T∞ =L/fr = 50/75 = 0.67 minutes

e. R = 0.25πD²fr = 9525 mm³/min.

7 0
3 years ago
What are the indicators of ineffective systems engineering?
liberstina [14]

Answer:

Indicators for ineffective system engineering are as follows

1.Requirement trends

2.System definition change backlog trends

3.interface trends

4.Requirement validation trends

5.Requirement verification trends

6.Work product approval trends

7.Review action closure trends

8.Risk exposure trends

9.Risk handling trends

10.Technology maturity trends

11.Technical measurement trends

12.System engineering skills trends

13.Process compliance trends

7 0
3 years ago
Other questions:
  • Define a public static method named s2f that takes two String arguments, the name of a file and some text. The method creates th
    5·1 answer
  • Why should engineers avoid obvious patterns?
    13·2 answers
  • Refrigerant-134a enters a diffuser steadily as saturated vapor at 600 kPa with a velocity of 160 m/s, and it leaves at 700 kPa a
    10·2 answers
  • Inspection with considering a variable uses gages to determine if the product is good or bad. True or False?
    15·2 answers
  • What are the three elementary parts of a vibrating system?
    14·1 answer
  • 1. A farmer had 752 sheep and took one shot that got them all. How did he do it?
    9·1 answer
  • The rainfall rate in a certain city is 20 inches per year over an infiltration area that covers 33000 acres. Twenty percent of t
    6·1 answer
  • If the same type of thermoplastic polymer is being tensile tested and the strain rate is increased, it will: g
    14·1 answer
  • What is the process pf distributing and selling clean fuel?​
    6·1 answer
  • who wants points for now work just put any answer who wants points for now work just put any answer who wants points for now wor
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!