Professional Documents
Culture Documents
Lab 4
Lab 4
4
COMPUTATION
I. Objectives:
Cognitive
a) understand the input-process-output
b) understand how operators are used
c) identify the different operators
.
Psychomotor:
b) construct a program that asks inputs from user, uses different operators and performs
calculations with the use of different operators.
Affective
a) appreciate the concept behind operators.
III.EXPERIMENTAL PROCEDURE:
1. Declaring and printing variables. Given the table below, declare the following variables
with the corresponding data types and initialization values. Output to the screen the variable names
together with the values.
2. Getting the average of three numbers. Create a program that outputs the average of three
numbers. Let the values of the three numbers be, 10, 20 and 45. The expected screen output is,
number 1 = 10
number 2 = 20
number 3 = 45
Average is = 25
3. Output greatest value. Given three numbers, write a program that outputs the number with the
greatest value among the three. Use the conditional ?: operator that we have studied so far (HINT:
You will need to use two sets of ?: to solve this). For example, given the numbers 10, 23 and 5,
your program should output,
number 1 = 10
number 2 = 23
number 3 = 5
The highest number is = 23
4. Operator precedence. Given the following expressions, re-write them by writing some parenthesis
based on the sequence on how they will be evaluated.
1. a / b ^ c ^ d – e + f – g * h + i
2. 3 * 10 *2 / 15 – 2 + 4 ^ 2 ^ 2
3. r ^ s * t / u – v + w ^ x – y++
5. The user will input a Philippine amount, then the said amount will be converted to different currencies
namely: US Dollar, Euro, Yuan, Koruna, Krone, Sheqel and Dinar
Sample run:
Enter Philippine peso: 43.33089
Suppose, 1.000 US Dollar is equivalent to Php. 43.33089, 0.734719Euro, 6.346934 Yuan, 18.77263
Koruna, 5.449007 Krone, 3.726334 Sheqel, and 0.274588 Dinar.
1. Which of the four arithmetic operators can operate on string as well as numeric operands?
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
2. Assuming total is a variable, how else could you express in code total = total +2?
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________