You are on page 1of 4

COMSATS University Islamabad, Lahore Campus

Department of Computer Science

Lab Rubrics # 2 – Post Lab Assessment – Spring 2022


Course Title Introduction to Computer Programming
Assignment 2
Due Date 12-June-2022
Student Name Huma Saulat + Hadia Saulat
Registration Number FA20-CHE-035+ FA20-CHE-036
Instructions:
● You need to submit a word and a pdf file against this assignment with proper name
format (e.g., Group#1_Assignment#2_PostLab_ICP)
● If found plagiarism, straight zero will be marked against assignment.
● Submit Assignment on Due Date. (No Late Submission will be Tolerated)

Question # 1 (CLO2, C4, PLO2) (CLO4, P5, PLO5, PLO10): (3 * 10 = 30)

Unit Converter Project program file is attached (Unit_Converter.c) and you can also get the c
program from https://github.com/achen58/Basic-Unit-Converter)

Group #
Student Name Registration Number Leader
Huma Saulat FA20-CHE-035
Hadia Saulat FA20-CHE-036 Hadia Saulat

Run and analyze the c code given in Unit_Converter.c file and demonstrate your thoughts
about the following questions:
Q1) Draw the flow of structure given in program.

Q2) Elaborate the purposes of variables used in temperature module and name them.
Temperature Module
TempChoice=To store variables for the choice of users unit conversion .
Category=To store variable T,for users preference of temperature conversion .
Fahrenheit to Celsius=Variables that store the converted F+ C.
Celsius to Fahrenheit=Variables that keep converted C+F.
After applying the formula these last two integers give output.
userinputf=If user enter fahrenheit unit it will store here.
userinputc=If user enter celsius unit it will store here.

Q3) Discuss the formula used for temperature conversion and also describe the purpose of 5/9
and 9/5 in the formula.
Fahrenheit To Celsius = (F-32) * (5/9)
Celsius To Fahrenheit = (9/5)*(C + 32) With the rise of temperature on the Celsius scale,
The temperature on the Fahrenheit scale also rises and vice versa. So, the ratio of change from
C to F is 100/180 or 5/9.
So °C= (F-32) x(5/9).
From F to C, it is 180/100 or 9/5. Thus on conversion, we get °F = °C × (9/5) + 32
K=C+273.15
C=K-273.15
C=5/9 (F-32)
F=9/5C+32
The purpose of 5/9 and 9/5 withinside the formula is a rearranged model of C=5/9(F-32) whilst
we rearrange this equation for fahrenheit is 5/9 becomes 9/5C+32
Q4) How can we convert if else structure to switch statement for this problem.

Switch (Category){
case(T):
Switch(temperature){
Case1:
F to C
Case2:
C to F
}
Case(C):
Switch(Currency Choice){
Case1:
USD to Euro
Case2:
USD to JYP
Case3:
USD to RMB
CaseM:
Switch(Mass Choice){
Case1:
Ounce to Pounds
Case2:
gram to Pounds
}

Q5) Why this program only asks users choice only once? And how can we make it repetitive?
Program only run one time because it is set on default ,we have not used loops yet to make
program repeat, we have to use loops , for loop , while loop, do while loop can be used , after
declaration of integers in our program ,we can set loop limits for the amount of reparations we
want, with an increment in it.

Q6) Why this program is divided into three different modules (Temperature, Currency and
Mass)? What difference will it make if we just enter any value and it converts?
If we let the user input any value, our system may be not able to recognize the value category,
moreover every category is interlinked with its units which desires to be converted otherwise if we
dont divide he program we can't decide which operation we need to use to the input and the output
may be overmixed.
Q7) Why this program uses the concept of nested if? How can we overcome this (remove
nested if)?
We have used Nested if Statement because we have subcatogaories in our program e.g
category choice have 3 options of T , C , M which onwards have sub categories e.g units and
yes we can do it through switch statement , as desired above in question 4.

Q8) As we know that USD rate varies time to time, but this program converts currency with
fix rates. How can we perform Currency Conversion more accurately?

If you know the exchange rate, divide your current currency by the exchange rate. For
example, suppose that the USD/EUR exchange rate is 0.631 and you'd like to convert
100 USD into EUR.To accomplish this, simply multiply the 100 by 0.631 and the result
is the number of EUR that you will receive: 63.10 EUR.

Q9) What if user input the amount of billion or trillion dollars to convert? Can used datatypes
handle that much amount? If no, then what is the solution?
We can store large values using long int data type with the help of this data type we can store
data upto 64 bits.
Q10) Can we make three different functions for three different modules? If yes, then will our
modified code be more efficient or not?

Yes we can make these different functions for our modules and yes it will be more efficient ,
faster to run and easily readable . We will just call the function and it will execute.

You might also like