Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ctt Exercise1 You are interested in analyzing the frequency of numbers selected

ID: 3733533 • Letter: C

Question

ctt Exercise1 You are interested in analyzing the frequency of numbers selected for the Powerball lottery. You have downloaded the previous year's Powerball numbers which are saved in a text file called pb_2014.txt and each record in the file has the following format: 01/01/14 15 24 40 48 52 23 x PP 01/04/14 19 20 37 41 58 14 x PP 01/08/14 10 28 39 47 58 22x PP 01/11/14 10 15 33 48 54 34 x PP Unfortunately this is an incompatible file format for the program you are using to analyze the frequency. The correct record file format needed by the program is shown below: 15 24 40 48 52 23 19 20 37 41 58 14 0 28 39 47 58 22 10 15 33 48 54 3-4 Write a program to convert the pb 2014.txt file into the required file format shown above saving the new format to the file powerball.txt, Copy and paste your program into your word document. Copy and paste the first 10 records of each file directly below your program.

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements.

//convert.cpp

#include<iostream>

#include<fstream>

using namespace std;

int main(){

                char inputFileName[]="pb_2014.txt";

                char outputFileName[]="powerball.txt";

                //initializing ifstream for reading input file

                ifstream inFile(inputFileName);

                if(!inFile){

                                //file not found or not readable

                                cout<<inputFileName<<" is not found"<<endl;

                                exit(1);

                }

                string date;//first field is the date

                string f1,f2,f3,f4,f5,f6;//followed by 6 fields which we NEED to save in the output file

                string x,pp;//followed by two fields that we dont need

                string outputData="";// a variable to store the output data

                //reading in all the fields, line by line

                while(inFile>>date>>f1>>f2>>f3>>f4>>f5>>f6>>x>>pp){

                                //appending only the required fields, to the outputdata variable

                                outputData+=f1+" "+f2+" "+f3+" "+f4+" "+f5+" "+f6+" ";

                }

                //closing input file

                inFile.close();

                //displaying output

                cout<<outputData<<endl;

                //initializing ofstream object and printing the output to the file

                ofstream outFile(outputFileName);

                outFile<<outputData;

                //closing output file

                outFile.close();

                cout<<"Output has been saved to "<<outputFileName<<endl;

               

               

}

/*OUTPUT*/

15 24 40 48 52 23

19 20 37 41 58 14

10 28 39 47 58 22

10 15 33 48 54 34

Output has been saved to powerball.txt

/*pb_2014.txt*/

01/01/14 15 24 40 48 52 23 x PP

01/04/14 19 20 37 41 58 14 x PP

01/08/14 10 28 39 47 58 22 x PP

01/11/14 10 15 33 48 54 34 x PP

/*powerball.txt*/

15 24 40 48 52 23

19 20 37 41 58 14

10 28 39 47 58 22

10 15 33 48 54 34