Question: hint.cpp code: #include #include #include #include using namespace std; // global constants const string FILENAME = output.txt; // a name for a text file const

 hint.cpp code: #include #include #include #include using namespace std; // global

hint.cpp code:

#include #include #include #include using namespace std;

// global constants const string FILENAME = "output.txt"; // a name for a text file const string TEXT = "Lorem ipsum"; // a string to be written to the file

// Pre: o is an output stream (eg cout or an initialized ofstream) // Post: o contains a line of text specified by global const TEXT // followed by a line containing the int n void helper(int n, ostream& o);

// Open a file; use helper to write to it; close before terminating int main() {

// Declare and initialize a variable favenum local to main. // Type is int; initial value is 73. int favNum = 73;

// Declare and initialize another variable outputfile local to main. // Type is ofstream; provides a way to write to a file called FILENAME. ofstream outputfile(FILENAME); // an ofstream is an ostream for file writing

// Pass both local vars as arguments to a helper function. helper(favNum, outputfile);

// Close the file before the program terminates. outputfile.close();

// Uncomment the line below to use the same function to write to the console! //helper(42, cout); // cout is a particular ostream for writing to the console

return 0; }

// Write TEXT and an int to an open file; important to pass the ostream by ref void helper(int n, ostream& o) { o

historgram.cpp code

#include #include using namespace std;

int main(int argc, char *argv[]) { // check that user provided enough args and store them in local variables if (argc

/* TODO: Produce a histogram of the data and write it to the hist file */

return 0; }

rolledice.cpp code

#include #include using namespace std;

// returns the value (between 2 and 12) of a toss of a pair of random dice int getRoll() { return (rand()%6+1 + rand()%6+1); }

int main(int argc, char *argv[]) { if (argc

int nRolls = stoi(argv[1]); // note: this expects the extra arg to be a string string filename = argv[2]; if (argc>3) srand(stoi(argv[3])); // seed rand with user-specified value else srand(time(NULL)); // seed rand with true randomness (time)

ofstream datafile(filename); // create or open for (int i=0; i

Program 1. A fully implemented program in rolldice.cpp simulates several rolls of a pair of 6-sided dice and records them in a datafile. Your task is to use skills from CSCI 10 to implement histogram.cpp to read values from a datafile and produce a text-based histogram of these values in a second file. For the first program, the user provides arguments specifying the number of rolls to simulate, the file that will store the data, and (optionally) a seed for the random number generator responsible for the simulation. For the second program, the user provides arguments specifying the number of rolls, the datafile, and the file where the histogram should be written; the code for parsing these arguments is already written for you. Then you can compile and run the two programs as follows to produce files that look like the ones below. (Omit the seed 2 to get different values each time, and increase the 15 to 200 for a better visualization of the distribution.) For full credit, format your histogram file exactly like the sample run, including spacing. 6 Connonsunnon on $ g++ rolldice.cpp -std=c++11 -o roll $ g++ histogram.cpp -std=c++11 -o hist $ ./roll 15 data.txt 2 $ ./hist 15 data.txt hist.txt 2: 3: * 4: 5: *** 6: Holok 7: *ock 8:* 9:* 10: * 11: * 12: 8 7 7 data.txt hist.txt Problem solving notes: You may find it useful to declare, implement, and use a helper function with signature void writeLineOfStars (int rolls[], int nRolls, int val, ostream& out); The precondition for such a function would be that the rolls array contains nRolls ints between 2 and 12 (data already read from the data file), and out is an output stream corresponding to the opened histogram file, which already contains a line of stars for each previous value. The postcondition would be that the line corresponding to the val row has been appended to the output stream. Recall that you can open and write to a file by declaring an ofstream, which, in addition to accepting content insertion using the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!