This assignment is built on the first assignment and involves the same functionality as below, with some improvements! The largest changes in A2 are the addition of loops and arrays to store data from multiple locations simultaneously. We are also adding the requirement of using specific functions to complete the assignment, the function prototypes can be found in the .h file included with the “Skeleton Code”. As this program will build off A1, much of the input/output is the same, however an additional menu option is present: “Enter New Location and Data”. Whenever the user selects this new option, they enter a location name and all three pollutant values. That name and data is stored by your program in an array, whenever an AQHI table is displayed it will include the data for ALL locations previously entered. The user may for example: enter 1 location, print the standard calculation table for 1 location, then enter 3 more locations and print the cool calculation table for the 4 locations. The program will store a maximum of 10 locations. Please ensure you read all the sections and follow the instructions exactly as we will grade your submission with an auto-grader. You must test your assignment on the SoCS Linux server, and it will be similarly graded on the SoCS Linux server for consistency. You will receive a 0 if your code includes global variables (variables declared outside of functions), goto statements, or if your code fails to compile without errors. Similarly, the auto-grader will not accept if you name your zip file or program file incorrectly. More details are outlined in Section 4: Program Submission and Administration Information.
CHECK THE UPLOADED FILE, HAS ALL THE DETAILS
CIS1500 Assignment 2: Air Quality Index Generator
Total Marks: 20 marks
Weight: 10%
Due: Friday March 10, 2023, at 11:59 pm
This assignment is built on the first assignment and involves the same functionality as below, with some
improvements! The largest changes in A2 are the addition of loops and arrays to store data from multiple
locations simultaneously. We are also adding the requirement of using specific functions to complete the
assignment, the function prototypes can be found in the .h file included with the “Skeleton Code”.
As this program will build off A1, much of the input/output is the same, however an additional menu option
is present: “Enter New Location and Data”. Whenever the user selects this new option, they enter a location
name and all three pollutant values. That name and data is stored by your program in an array, whenever
an AQHI table is displayed it will include the data for ALL locations previously entered. The user may for
example: enter 1 location, print the standard calculation table for 1 location, then enter 3 more locations
and print the cool calculation table for the 4 locations. The program will store a maximum of 10 locations.
Please ensure you read all the sections and follow the instructions exactly as we will grade your
submission with an auto-grader. You must test your assignment on the SoCS Linux server, and it will be
similarly graded on the SoCS Linux server for consistency.
You will receive a 0 if your code includes global variables (variables declared outside of functions), goto
statements, or if your code fails to compile without errors. Similarly, the auto-grader will not accept if you
name your zip file or program file incorrectly. More details are outlined in Section 4: Program Submission
and Administration Information.
1. Background
In this assignment, you will create an air quality index generator based on values received from the user.
The Air Quality Health Index (AQHI) is a scale developed for Canada and used to determine the impact of
air quality on health. The scale starts at 1 and goes up to “Above 10” which is for very high-risk conditions.
This is illustrated below:
Table 1: AQHI Health Risk and Messages
Health Risk
Air Quality Health Index
Health Message to the General Population
Low
1, 2 and 3
Ideal air quality for outdoor activities.
Moderate
4, 5 and 6
No need to modify your outdoor activities.
High
7, 8, 9 and 10
Consider reducing or rescheduling activities outdoors.
Very High
Above 10
Reduce or reschedule strenuous activities outdoors.
Adapted from http://www.airqualityontario.com/aqhi/index.php
1.1 AQHI Equations
To develop this, three pollutants were chosen, and their average concentration values for the last three hours
are used to calculate the AQHI. These are ground-level ozone (O3), fine particulate matter (PM2.5) and
nitrogen dioxide (NO2). This is calculated using the following equations depending on environmental
conditions.
Standard Calculation:
𝐴𝑄𝐻𝐼 = (
1000
) × [(𝑒 0.000537×𝑂3 − 1) + (𝑒 0.000871×𝑁𝑂2 − 1) + (𝑒 0.000487×𝑃𝑀2.5 − 1)]
10.4
Cool Conditions (disregards the effect of O3):
𝐴𝑄𝐻𝐼𝑐𝑜𝑜𝑙 = (
1000
) × [(𝑒 0.000457×𝑁𝑂2 − 1) + (𝑒 0.000462×𝑃𝑀2.5 − 1)]
6.43
Warm Conditions:
𝐴𝑄𝐻𝐼𝑤𝑎𝑟𝑚 = (
1000
) × [(𝑒 0.00104×𝑂3 − 1) + (𝑒 0.00101×𝑁𝑂2 − 1) + (𝑒 0.000621×𝑃𝑀2.5 − 1)]
12.8
A few things about the calculation:
1. If any pollutant’s average concentration value is unavailable, the AQHI cannot be calculated.
2. The result is rounded off to the nearest positive integer; however, if the calculation is less than
0.5, it is rounded off to 1.
3. The warm vs cold condition is determined by the season: warm season is April–September and
cool season is October–March.
You can refer to Air Quality Health Index, Equations (page 8) and Air Quality Ontario for more information
if you are interested! You can also see sample values for on an hourly basis on Air Quality Ontario –
Pollutant Concentrations (note that there are many more equations for this calculation, so results here may
differ). Note that you do not need any more information about the AQHI than that provided in this document
to work on this assignment.
You may use any values you like to test your program, you do not need to obtain any real data for this
assignment. Selecting logical input/output pairs is a critical part of programming and developing software;
take some time to pick a test cases that will cover many outcomes. When testing we will only enter data of
a valid type, ex if you ask for a number we might test by entering –10 or 60000, but we will not enter
“hello”.
2. Program Requirements
You are provided with a zip file on Courselink called “A2_Skeleton.zip” which contains three files, use
this skeleton code as the basis of your program. You are asked to write two C files for this program, in the
studentNumberA2_main.c and A2_functions.c. You are provided with the file A2_functions.h, which is the
header file you will be using for A2 – it contains the functions prototypes that you are required to write in
the form that is expected. The A2_functions.h file must remain as it is provided to you, do not change the
name or the content of the file.
Your functions will be added to the A2_functions.c file and these will be called in the main function in
studentNumberA2_main.c. All considerations from A1 apply to this assignment, in addition to those
explained below. Refer to the sample flows provided for how your program is expected to run (see 3
Sample Flows).
You are not permitted to use global variables or goto statements. This will result in a grade of zero
on the entire assignment. Note that global constants are permitted (not the same global variables); they
are already provided in the skeleton code A2_functions.h (ex. #define MAX_LOCATIONS 10 is used to
set the maximum size of arrays storing location data). These are global meaning they can be used in any
function including the main.
2.1 The First 12 Marks
As you are improving on your A1 code, you will be required to write functions for printing the menu, taking
user inputs, calculating AQHI and printing the results table to modularize your code. A2_functions.c will
contain the following functions that you must complete and use in your assignment:
•
int printMenuGetSelection()
o This prints the following main menu:
Choose your AQHI settings:
1. Calculate in Standard Conditions
2. Calculate Season-Based Conditions
3. Enter New Location and Data
4. Exit
o It will take in the user’s selection as an integer.
o If the user selects to Calculate Season-Based Conditions a second input is required to ask
the month.
o If a user enters an invalid entry, prompt the user to enter the choice again until they enter a
valid entry. Ex. “Error: invalid option – input must be between 1 and 12.” or “Error: invalid
option – input must be between 1 and 4.”
o The function returns:
▪ 0 if the user selected to print the standard calculation table (you may return the
constant STANDARD_AQHI which stores the value 0)
▪ 1 if the user selected to print the warm calculation table (you may return the
constant WARM_AQHI which stores the value 1)
▪ 2 if the user selected to print the cool calculation table (you may return the constant
COOL_AQHI which stores the value 2)
▪ 3 if the user selected to input location data
▪ -1 if the user selected to exit the program
o Refer to the sample flows provided for the expected input/output
•
•
•
•
•
•
void getInputs(char location[MAX_STRING_SIZE], float pollutants[3])
o Take in the location name from the user
o MAX_STRING_SIZE is 50 as defined in A2_functions.h
o Then requests the 3 pollutant values from the user (always 3 values, however you will only
use 2 when calculating Cool Condition)
o If a user enters an invalid entry, always prompt the user to enter the choice again.
o Refer to the sample flows provided for the expected input/output
float standardAQHI(float O3, float NO2, float PM2_5)
o Returns the AQHI in standard conditions
float coolAQHI(float NO2, float PM2_5)
o Returns the AQHI in cool conditions
float warmAQHI(float O3, float NO2, float PM2_5)
o Returns the AQHI in warm conditions
float roundAQHI(float aqhi)
o Returns the aqhi value rounded up as per Section 1.1
void printTable(char equationName[MAX_STRING_SIZE], int numLocations, char
locations[MAX_LOCATIONS][MAX_STRING_SIZE], float AQHIs[MAX_LOCATIONS])
o This function prints “AQHI for _____ conditions:” with the appropriate calculation type,
ie. Standard, Warm, or Cool
o Then prints the table with the names, rounded AQHI values, Health Risks, and Health
Messages for all data that has been input by the user at that point.
o Refer to the sample flows provided for the expected input/output
You must ensure the function signatures are identical to those provided here. You are allowed to add as
many variables as needed for each function implementation within the function; however, do not add or
remove arguments, do not change argument/return types, and do not modify the .h file. We will test these
functions individually by calling them with known arguments/user input and test if the output is as expected.
2.2 The Next 4 Marks
Your output text formatting will be graded out of 4 i.e. it will be worth 20% of this assignment. We
will flag differences in spellings, spaces, tables, new lines, etc. and test against different input values using
the auto-grader, so make your you follow the output exactly. For each unique error, 0.5 marks will be
deducted. The formatting grade will not be negative, it will only range from 0 to 4.
Refer to the sample flows provided for how your program is expected to run (Section 3 Sample
Flows). Altering/customizing sentences will not be accepted, and you will receive a zero in this category if
you do so.
2.3 The Final 4 Marks
Style: Indentation, variable names, and comments.
Comments are most commonly used to explain confusing or not easily understood parts of code or for
depicting that the following code carries out a certain piece of logic. These are also used to explain the
program and add a header to it. A file header comment is a type of comment that appears at the top of your
program before the #include line(s). Comment grades include header comments (see 4.3 File Header
Comment Format) and meaningful comments throughout your code.
Each code block should be indented for readability (if/else statements are an example of a code block).
We are looking for meaningful variable names that depict the values they are representing – this will
make it easier for you to remember what each variable is for and for us to grade you!
3. Sample Flows
Here are some samples for you to test against. To ensure your output matches ours, we are providing you
with the spacing/size counts at different points in the output.
•
•
Calculation type menu choices are indented by a single \t
The first two lines of creating the table are given below, use this to correctly create the table entry
for Guelph:
printf(“\n—————————————————————————————————\n”);
printf(“| %-10s| %-10s| %-12s| %-58s|\n”, “Location”, “AQHI”, “Health Risk”, “Health Message”);
•
•
The AQHI value should be displayed with two decimal places.
If the AQHI value is greater than 10, display “Above 10” ( Sample Flow V)
Note that your submission will be either fully or partially graded by an auto-grader. To get full grades
you need to match our output requirements exactly.
Make sure to cover the following sample flows:
3.1 Sample Flow I
3.2 Sample Flow II
3.3 Sample Flow III
3.4 Sample Flow IV
3.5 Sample Flow V
3.6 Sample Flow VI
3.7 Sample Flow VII
For this sample note that the user has already entered the following inputs:
3 Vancouver 1 2 3
3 Guelph 10 20 30
3 Hamilton 100 100 100
3 Toronto 85 73 16.6
3 Calgary 95 95 95
3 Quebec 10 10 10
3 Oshawa 7 8 16
3 TroisRivieres 71 13 9
3 Abbotford 56 45 23
3 Iqaluit 0 1 0
4. Program Submission and Administration Information
The following section outlines what is expected when submitting the assignment and various other
administration information with respect to the assignment. To submit your assignment, upload a single zip
file to the Dropbox box for A2 on Courselink.
4.1 The Submission File
The following is expected for the file that is to be submitted upon completing the assignment:
•
•
•
•
•
•
You are to submit one zip file containing studentNumberA2_main.c and A2_functions.c file
for your program.
o Do not include the header file provided to you; it will result in a penalty on your submission
and we will replace the file to ensure no code changes were made to it.
o Do not include any other files or folders in your submission; they will be ignored.
o Do not include this file inside another folder; it will be ignored by the auto-grader.
The name of the zip file follows the following format: studentNumberA2.zip
o Example: John Snow’s student number is 1770770 then the zip file name is 1770770A2.zip
The name of the C file follows the following format: studentNumberA2_main.c
o Example: John Snow’s student number is 1770770 then the C file name is
1770770A2_main.c
The name of the C file follows the following format: A2_functions.c
o Do not change the file name from the skeleton.
Incorrect zip file or C file names will result in a grade of 0.
To ensure you zip correctly and in the right format, we require you to zip your submission through
the command line using the following command:
zip studentNumberA2.zip studentNumberA2_main.c A2_functions.c
Make sure to replace studentNumber with your own student number.
You may wish to download your own submission from dropbox, transfer a copy back to the SoCS server
and re-test after submission. This way you can be 100% certain you have submitted the correct document.
4.2 Program Expectations
Your program is expected to follow the outlined information exactly. Failure to do so will result in
deductions to your assignment grade.
•
•
•
•
•
Your program should be compiled and tested on the SoCS Linux server.
You must use the following command to compile your code:
gcc -Wall -std=c99 studentNumberA2_main.c A2_functions.c -lm
o Example: For John Snow’s submission, the command would be:
gcc -Wall -std=c99 1770770A2_main.c A2_functions -lm
The program file you submit must compile with no errors
o Programs that fail to compile will be given a mark of zero.
Programs that produce warnings upon compilation will receive a deduction of 1 mark for each
type/category of warning
The program files must contain instructions for the TA on how to compile and run your program
in a file header comment (see 3.3 File Header Comment Format).
1.4.1
4.3 File Header Comment Format
Note: This sample uses the same John Snow example; the file name, student name, student ID, etc., and file
descriptions must be changed per student.
/************************** 1770770A2_main.c **************************
Student Name: John Snow
Student ID: 1770770
Due Date: Friday, 10th February 2023, at 11:59 pm
Course Name: CIS*1500
I have exclusive control over this submission via my password.
By including this statement in this header comment, I certify that:
1) I have read and understood the University policy on academic integrity; and
2) I have completed assigned video on academic integrity.
I assert that this work is my own. I have appropriately acknowledged any and all material (code, data,
images, ideas or words) that I have used, whether directly quoted or paraphrase. Furthermore, I certify that
this assignment was prepared by me specifically for this course.
***************************************************************
This file contains…
Describe the program, functions, important variables, etc.
***************************************************************
The program should be compiled using the following flags:
-std=c99
-Wall
-lm
Compiling:
gcc -Wall -std=c99 1770707A2_main.c A2_functions.c -o A2 -lm
OR
gcc -Wall -std=c99 1770707A2_main.c A2_functions.c -lm
Running the program:
./A2
OR
./a.out
***************************************************************/