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

Write following functions. (a) A function called largerThan11 that checks whethe

ID: 3811567 • Letter: W

Question

Write following functions. (a) A function called largerThan11 that checks whether the integer parameter is larger than 11, return true if it is, return false otherwise. (b) A function called rollDice that returns a random dice value (1-6). (c) A function called emphasis which print a string parameter 3 times to screen.(use loop). In your main function. 1. Use function roll dice three times, to generate 3 dice values. Print each number to screen. 2. Add previous dice values together to a variable called sum. Print out the sum to screen. 3. Use function largerThan11, to check whether the sum is greater than 11. 4. Repeat step 1, 2, 3 until the sum is larger than 11. 5. Use function emphasis, to print out string "Yes! Finally." 3 times to screen. Output should look similar to example below: Part A: Roll dice: 2 2 5 Sum = 9 Roll dice: 4 6 5 Sum = 15 Yes! Finally.Yes! Finally.Yes! Finally.

Explanation / Answer

// C++ code
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;


// unction called largerThan11 that checks whether the integer parameter
//is larger than 11, return true if it is, return false otherwise.
bool largerThan11(int number)
{
   if(number > 11)
       return true;
   else
       return false;  
}

// function called rollDice that returns a random dice value (1-6).
int rollDice()
{
   return (rand()%6 + 1);
}

// function called emphasis which print a string parameter 3 times to screen.
void emphasis(string str)
{
   for (int i = 0; i < 3; ++i)
   {
       cout << str << endl;
   }
}

int main()
{
   srand(time(NULL));

   int dice1, dice2, dice3;
   dice1 = rollDice();
   dice2 = rollDice();
   dice3 = rollDice();

   cout << "Roll dice: " << dice1 << " " << dice2 << " " << dice3 << endl;

   int sum = dice3+dice2+dice1;

   cout << "Sum: " << sum << endl;

   if(largerThan11(sum) == true)
   {
       emphasis("Yes! Finally.");
   }

return 0;
}

/*
output:

Roll dice: 4 4 5
Sum: 13
Yes! Finally.
Yes! Finally.
Yes! Finally.


*/

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