Hello, today is our lab7 which about Repetition topic.
The first question is
asking about the output. The loop will be kept repeated until the maximum
number of type int. The answer is 2147483648.
The second question is asked to trace the coding
with the selection statement inside the loops statements. The output for the boolean
type will show either true or false depend on the statement in the Boolean. When the s is greater than 5, the statement will straight print the s and break and end the program.
The third question is asked to onvert the while loop
into a do-while loop. The differences between while loop and do-while loop is
while loop will do the loop body if the condition is true and do-while loop
will execute the body of the loop first before checking the condition.
The forth question is asked to write a for loop that
prints the numbers from 1 to 100. The initial- action is int number = 1, loop
continuation condition number <= 100 and action after each iteration number++
The fifth question is asked to convert the for loop
statement to a while and do-while loop.
The first picture is the while loop while the second picture is the do-while loop.
The question 6 is about nested loop.
The first pass of the outer loop triggers the inner loop,
which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the
outer loop finishes.
The
question 7 is asked to write a program that prompts the user to enter a string
and then displays the number of vowels in the string. Due to the question is about string, we must use the string type to prompt the user to enter the word in cmd. Then, we need to use if-else statement in solving this problem.
The
question 8 is requested to write a program that prompts the user to enter
student’s name and the student’s test 1 score and finally display the name of
the student with the highest score. The main point for this question is to declare the highestScore as 0 and keep to be compared with other score under the loops statement.
The question 9 is asked to write a
program that plays the popular rock-paper-scissor game. The program prompts the
user to enter a number 0, 1 or 2 and displays a message indicating whether the
user or the computer wins, loses or draws. Let the user continuously play until
either the user or the computer wins three times more than their opponent. The coding is written in which program will end either user or computer wins for three times.
The question 10 is to ask for finding
the minimum point on the function f(x) = (x – 2 )2 + 1 where x = [-1, 0, … , 4]
using random optimization. This question is quite complicate, but finally I am able to run the program with the help from friends and google.
That's all for today's lab. From lab7, I have more understanding about repetition for loops. The basic in loops must be understood in very detail way so that the question being asked able to be solved. Thank you. See you all again next week.
LIM XUE TING
183615
SSK3100
(Group15)
Next blog: hennyabigail.blogspot.com (Henny
Abigailwillyen Sinjus)
Sometimes Binance users become unable to send and receive an address that seems too irritating to its users. This needs to be fixed as soon as possible. Therefore make a call on Binance phone number which you may find online quickly to know about the solution to such problem. The only need is to let us know about the issues calling our phone number and get the instant solution in no time. You can enjoy their services at fullest because you don’t have to pay for it.
ReplyDelete