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

Program Purpose Using Visual Studio 2017 create a CLR console application. Creat

ID: 3904328 • Letter: P

Question

Program Purpose Using Visual Studio 2017 create a CLR console application. Create a program plan and then convert it into C++ statements. Practice debugging, declaring variables, type casting, formatting output, if statements and input /output to/from the console window and files, input validation, loops, arrays and functions. Always bring to class 1. Gaddis' book, How-to handouts from the Blackboard and your class notes. 2. This assignment sheet& the grade sheet for this lab already printed out. 3. USB Flash drive(s) or other storage media. LATE PROGRAMS will be not be accepted. Please be sure to upload compressed solution and Word document grade sheet to Canvas by due date/time Mandatory Instructions Your next assignment will be to write a program to play the children's game Chutes and Ladders. The game is played on a board which contains 81 squares, numbered 1 through 81. Each player starts at position 1 and throws one die to determine the number of squares to move on that turn. The first player to reach (or exceed) square 81 wins the game. "Chutes" and "Ladders" exist at various points on the board to enhance play. If a player's token lands on a chute, they "slide" down it and move backward on the board, but if they land on a ladder, they "climb" it and move forward on the board. The beginning and ending locations of each are: Chutes move back Ladders -move forwa bottom 12 bottom 16 4 21 43 15 27 46 75 28 58 64 48 54 Write the program to play the game with two players, Judy and Jane, all starting at position 1, and terminating when one player has reached square 81 or beyond. The output should be a table indicating the player, the move number, the position before the move, the value of the die, and the position after the move. A header for the table should be printed before the game begins. In addition, a line of dashes should separate each set of turns. The winning player should be printed at the end. You should use functions which return a single value through the return statement or return no value (void) when you write this Method program. Functions should use value parameters as needed, but use reference parameters only if a function has more than one value to return. Use 2 variables to represent the players' position on the board. Both variables will be initialized to 1 since they start at position

Explanation / Answer

ScreenShot

---------------------------------------------------------------

Program

/*Your name,Course name and Class time
//Program assignment number,Program file name and due date
//This program to generate Chute and ladder play between two player's
display each player's move and winner
//Giving names of the players as input
//Each move calculate start and end position , according to the chute or ladder check
//Produce result of each move of the players and announce the winner
*/
//Header Files for input/Output,rand(),string manipulation
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<string>
using namespace std;
//Function prototypes
void printHeader();
int rollDice();
int move(int posSt,int posM);
void printMove(string name,int mNumber,int posSt, int die,int posEnd);
int checkChutes(int posn);
int checkLadder(int pos);
bool win(int p1,int p2);
//Main method
int main()
{
   //Variable declaration
   srand(time(NULL));
   string name1, name2;
   int posMovePlayer1 = 0, posStartPlayer1 = 1, posEndPlayer1 = 0, playRoundPlayer1 = 1;
   int posMovePlayer2 = 0, posStartPlayer2 = 1, posEndPlayer2 = 0, playRoundPlayer2 = 1;
   //Prompt user for the names of players
   cout << "Please enter Player name1:";
   cin >> name1;
   cout << "Please enter Player name2:";
   cin >> name2;
   //Output header display function call
   printHeader();
   //Loop to check the board reach 81
   while (posStartPlayer1 < 81 && posStartPlayer2 < 81) {
       // first Player play scores
       posMovePlayer1 = rollDice();                               //Get dice roll value
       posEndPlayer1 = move(posStartPlayer1, posMovePlayer1);     //calculate move
       posEndPlayer1 = checkChutes(posEndPlayer1);                //Check if the move reach into a jute
       posEndPlayer1 = checkLadder(posEndPlayer1);                //Check if the move reach into a Ladder
       printMove(name1, playRoundPlayer1, posStartPlayer1, posMovePlayer1, posEndPlayer1); //Print the move details of player1
       playRoundPlayer1++;                                         //Increment round of the play
       posStartPlayer1 = posEndPlayer1;                            //Set start as the end of last move
       //Second Player play scores
       posMovePlayer2 = rollDice();                             //Get dice roll value
       posEndPlayer2 = move(posStartPlayer2, posMovePlayer2);   //calculate move
       posEndPlayer2=checkChutes(posEndPlayer2);                // Check if the move reach into a jute
       posEndPlayer2 = checkLadder(posEndPlayer2);               //Check if the move reach into a Ladder
       printMove(name2, playRoundPlayer2, posStartPlayer2, posMovePlayer2, posEndPlayer2);   //Print the move details of player2
       playRoundPlayer2++;                                         //Increment round of the play
       posStartPlayer2 = posEndPlayer2;                            //Set start as the end of last move
       cout << "-----------------------------------------------------------------------" << endl;   //Seperator
   }
   //Call win function to display who is the winner
   if (win(posStartPlayer1, posStartPlayer2)) {
       cout << name2 << " is the winner!!!" << endl;
   }
   else {
       cout << name1 << " is the winner!!!" << endl;
   }
    return 0;
}
//Header display
void printHeader() {
   cout<<"Player     Move Number     Current Position     Die     New Position ";
   cout << "*********************************************************************" << endl;
}
//Dice roll
int rollDice() {
   return rand() % 6 + 1;
}
//New position calculation
int move(int posSt, int posM) {
   return posSt += posM;
}
//Print each move of the players
void printMove(string name, int mNumber, int posSt, int die, int posEnd) {
   cout << " "<<name<<"          "<<mNumber<<"                   "<<posSt<<"             "<<die<<"           "<<posEnd<<endl;
}
//Check chute
int checkChutes(int posn) {
   if (posn == 11){
       return (posn = 4);
   }
   else if (posn == 15) {
       return (posn = 7);
   }
   else if (posn == 30) {
       return (posn = 21);
   }
   else if (posn == 44) {
       return (posn = 31);
   }
   else if (posn == 58) {
       return (posn = 43);
   }
   else if (posn == 64) {
       return (posn = 54);
   }
   else {
       return posn;
   }
}
//Check Ladder
int checkLadder(int posn) {
   if (posn == 8) {
       return (posn = 16);
   }
   else if (posn == 12) {
       return (posn =27);
   }
   else if (posn == 28) {
       return (posn = 39);
   }
   else if (posn == 33) {
       return (posn = 46);
   }
   else if (posn ==48) {
       return (posn = 55);
   }
   else if (posn == 59) {
       return (posn =75);
   }
   else {
       return posn;
   }
}
//Check who is the winner
bool win(int p1, int p2) {
   if (p1 < p2) {
       return true;
   }
   else {
       return false;
   }
}

