Details of this Paper

1 Open a copy of the file_open_shell_S14.cpp program and the file random.txt.dat;(download from Blackboard???Course Materials/Code/). Rename the program file;random_max.cpp. In...




1 Open a copy of the file_open_shell_S14.cpp program and the file random.txt.dat;(download from Blackboard?Course Materials/Code/). Rename the program file;random_max.cpp. In the data file is a column of numbers generated using the random;number generating function we will study soon. One method of detecting defining the end;of a file is to include a trailer signal. This signal is a value that is outside the range of data;contained in the file. In this case, the file random.txt.dat contains a series of positive;random numbers, so the trailer signal is -99, a number that is clearly not within the range;of expected data. The challenge for this problem is to read the file until the end of the data;is found, and keep track of the number of records in the file. Since the file contains several;records, it should be clear that we?ll use some kind of loop and a counter variable.;Let?s think about the variables we?ll neeed;? Since all of the values in the file are integers, we will need an integer variable to;store the records as we read them and a counter variable to determine the number of;records in the file: int num, counter;? Since we will need to read from an input file and and write the values we read to an;output file, we?ll need stream objects for input and output files: ifstream fin and ofstream;fout, (Note: these names are arbitrary, and I use these names out of habit, and because;they speak their functions clearly);? We will need two string variables for file names. Let?s use: string ifname, ofname;(Note: Once again, these are arbitrary?feel free to devise your own);So, we should have;int num, ctr;string ifname(?random.txt.dat?), ofname(?random_out.dat?);ifstream fin;ofstream fout;Most of the code above is already in the program shell file. Since we are ?hard coding? the;Revised 02-01-2012;1;Professor D. H. Goldthwaite;GE 1111 Spring 2014;filenames in, we can remove the part of the program file that prompts the user for;filenames.;Now, what type of loop should we use?;? We are looping until we detect a value that is out of range, specifically, it is = 0;fin>>num;while(num>=0);ctr++;fin>>num;fout<


Paper#70222 | Written in 18-Jul-2015

Price : $22