Please Finish Code Use Simple C Language Second C Course Also Give Explanation Writehistog Q43856524
Please finish my code use simple c++ language for this is mysecond c++ course. Also, give an explanation of the writehistogramfunction, please. the comments at the end of my code are thegeneral flow I would like it to be done
Q:
Your completed program should simulate rolls of several pairs ofdice and store them in a data file, and then it should read fromthe data file to produce a histogram file with a simple textrepresentation of a histogram. The simulation is already done foryou; your task is to produce a histogram, formatted as on thereverse sheet. You are encouraged to use the helper functions inthe starter file as guidance, but you don’t have to as long as youproduce a correct histogram.
// Starter file for Homework 1, Question 1; due before class1/15/20
// [YOUR NAME HERE]
#include
#include
#include
#include
using namespace std;
const int N_ROLLS = 200; // how many rolls to simulate
const string DATA_FILENAME = “data.txt”;
const string HIST_FILENAME = “hist.txt”;
int getRoll() { return (rand() % 6 + rand() % 6 + 2); }
// returns the value (between 2 and 12) of a toss of a pair ofrandom dice
void simulateAndRecord();
// Pre: No meaningful data is in either file
// Post: Results of simulation of N_ROLLS pairs of dice are inDATA_FILENAME
void produceHistogram();
// Pre: DATA_FILE contains (at most) N_ROLLS values 2-12;
// HIST_DATA has no meaningful info; both files are closed
// Post: For each val 2-12, HIST_FILE contains a line ofstars
// counting the # times that val appears in DATA_FILE
void writeLineOfStars(int rolls[], int nRolls, int val,ostream& out) {
out << val << “:”;
for (int i = 0; i < nRolls; i++)
out << “*”;
out << “n”;
}
// Pre: rolls array contains nRolls simulations; out is an openedoutput file
// Post: The val line of the histogram has been appended to out,e.g., if val=3
// and 3 occured 5 times, the line would be “3: *****”
int main() {
simulateAndRecord();
produceHistogram();
return 0;
}
// simulate rolling N_ROLLS pairs of dice; record values inDATA_FILENAME
void simulateAndRecord() {
ofstream datafile(DATA_FILENAME); // openDATA_FILENAME
for (int i = 0; i < N_ROLLS; i++) {
datafile << getRoll()<< endl; // simulate 1 roll and output it to datafile
}
datafile.close(); // close the file
}
void produceHistogram() {
/* TODO: implement this function; definewriteLineOfStars helper */
}
/*data.txt record the rolls
producehistogram… data.txt input to histogram and hist.txtoutput
200 stars
open data file as a ifstream(inputfile) and open hist.txt as aofstream
2 to 12
go line by line get one data value and
for
do while that goes untill end of data.txt
prints line i of hist
*/
Expert Answer
Answer to Please finish my code use simple c++ language for this is my second c++ course. Also, give an explanation of the writehi…
OR