-------------------------------------------------------

Output

Please enter Player name1:Judy
Please enter Player name2:Jane
Player     Move Number     Current Position     Die     New Position
*********************************************************************
Judy          1                   1             1           2
Jane          1                   1             2           3
-----------------------------------------------------------------------
Judy          2                   2             6           16
Jane          2                   3             5           16
-----------------------------------------------------------------------
Judy          3                   16             4           20
Jane          3                   16             5           21
-----------------------------------------------------------------------
Judy          4                   20             5           25
Jane          4                   21             6           27
-----------------------------------------------------------------------
Judy          5                   25             2           27
Jane          5                   27             4           31
-----------------------------------------------------------------------
Judy          6                   27             5           32
Jane          6                   31             5           36
-----------------------------------------------------------------------
Judy          7                   32             5           37
Jane          7                   36             5           41
-----------------------------------------------------------------------
Judy          8                   37             5           42
Jane          8                   41             1           42
-----------------------------------------------------------------------
Judy          9                   42             4           46
Jane          9                   42             1           43
-----------------------------------------------------------------------
Judy          10                   46             4           50
Jane          10                   43             3           46
-----------------------------------------------------------------------
Judy          11                   50             4           54
Jane          11                   46             1           47
-----------------------------------------------------------------------
Judy          12                   54             1           55
Jane          12                   47             6           53
-----------------------------------------------------------------------
Judy          13                   55             2           57
Jane          13                   53             2           55
-----------------------------------------------------------------------
Judy          14                   57             1           43
Jane          14                   55             3           43
-----------------------------------------------------------------------
Judy          15                   43             3           46
Jane          15                   43             6           49
-----------------------------------------------------------------------
Judy          16                   46             2           55
Jane          16                   49             1           50
-----------------------------------------------------------------------
Judy          17                   55             5           60
Jane          17                   50             2           52
-----------------------------------------------------------------------
Judy          18                   60             3           63
Jane          18                   52             2           54
-----------------------------------------------------------------------
Judy          19                   63             3           66
Jane          19                   54             2           56
-----------------------------------------------------------------------
Judy          20                   66             6           72
Jane          20                   56             2           43
-----------------------------------------------------------------------
Judy          21                   72             4           76
Jane          21                   43             2           45
-----------------------------------------------------------------------
Judy          22                   76             3           79
Jane          22                   45             6           51
-----------------------------------------------------------------------
Judy          23                   79             2           81
Jane          23                   51             3           54
-----------------------------------------------------------------------
Judy is the winner!!!
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote