Please Help!!! This is C++ class. Thank you!!! a O O cs128-hw4.pdf HOMEWORK: 4 (
ID: 3666010 • Letter: P
Question
Please Help!!! This is C++ class. Thank you!!!
a O O cs128-hw4.pdf HOMEWORK: 4 (10 points) DUE DATE: Monday February 8, 2016 Description: Implement the problem in quiz #5 Write a complete C++ program that will simulate rolling a regular die n times and output the number of times the die landed with face number k. Your program will prompt the user for n and k. Your program output DICE by your-name. the rest of the I/O from your program Turn in 1. Email the captured I/O in a file name fast-hw4.txt (use the script command and the source code with the file name flast-hw4.cpp, where fast is your first name initial and last name (ex. tnguyen-hw3.cpp) to tvnguyen7@cpp.edu with the subject: cs1280?w16 hw4. is your section, space between 6 and h. Rename the file before submitting. Notes: 1. The following information is required in the beginning of every source file. Last, First Name Homework:Explanation / Answer
//Name : XXXXXX
//Homework:#
/**C++ program that simulates the rolling dice
with n -times with face value ,k .
After rolling completion, the program prints a
message that the number of times the dice is rolled
with k value in n-times*/
//Source code of program
//tnguyen-hw.cpp
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int roll();
int main()
{
//seed the value
srand(time(0));
//set k value
int k=5;
//set k as facevalue
int faceValue=k;
//set number of times dice to roll
int ntimes=100;
//coun variabe to count number of times k values is found
int count=0;
//roll dice ntimes
for(int index=1;index<ntimes;index++)
{
//increment count vlaue if roll return value
//is k
if(roll()==k)
count++;
}
//print a message
cout<<"Dice rolled,n= "
<<ntimes<<" with face value, k = "<<faceValue
<<" is "<<count<<endl;
system("pause");
return 0;
}
//Returns a a dice value in range of 1 to 6
int roll()
{
return rand()%6+1;
}
Sampel output:
Dice rolled,n= 100 with face value, k = 5 is 17