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

C++ Monte Carlo Assignment Functions: You should now be learning to make your pr

ID: 662557 • Letter: C

Question

C++ Monte Carlo Assignment Functions:

You should now be learning to make your programs as general as possible. For this assignment, you

have to be able to make your calculations work for any board size and configuration: all you know

about it is that all the "cells" (the squares on which a player can land) are evenly distributed around

the edge of an n?sided polygon, k cells per side. For our purposes, we shall number the cells 1

through (n * k), with cell (n * k) also being the original starting position.

A player rolls a pair of 6?sided dice, and moves that many cells from the start spot; this process is

repeated as many times as required until the roll places the "piece" on or past the starting space.

Since we are modeling only a single player, there are no turns: each simulation is of a single player

going around the entire board once. The starting space is also the last possible spot a player can

land in a single rotation, we record landing on this space but then end the simulation

You will model the board as a vector of size (n * k). Note that although you will be working with

indices 0 through (n * k ? 1), you will report the cells as numbers 1 through (n * k), as this is how a

player would think about the board.

As your player traverses the board, you will record each cell he/she lands on. You will perform

multiple simulations of a single board rotation, accumulating in each vector cell the number of times

the player lands on the corresponding board space.

The first function will simulate the dice roll. Once again we want the function to be as general as

possible, so we will parameterize both the number of dice and the number of sides on a dice.

The second function returns the cell with most landings within a closed interval of board spots.

(The closed interval [5,10] means any of the values 5, 6, 7, 8, 9, or 10.)

rollNDice

? simulates rolling N dice, each of which has the specified number of sides

? parameters: two integers by value:

? first integer: the number of dice to roll, by value

? second integer ? the number of sides on the dice, by value

? return type: integer, the summation of all N dice rolls

mostLandings

? returns the cell on the board with the most "landings", within an inclusive interval

? parameters: a vector<int>; two integers

? first parameter: the game board vector, by const reference

? second parameter: the start of the interval to be tested, by value

? third parameter: the end of the interval to be tested, by value

? return type: integer, the index of the first cell in the interval with the most landings

How would you code rollNdice() and mostLandings()?

Explanation / Answer

#include #include #include #define SIZE 7 int main() { int face, roll, frequency[SIZE] = { 0 }; srand( time(NULL) ); for (roll = 1; roll
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