SPIES BERDAFTAR

Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

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,

12 March 2015

personal blog #7 : done!!

ASSALAMMUALAIKUM W.B.T. peeps !

alhamdulillah, at last. at last. at laaast, i finished my final programming project. 15 types of sports score keepers all together. at first i made each of them in different c file, then after combining all of them... 2.1k lines in total! what a number! :3 yeahh, of course with some blank lines between those codes. hehe. at first we planned to make 25 types, then shorten to 20, and then 15..at last. kih kih. got no time to make that much, maybe(?). btw if.. i do make that much, that's mean my whole program will consist about..(takes calculator..calculating 2.1k/15*25)... 3.5k?! hah, kinda insanee. it's ok, daijou bu! 2.1k already enough & appropriate for my level i think.. hehe

soo, all these score keepers, if Allah wills, i will share in my blog once i'm over with my final exam here. or if i do find some time to update, i'll do it, one at a time. ;)

oh, i'm also planning to share inventory item updater source code! ← my csc individual assignment.
maybe in near future, potassium? :3

today is the last time i'm wearing lab coat here, in uitm palam


***update:my groupmate's coding is 8k lines! omo, i felt soooo down to earth. huhu

regards,

10 February 2015

c programming source code sharing #6 : Printing a hollow square using nested for

ASSALAMMUALAIKUM W.B.T. peeps !

hi hi hi. (greeting ni, "hai hai hai" bukan gelak hi hi hi)
so today i would like to share the next source code, of my homework this week, freshly from oven!
*baru siap buat daa*

sample question:
Read an integer(entered by user) and prints a hollow square. the number of '=' used to draw line of each sides of square.

example, user enter 5, so the output is
=====
=      =
=      =
=      =
=====
a 5x5 square with a hollow.(hollow-lubang)
(not-so-square looking here, but in .exe file you'll see it is more like a square!)

another sample output:


of course, it will only works with positive integers.
& for integer=1 & 2, you'll not see a hollow.

soooo here's the screenshot of my source code:

CLICK IMAGE TO ENLARGE

or, download the c-file here. (can edit&try compile yourself!)

my lecturer told us, usually for this kind of question, there would be more than 1 solution. so my fellas out there, if you have a simpler & more unique way, please share! sharing is caring yow! & for any questions, please, just ask me ok? :)

regards,

02 February 2015

my group project assignment

ASSALAMMUALAIKUM W.B.T. peeps !

hi. just wanna tell you guys i'm doing sports score keeper (yep, with 's' coz more than 1 sport). for my Foundation in Computing II subject group project assignment. there'll will be basketball, futsal, netball & so on if Allah wills. Currently when i'm writing this i only finished Basketball Score Keeper & working on Futsal one. (stuck at penalty shootout part,duh.). Please pray for my group k. Adios!


regards,

28 January 2015

when..

ASSALAMMUALAIKUM W.B.T. peeps !

pabila lebih utamakan kerja yg due 2 MAC berbanding ESOK kerana minat..
watever. janji dah siap assignment. alhamdulillah. :3




korang dah siap assignment csc? 

***update---assignmentku direject, kena tunggu dah blajo chapter function dlu ghupanya...huhu


regards,

27 January 2015

c programming source code sharing #5 : Buying Ticket/Booking Hotel using switch

ASSALAMMUALAIKUM W.B.T. peeps !

question example:

Ticket Type             Code         Price
Bed Class                   D             65
Standard Class           E              40
Economy Class           S              29

Ask user to input ticket type's code & number of seats they want to buy.
Display total price including 6% government tax.

snapshot of source code :
CLICK THE IMAGE FOR LARGER VIEW

CLICK HERE FOR THE C FILE (can copy&paste and try to compile on your own compiler&edit)

regards,

c programming source code sharing #4 : Buying Ticket/Booking Hotel using if...else

ASSALAMMUALAIKUM W.B.T. peeps !

question example:

Room Type        Code         Price
Deluxe                  D             220
Exclusive              E             170
Single                   S              130

Ask user to input room's code & number of days they are staying.
Display total price including 6% government tax.

snapshot of source code :
CLICK THE IMAGE FOR LARGER VIEW

CLICK HERE FOR THE C FILE (can copy&paste and try to compile on your own compiler&edit)

regards,

c programming source code sharing #3 : Summon Rate

ASSALAMMUALAIKUM W.B.T. peeps !

so.. hi! sorry for not updating last week as i got no homework. :3 as repayment, today more source codes are coming! and as for the first 1 here is Summon Rate.

example of question :

(USE NESTED IF....ELSE)

Summon Rate
1.Summon within 1 month
2.Summon within 2 months and above

If user enter 1;
1.ask input for the value of summon
2.ask whether summon is within 15 days or not
   a)if yes, 50% discount will be given. display discounted value & the new summon value
   b)if no, 25% discount will be given. display discounted value & the new summon value

If user enter 2;
1.ask input for the value of summon
2.15% discount will be given. display discounted value & the new summon value

DISPLAY ERROR MESSAGE IF USER ENTER OTHER THAN 1 & 2.

so here is the snapshot of the source code.

CLICK THE IMAGE FOR LARGER VIEW


CLICK HERE FOR THE C FILE (can copy&paste and try to compile on your own compiler&edit)




regards,

15 January 2015

c programming source code sharing #2 : area of circle/disk/rim with hole calculator

ASSALAMMUALAIKUM W.B.T. peeps !
& good day

the title itself already describe the source code i'm gonna to share today. it is basically a a program which will calculate the area of circle/disk/rim with circular hole. the user need to input the outer diameter & inner diameter of the circle.

CLICK THE PICTURE TO ENLARGE

with a little bit of twist, you can change for the user to enter radius or perhaps both based on how the user wanted! this is just the simple version ;)

CLICK HERE FOR THE C-FILE (can copy&paste directly)
                                                                    regards,

c programming source code sharing #1 : change money calculator

ASSALAMMUALAIKUM W.B.T. peeps !
& good day.


this is my first entry on sharing my source code i've worked on. from now onwards i will basically share my source codes here which are actually my homework that i will be getting every weeks this semester.

do feel free to comments & ask anything. :)

example question:

              Write a program that takes as input any change expressed in cents. It should then compute the number of 50-ringgit, 10-ringgit, 5-ringgit, 1-ringgit, 50-cent, 20-cent, and 10-cent, in that order. For example, 3020 cents should be returned as one 20-ringgit, one 10-ringgit and one 20-cent.



CLICK THE IMAGE FOR LARGER VIEW


view the c-file here (can copy-paste)


                                                                    regards,