News of wildfires in the US has been abundant over the past several years as their reach continues to devastate life, the environment, and infrastructure. Researchers and scientists have been increasingly involved in the effort to study wildfires in an effort to predict, prevent, and fight these disasters. As savvy computer scientists, you have been given the important task to analyze data on large wildfires occurring in the US over the last couple of decades, reporting the statistics that you compute.
The file format will contain the following records of information, with each of the five components composing a record residing on a single line of the file: Year, Fire Name, Location Code, State, and Total Acres Affected. Note that the file contains a sentinel (#####) to denote the end of file data.
Your program should behave as follows.
For each fire record in the file, show its data on one line of the output file following the format:
Year is left aligned and uses 7 characters
Fire Name is left aligned and uses 28 characters
Location Code is left aligned and uses 10 characters
State is left aligned and uses 5 characters
Acres Affected is right aligned and uses 11 characters
In implementing this, you are required to define a struct called FireRecords. Declare an instance of FireRecords (name it Fires[], capable of storing up to 10,000 fire records) in main to input, store, and output each record of fire information (Year, Fire Name, Location Code, State, and Total Acres Affected). You also need a function called writeFireData which take three arguments—your output file, your Fires[] array, and the number of elements that you are using in your array. The function will write the output file based on the arguments passed to it. This task will be performed in class and counted as lab #7 – it is due by the end of class on Nov. 10, 2015!
Note: Use getline and store each line of the file as a string as you read it in. In step 2, you will be converting the string holding Acres Affected to an integer, but this will require stripping the commas from the string before storing (e.g. “1,473,000” will become 1473000). However, this step will not be required to get full credit for your lab (although it will be required when turning in the full project 5).
Implement a function called stripCommasFromNum. This will take a string as a parameter, and return an associated integer value by first stripping the commas from it. To do so, use a for loop to go from the back of the string to the front of the string (i.e. from the character at length – 1 to the character at 0). If a character is a comma (,), use .erase on the string to erase that particular character. Finally, use stoi to return the integer version of the string.
Now, update Step 1 so that your Acres Affected field of your FireRecords struct is represented by an integer instead of a string. Call this function as you read each Acres Affected item from your file to convert the string into an int before storing in your struct.
Calculate and record the overall total amount of square miles of damage listed by all fires in the file. Note that 1 mile = 0.0015625 acres. (Note that I just want the accumulated total for all fires – not a listing for each and every individual fire).
List the total fire damage (in acres) recorded by each individual state (no matter what states, and how many of them, are represented in the file). You are required to define a StateTotals struct to accomplish this. The members of StateTotals will be a string for the state name, and an integer to keep track of the total fire damage recorded in that state. You then need declare a StateTotals array in main called StTots[]. This StTots[] array should be capable of holding up to 50 unique StateTotals records. You are also required to implement a printTotals function which takes as arguments your output file, your StTots[] array, and the number of StTots[] records. In this function, each represented state and the (calculated) total fire damage in that state should be written to the output file.
Hints: Keep a counter called numStates (initialized to 0) for your StTots[] array (like you would any other array). When a new state is read in from the file (search through the array to see if the state exists or not), set the state and totalDamage member of StTots[] at index numStates to the State and Acres Affected, respectively, that are read in from the file and increment numStates. When a state that is already in StTots[] is read in from the file, just add the currently read Acres Affected to the total for that state.
Repeat Step 4, but listing the total fire damage (in acres) recorded by each individual year (no matter what year, and how many of them, are represented in the file). You are required to define a YearlyTotals struct to accomplish this. The members of YearlyTotals will be a string for the year, and an integer to keep track of the total fire damage recorded in that year. You then need declare a YearlyTotals array in main called YrTots[]. Now, call the printTotals function you implemented in Step 4, updating the arguments appropriately in the function call (don’t mess with the function implementation itself) so that each represented year and the (calculated) total fire damage in that year is written to the output file
Give the fire record info of the MAX_WORST_FIRES fire records with the highest acreage damage. For this task you will need another FireRecords array called worstFires[] capable of holding MAX_WORST_FIRES records (set it as 10 for now). You are required to implement a calcWorstFires function which will take as arguments worstFires[], its MAX_WORST_FIRES size, and a single FireRecords array element. This function will compare the incoming record’s affectedAcres member to see if it belongs in worstFires[]. If it is greater, it will be inserted in the appropriate index within the struct’s arrays (see hint below). You are also required to implement a printWorstFires function which takes as arguments your output file, worstFires[], and MAX_WORST_FIRES. This function simply prints out the stored records.
Hints: Call calcTopFires every time a new record of fire data is read from the file. To implement the function: We performed sorted insertion in problem #9 of our array practice lab (Lab #4) in class. Use similar logic to track the top MAX_WORST_FIRES most destructive fires.
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more