Question: C++: Please use the format which is outlined in the hint.cpp code. rolldice.cpp #include #include using namespace std; // returns the value (between 2 and

C++: Please use the format which is outlined in the hint.cpp code.
rolldice.cpp
#include
// 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 hint.cpp #include // 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 histogram.cpp #include 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; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
