Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ //Here is the dice.cpp code #include #include using namespace std; int* startEndPairs(string s); int main() { srand(time(0)); // DO NOT WRITE THIS LINE

In C++image text in transcribed

//Here is the dice.cpp code

#include  #include  using namespace std; int* startEndPairs(string s); int main() { srand(time(0)); // DO NOT WRITE THIS LINE AGAIN OR ANYWHERE ELSE cout (s.length()); i++) { if(s[i] == 'd' || s[i] == '+') { parts++; } } // ... so we can make the correct size array to store the info string* data = new string[2*parts]; int index=0; unsigned d = s.find('d'); unsigned p = s.find('+'); while(d != static_cast(-1) || p != static_cast(-1)) { bool dFirst = d (s.length()-d-1); i++) { if(isdigit(s[count+d+1])) { foundDigit=true; } if(!isdigit(s[count+d+1]) && foundDigit) { break; } count++; } string after = s.substr(d+1,count); //should be just the number after 'd' // store these two parts data[index] = before; data[index+1] = after; index+=2; // remove this part from the string s s = s.substr(d+count+1); // discard these two parts } else // same idea for the '+' { // figure out what number is after '+' int count = 0; bool foundDigit=false; for(int i=0; i(s.length()-p-1); i++) { if(isdigit(s[count+p+1])) { foundDigit=true; } if(!isdigit(s[count+p+1]) && foundDigit) { break; } count++; } string after = s.substr(p+1,count); //should be just the number after '+' // store this part data[index] = "+"; data[index+1] = after; index+=2; // remove this part from the string s s = s.substr(p+count+1); // discard these two parts } // update d and p for next loop interation d = s.find('d'); p = s.find('+'); } // now we need to figure out how many dice there are (as 2d4 is 2 dice) // we will treat "+2" as a die that rolls [2,2] int diceCount = 0; for(int i=0; i   Problem B: Dice rolling class (20 points) Start by downloading the "dice.cpp" file from the webpage. This will come with a small main() function, and a function to parse user input into an array of ranges for dice. The format expected for user input is either "Xdy", where x and y and integers or +x" where x is an integer The format "xdy" indicates rolling x y-sided dice, and the format "+x" indicates that x should be added to the total of the dice roll. For example: "2d6+1" represents rolling two 6-sided dice then adding one to the result. In this example, the minimum and maximum possible rolls are 3 and 13 respectively. Multiple additions or dice can be added to the roll by spacing; for example: "2d4 +1 3d6 +4" represents rolling two 4-sided dice, three 6-sided dice, and adding 5 to the total Your program must have the following 1) Create a Dice class that contains the following members a) Two private integer variables to store the minimum and maximum roll possible b) Two constructors (a default constructor and one that takes two integers to initialize the dat:a members that store the min/max possible values of rolls) c) Create a roll() function that returns a random number uniformly distributed between the minimum and maximum possible roll values 2) Create a dynamic array of objects of the Dice class, and use this to compute the statistics (Don't forget to properly delete the array when you are done with it.) After the single getline() in the sample code, your program should ask the user how many rounds they wish to roll. You may assume that the user does not enter a malicious input Then, roll all the dice this number of times and display the following information (following the format and order shown in the examples) 1) A sample roll from the entered line (this roll is not counted in min/max/average statistics) 2) The minimum roll observed 3) The maximum roll observed 4) The average value of all the rolls  Problem B: Dice rolling class (20 points) Start by downloading the "dice.cpp" file from the webpage. This will come with a small main() function, and a function to parse user input into an array of ranges for dice. The format expected for user input is either "Xdy", where x and y and integers or +x" where x is an integer The format "xdy" indicates rolling x y-sided dice, and the format "+x" indicates that x should be added to the total of the dice roll. For example: "2d6+1" represents rolling two 6-sided dice then adding one to the result. In this example, the minimum and maximum possible rolls are 3 and 13 respectively. Multiple additions or dice can be added to the roll by spacing; for example: "2d4 +1 3d6 +4" represents rolling two 4-sided dice, three 6-sided dice, and adding 5 to the total Your program must have the following 1) Create a Dice class that contains the following members a) Two private integer variables to store the minimum and maximum roll possible b) Two constructors (a default constructor and one that takes two integers to initialize the dat:a members that store the min/max possible values of rolls) c) Create a roll() function that returns a random number uniformly distributed between the minimum and maximum possible roll values 2) Create a dynamic array of objects of the Dice class, and use this to compute the statistics (Don't forget to properly delete the array when you are done with it.) After the single getline() in the sample code, your program should ask the user how many rounds they wish to roll. You may assume that the user does not enter a malicious input Then, roll all the dice this number of times and display the following information (following the format and order shown in the examples) 1) A sample roll from the entered line (this roll is not counted in min/max/average statistics) 2) The minimum roll observed 3) The maximum roll observed 4) The average value of all the rolls

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the first step in doing a custom sort in Power BI ?

Answered: 1 week ago

Question

=+Where do you want to live and work?

Answered: 1 week ago

Question

=+1 Where are the best places in the world to live (and work)?

Answered: 1 week ago

Question

=+Are you interested in working on global teams?

Answered: 1 week ago