SPIES BERDAFTAR

28 October 2015

c++ programming source code sharing #1 : CALCULATE API VALUE (my midterm exam's answer)

ASSALAMMUALAIKUM W.B.T. peeps !


So today, I would like to share with you all, my midterm exam's question and sample answer. The answer for this question is not yet discussed in class, so the one I share here is the one I wrote during the exam, with some modification was done later. oh yeah, i'm using Dev-C++ ver 5.11 IDE.

even though haze prob is almost nil right now in Skudai, all thanks to Allah for these past 1-2 days heavy rain.. it's still not a crime to post some haze-related coding, rite? :v

INSTRUCTIONS:
Write a C++ program to calculate the accurate API value and determine the status of the air quality.
The program should perform the following steps:

a. Ask the user to enter the number of locations that will be read from an input file (maximum
number of location is 10). Example runs of the program are shown in Figures 1(a), 2(a) and
3(a). Note: The bold texts in Figures 1(a), 2(a) and 3(a) indicate input from the user.

b. Read input data, location and the pollutant value of PM2.5 from the input file named
input.txt”. The number of input data that will be read from the file is based on the number
of locations entered in (a). An example of the series of input data in the input file is shown in
Figure 4.

c. Calculate the API value using the formula given.

d. Based on the API value calculated; determine the air quality status.

e. Calculate the number of stars that represent API value. Each star (the character '*') represents
twenty (20) API value.

f. Calculate the average of API value.

g. Find the highest and lowest API value.

h. The output of this program should be displayed into the output file named “output.txt”. The
snapshots of the output file are as shown in Figures 1(b), 2(b) and 3(b). Display the output
telling the following information:
i. The location
ii. The calculated API value
iii. The corresponding air quality status
iv. Display a bar chart (using stars) for the API value. Each star (the character '*')
represents twenty (20) API value.
v. The highest API value
vi. The lowest API value
vii. The average API value


***I also add some extra coding in my source code that is to check the validity of number of location entered. if number entered is negative or more than 10, error message will appear and user need to enter another number. also, i add a prompt message at the end of the program where it tells the user to refer to output.txt file for the report. :3

below are figures from my question paper:
formula & status







and here's the screenshot of my code :

****I changed the output file name a bit coz this is my modified version of coding and I want to compare with the original one.

Some of the code is not seen clearly due to the loooong line. maybe you can figure out the 'hidden' code by yourself or if you need, you can download the source file. link is at the end of this post.

**depending on your IDE version, you may not see the prompt message I mentioned earlier. if that's the case, you need to add system("pause"); at the end of your main function.


Here's the output.txt screenshot for 10 inputs:





that's all for now. till we meet again. adios! ;)

regards,

No comments:

Post a Comment

pecah kaca sebab koman,
lepas baca harap komen. :D