0% found this document useful (0 votes)
375 views2 pages

Answer:: Mean Static - Cast (Float) (Total) /value? What Do You Think Will Happen If It Is Removed?

This document contains the tasks and answers from a student's programming assignment. It involves several short programs related to rainfall data, vending machines, calculating means, and modifying a nested loop based on user input. For each task, the student provides code snippets to complete the tasks and explains the outputs and behaviors of the programs for different test cases and scenarios.

Uploaded by

klyn pontero
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
375 views2 pages

Answer:: Mean Static - Cast (Float) (Total) /value? What Do You Think Will Happen If It Is Removed?

This document contains the tasks and answers from a student's programming assignment. It involves several short programs related to rainfall data, vending machines, calculating means, and modifying a nested loop based on user input. For each task, the student provides code snippets to complete the tasks and explains the outputs and behaviors of the programs for different test cases and scenarios.

Uploaded by

klyn pontero
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Klyn Marion D.

Pontero
EDP 101L(1095)
Ulo-2C

Task A.
1. This program is not user-friendly. Run it a few times and explain why.
2. How would this code affect the execution of the program if the while loop is
replaced by a do-while loop? Try it and see
ANSWER:
1. The program is not user friendly because it does not show the user how to exit the
program and does not tell the user when to stop.
2. The loop body of the program will always execute at least once.

Task B.
1. Run the program several times with various input. Record your results. Are they
correct?
2. What happens if you enter –1 first?
3. What happens if you enter only values of 0 for one or more months?
4. Is there any numerical data that you should not enter?
ANSWER:
1. Yes the results are correct
2. The program will not display any data and exits the program
3. The program will continue to increase the month
4. Numerical data should be not equal to -1 and the total rainfall should not be
negative.

Task C.
1. Fill in the indicated code to complete the above program. Then compile and run
the program several times with various inputs. Try all the possible relevant cases
and record your results. What did you realize from this exercise?
2. What do you think will happen if you do not enter A, B, C, D, or E? Try running
the program and inputting another letter.
ANSWER:
1. This exercise shows the program on vending machines it tally the users choice on
how many does he want from his\her choice.
2. The input you put will be invalid and the program tells you to choose another
letter.

Task D.
1. Why is the typecast operator needed to compute the mean in the statement
mean=
static_cast(float)(total)/value? What do you think will happen if it is removed?
Modify
the code and try it. Record what happens. Make sure that you try both even and odd
cases. Now put static_cast<float> total back in the program.
2. What happens if you enter a float such as 4.58 instead of an integer for value? Try
it
and record the results.
ANSWER:
1. The odd cases answer will not be affected however the even number if the
static_cast<float> total will be removed the answer will not show in decimal form.
2. The program will disregard the float and instead it calculates it as a whole number
and not a float.

Task E.
Note that the inner loop of this program is always executed exactly three times—
once for
each day of the long weekend. Which part of the code you need to alter so that the
inner
loop iterates n times, where n is a positive integer input by the user. In other words,
let the
user decide how many days to consider just as they choose how many students to
consider.
ANSWER:
You must change the condition in for(day = 1; day <= 3; day++) to for(day = 1; day <=
numDays; day++), then declare int numDays in the program then change the average
= total / 3 into average = total / numDays. This program will now let the user
decide on how many day to consider.

You might also like