Ambient (Outdoor) Pollution
Air pollution is responsible for many deaths in a given year, contributing to such things as strokes, heart disease, cancer, asthma, and other respiratory diseases. Many cities actively attempt to reduce the amount of pollutants in the air, but industrialization can make this a challenge. Government policies like the Clean Air Act have also attempted to tackle this difficult problem. Check out the following video for an example of how computing power is used to assess air quality:
Such things as automobiles, fertilizers, pesticides, energy production (e.g. coal), and agricultural production all contribute pollutants to the surrounding air. Topography can exacerbate the effects of pollutants, trapping them inside a limited area or making it easy for pollutants to settle instead of being swept away by winds (think: Los Angeles, with its basin topography, typically rated as having the “worst” air quality in the United States). The following video describes some of the more common sources of air pollution, including the science behind them:
The World Health Organization (WHO) offers the following limits for the primary elements of air pollution. Please note that μg/m3 means “micrograms per cubic meter”:
Pollutant | Symbol | Limit | Comment |
Fine Particulates | PM2.5 | 10 μg/m3 | (Annual Mean) |
25 μg/m3 | (24-hour Mean) | ||
Coarse Particulates | PM10 | 20 μg/m3 | (Annual Mean) |
50 μg/m3 | (24-hour Mean) | ||
Ozone | O3 | 100 μg/m3 | (8-hour Mean) |
Nitrogen Dioxide | NO2 | 40 μg/m3 | (Annual Mean) |
200 μg/m3 | (1-hour Mean) | ||
Sulfur Dioxide | SO2 | 20 μg/m3 | (24-hour Mean) |
500 μg/m3 | (10-minute Mean) |
C++ Project: Assessing Air Quality
This project will provide you with an introduction to the fundamentals of one-dimensional arrays and user-defined functions in C++. In this project, you will…
- Develop code to read data from the standard input and produce data to the standard output.
- Write code that conforms to a programming style specified by the instructor.
- Select and implement the appropriate control structure(s) for this problem.
- Decompose the given problem into a sequence of single-purpose functions that are highly cohesive and loosely coupled.
- Declare, define, and initialize one-dimensional, simple data type arrays of a fixed size.
- Demonstrate the ability to read from and write to an arbitrary array element using array indices.
- Demonstrate an ability to process the entire array, one element at a time, performing both read and write operations.
- Develop code to read data from a text file and write data in a prescribed format to a text file.
As always, be sure to properly document your code. Consult the C++ Coding Guidelines document for proper coding standards. Use good design principles and design the solution before attempting to write code.
Create a program called AirQuality.cpp.
This program will take the following user input:
- A filename (
string
)
Once the input is complete, your program should open the specified file and begin reading the data. The data is organized as a binary file, with each “record” of data broken into three parts:
- The county name (e.g. “Adams” or “Dauphin”), a
string
of length 256. - The average amount of fine particular matter observed (0-65 μg/m3), a
double
value. - The maximum amount of fine particular matter observed (0-65 μg/m3), a
double
value.
The input does NOT need to be validated. Store the records into an array of a struct
type; this struct
is defined as follows:
struct PollutionData { char county_name[256]; // the county name double average_pm25; // the average amount of fine particular matter double maximum_pm25; // the maximum amount of fine particular matter }; |
Once the file is read, create a Binary Search Tree structure with each node having the following struct
:
struct TreeNode { char key[256]; // the key value for the node, i.e. the county name int index_of_data; // the index of the corresponding record in the array TreeNode* left_child; // a pointer to the "left child" of this node TreeNode* right_child; // a pointer to the "right child" of this node }; |
Each node will contain a key (the county name) and the node ordering will be based on lexicographic ordering. Iterate through your array and produce the Binary Search Tree structure. When the Binary Search Tree is constructed, your program should display the contents of the array in a three-column, formatted table (see the test cases) based on the inorder traversal of the the Binary Search Tree. The following summary information should then be displayed after the table:
- The county with the highest observed average level of fine particular matter
- The county with the lowest observed average level of fine particular matter
- The number of counties whose observed average level of fine particular matter exceeded the annual mean limit
- The number of counties whose observed maximum level of fine particular matter exceeded the annual mean limit
All numerical values should be precise to two decimal places. Before the program exits, dump the contents of your data array to the binary file output.dat
by performing an preorder traversal of your Binary Search Tree.
Your program should make use of multiple functions besides main()
(use the input/process/output cycle as your guide). Think about how each problem actually involves more than one subproblem. At a minimum, you must construct functions aligned with the input-process-output steps. Don’t forget to validate all input, in the manner we discussed in class!
Here are couple of sample tests you can run to check if your program is working correctly. Test Cases #1 and #2 are using CDC data from the period 2003-2011. Two sample data files will be provided by the instructor.
Test Case #1
Enter your filename: input1.dat File input1.dat opened and 4 records have been read. The file is now closed. Binary Search Tree construction complete. COUNTY NAME AVERAGE PM2.5 MAX PM2.5 =========== ============= ========= FULTON 13.89 59.10 COLUMBIA 12.74 62.40 CARBON 12.78 59.40 ADAMS 13.74 61.50 The county with the highest observed average level of PM2.5 is FULTON. The county with the lowest observed average level of PM2.5 is COLUMBIA. There are 4 counties whose observed average level of PM2.5 exceeded the annual mean limit. There are 4 counties whose observed maximum level of PM2.5 exceeded the annual mean limit. File output.dat created. |
Test Case #2
Enter your filename: input2.dat File input2.dat opened and 5 records have been read. The file is now closed. Binary Search Tree construction complete. COUNTY NAME AVERAGE PM2.5 MAX PM2.5 =========== ============= ========= BUCKS 12.91 59.60 DAUPHIN 13.68 64.30 PHILADELPHIA 12.82 60.10 SCHUYLKILL 13.31 64.70 WYOMING 11.75 54.90 The county with the highest observed average level of PM2.5 is DAUPHIN. The county with the lowest observed average level of PM2.5 is WYOMING. There are 5 counties whose observed average level of PM2.5 exceeded the annual mean limit. There are 5 counties whose observed maximum level of PM2.5 exceeded the annual mean limit. File output.dat created. |
Deliverables
See the instructor for submission instructions and due date(s).