Lesson 2
.docx
keyboard_arrow_up
School
Ashworth College *
*We aren’t endorsed by this school
Course
K08V.1.1
Subject
Computer Science
Date
Jan 9, 2024
Type
docx
Pages
6
Uploaded by PrivateIronPorcupine45
Question 1
A programmer created a while loop in C#, but failed to provide an action in the while statement, which
caused the condition of the while to return false. What will the result be?
Question options:
A compiler error
An infinite loop
Code execution stops after 100 loops based on the debugger settings
True
Question 2
Assuming a is a bool with a value of false, which of the following evaluates to true?
Question options:
!(!a)
a
!a
!a!
Question 3
Which of the following operators ensures that at least one out of multiple conditions is TRUE?
Question options:
||
&&
==
^
Question 4
The | and & operators will __________ evaluate all operands in a conditional statement.
Question options:
never
always
conditionally
prematurely
Question 5
In a loop, the programmer can terminate execution within the executing block of code by using the
__________ statement.
Question options:
default
continue
break
XOr
Question 6
In a switch statement, the __________ case will execute code when no match occurs between the
switch's expression label and the case label.
Question options:
default
continue
break
XOr
Question 7
In a loop, the programmer can continue execution within the executing block of code, but skip all
remaining lines and simply return to the loop continuation test by using the __________ statement.
Question options:
default
continue
break
XOr
Question 8
Which case of the following would warrant using the boolean logical inclusive OR (|) rather than the
conditional OR (||)?
Question options:
Testing if two conditions are both true
Testing if at least one of two conditions is true
Testing if at least one of two conditions is true when the right operand has a required side effect
Testing if at least one of two conditions is true when the left operand has a required side effect
Question 9
The __________ loop always performs the logic condition test before attempting to execute the loop's
body.
Question options:
for
case
do while
switch
Question 10
In a switch statement, the programmer can terminate execution within the executing case by using the
__________ statement.
Question options:
default
continue
break
XOr
Question 11
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
All programming languages have a loop capability. Looping is the program logic’s ability to repeat one or more lines of code either:
A set number of times, a “for loop” (i.e. 10, 100, 500, 763 or more times)
An “unknown” number of times (i.e. loop terminates if a tested condition becomes “true” or as long as the tested condition remains “false”), a “while” loop, a “do until” loop, a “do while” loop.
This Lab exercise demonstrates the use of the “For Loop”, a standard loop in all programming languages. C++ standard For Loop format looks like:
For (n = 1; n <= 100; n++)
{
Loop line 1 code;
Loop line 2 code;
Loop line 3 code;
Loop line N code;
}
The loop code needs:
A “loop counter variable” (n in the above example) to keep track of how many iterations this loop has run
A starting value (i.e. 1 in the above example)
A stop test (i.e. run as…
arrow_forward
JAVA
Even if the condition is false at the first execution a while loop at least executes once.
True
False
A while loop can be used both as an event-controlled loop and as a count controlled loop.
True
False
arrow_forward
All of the following are examples of nesting control structure EXCEPT:
OHaving a loop inside an if statement body.
OHaving a function call inside the body a loop
OHaving one loop structure inside another loop structure
Having an if-elif statement inside a loop body
arrow_forward
c++ problem
arrow_forward
True or False
___(4) In a while loop, the body of the loop has to be executed at least once whether the test is true or not.
___(5) In Java a while loop can be changed to a for loop and vice versa.
___(6) Java statement !( x / 3 = = 6 ) || y*3 = = -6 ; evaluates to false if x=19 and y= -2
arrow_forward
C++ code not Java
arrow_forward
Problem Description:
A while loop and do/while loop will repeat code while the condition is true. The basic
difference is when the condition is checked. The while loop checks the condition before the loop
starts or after the loop ends. A do/while loop will check the condition at the end of the loop to
determine if the loop should be repeated. A do/while loop will run at least once whereas a while
may be skipped entirely.
while ( )
do
I/ Repeated code goes here
I/ Repeated code goes here
while ( );
Checkpoint 1: Use a while loop to display the numbers 1 through 10. You must initialize your
loop counter before the loop and increment the loop counter inside the loop.
Checkpoint 2: Use a while to ask the user for a list of numbers. It is not known how many
numbers the user will enter, but the last number will be -1. After all numbers have been entered,
state how many numbers were put in.
Checkpoint 3: Use a do/while loop to display the numbers I through 10. You must initialize
your loop…
arrow_forward
in python
for glass box testing of a while loop, you should test cases where:
a) the while loop is not entered
b) the body of the while loop is executed just once
c) the body of the while loop is executed more than once
e) all of these
f) exiting the loop in the middle of the body
arrow_forward
assembly language please with comment and screen shot of the out put
arrow_forward
PROGRAMMING LANGUAGE: C++
arrow_forward
Design and write a Python program for exercise #19:
Please label your steps with comments (#) on your program
arrow_forward
C++
arrow_forward
computer programming
Loop is used to repeat a sequence of actions or statements many times. Simplydescribe the differences between for-loop and while-loop.
arrow_forward
Describe specific programming situations that require a posttest loop.
arrow_forward
Python
get_user_input(message, sentinel):
The parameter message is the string message to request an integer from the user.
The parameter sentinel is the unique character that signals the end of input.
This function will return value: done, The parameter done is a Boolean flag that signals that the user entered a sentinel value and the value is invalid.
main():
calling the get_user_input function until the sentinel value is detected
capture the output from the get_user_input function into two variables
use the Boolean flag return value to control the loop in main
store the integer return value to a Python list
The program will print the integers entered back to the user only after the sentinel value is detected
arrow_forward
PuTTY/Ocelot
Assignment #2 Instructions: (using C language in the UNIX environment, Systems Programming)
Through this programming assignment, the students will learn to do the following:
Usage: mortgagepmt [-s] -r rate [-d downpayment] price
In this assignment, you are asked to perform a mortgage payment calculation. All information needed for this will be passed to the program on the command line. There will be no user input during the execution of the program
You will need a few pieces of information. The price of the home and the amount of the down payment. You will also need to know the interest rate and the term of the mortgage. To figure your mortgage payment, start by converting your annual interest rate to a monthly interest rate by dividing by 12. Next, add 1 to the monthly rate. Third, multiply the number of years in the term of the mortgage by 12 to calculate the number of monthly payments you'll make. Fourth, raise the result of 1 plus the monthly rate to the…
arrow_forward
C++ Demonstration #3: Create a program that uses a switch statement
for a simple help program. The screen will display the following choices:
1. for
2. if
3. switch
Help on:
Upon choosing the number, the program will output the
following:
If 1: for is C++'s most versatile loop
If 2: if is C++'s conditional branch statement
If 3: switch is C++'s multi-way branch statement
If none: Choose a number between 1 and 3
Enter choice (1 – 3):
arrow_forward
Using a Sentinel Value to Control a while Loop
Summary
In this lab, you write a while loop that uses a sentinel value to control a loop in a Java program that has been provided. You also write the statements that make up the body of the loop.
The source code file already contains the necessary variable declarations and output statements. Each theater patron enters a value from 0 to 4 indicating the number of stars the patron awards to the Guide’s featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, you should display the average star rating for the movie.
Instructions
Ensure the file named MovieGuide.java is open.
Write the while loop using a sentinel value to control the loop, and write the statements that make up the body of the loop to calculate the average star rating.
Execute the program by clicking Run.
Input the following: 0, 3, 4, 4, 1, 1, 2, -1
Check that the average…
arrow_forward
Instruction: It should be a C++ PROGRAM INCLUDE THE HEADER FILE, MAIN CPP, AND BSTREE.CPP
There is a real program developed by a computer company that reads a report ( running text ) and issues warnings on style and partially corrects bad style. You are to write a simplified version of this program with the following features:
Statistics
A statistical summary with the following information:
Total number of words in the report
Number of unique words
Number of unique words of more than three letters
Average word length
Average sentence length
An index (alphabetical listing) of all the unique words (see next page for a specific format)
Style Warnings
Issue a warning in the following cases:
Word used too often: list each unique word of more than three letters if its usage is more than 5% of the total number of words of more than three letters
Sentence length : write a warning message if the average sentence length is greater than 10
Word length : write a warning message if the…
arrow_forward
JAVA
The loop continuation condition is the inverse of the loop termination condition.
True
False
arrow_forward
MUST BE IN PYTHON PROGRAMMING CODE!!!!! NO C++ or Java!!
Directions: Design a program with a loop that lets the user enter a series of names (in no particular order). After the final person’s name has been entered, the program should display the name that is first alphabetically and the name that is last alphabetically. For example, if the user enters the names Kristin, Joel, Adam, Beth, Zeb, and Chris, the program would display Adam and Zeb.
Additional requirements: Note that the possible set of input values can include negative, 0, or positive values, but not the sentinel value of -99.
DESIGN HINT: • When determining the largest (or smallest) value in a set of numbers, remember to use variables to keep track of the current largest (or smallest) number found thus far. These variables can then be used as a comparison to each subsequent input number to see if the new number is larger (or smaller) than the current largest (or smallest) number and updated appropriately. At the end of all…
arrow_forward
PYTHON:
The following code causes an infinite loop. Can you figure out what is incorrect?
def test_code(num):
x = num
while x % 2 == 0:
x = x / 2
test_code(0)
When called with 0, it triggers an infinite loop
The modulo operator is used incorrectly
Missing an else statement
Missing the continue keyword
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Related Questions
- All programming languages have a loop capability. Looping is the program logic’s ability to repeat one or more lines of code either: A set number of times, a “for loop” (i.e. 10, 100, 500, 763 or more times) An “unknown” number of times (i.e. loop terminates if a tested condition becomes “true” or as long as the tested condition remains “false”), a “while” loop, a “do until” loop, a “do while” loop. This Lab exercise demonstrates the use of the “For Loop”, a standard loop in all programming languages. C++ standard For Loop format looks like: For (n = 1; n <= 100; n++) { Loop line 1 code; Loop line 2 code; Loop line 3 code; Loop line N code; } The loop code needs: A “loop counter variable” (n in the above example) to keep track of how many iterations this loop has run A starting value (i.e. 1 in the above example) A stop test (i.e. run as…arrow_forwardJAVA Even if the condition is false at the first execution a while loop at least executes once. True False A while loop can be used both as an event-controlled loop and as a count controlled loop. True Falsearrow_forwardAll of the following are examples of nesting control structure EXCEPT: OHaving a loop inside an if statement body. OHaving a function call inside the body a loop OHaving one loop structure inside another loop structure Having an if-elif statement inside a loop bodyarrow_forward
- c++ problemarrow_forwardTrue or False ___(4) In a while loop, the body of the loop has to be executed at least once whether the test is true or not. ___(5) In Java a while loop can be changed to a for loop and vice versa. ___(6) Java statement !( x / 3 = = 6 ) || y*3 = = -6 ; evaluates to false if x=19 and y= -2arrow_forwardC++ code not Javaarrow_forward
- Problem Description: A while loop and do/while loop will repeat code while the condition is true. The basic difference is when the condition is checked. The while loop checks the condition before the loop starts or after the loop ends. A do/while loop will check the condition at the end of the loop to determine if the loop should be repeated. A do/while loop will run at least once whereas a while may be skipped entirely. while ( ) do I/ Repeated code goes here I/ Repeated code goes here while ( ); Checkpoint 1: Use a while loop to display the numbers 1 through 10. You must initialize your loop counter before the loop and increment the loop counter inside the loop. Checkpoint 2: Use a while to ask the user for a list of numbers. It is not known how many numbers the user will enter, but the last number will be -1. After all numbers have been entered, state how many numbers were put in. Checkpoint 3: Use a do/while loop to display the numbers I through 10. You must initialize your loop…arrow_forwardin python for glass box testing of a while loop, you should test cases where: a) the while loop is not entered b) the body of the while loop is executed just once c) the body of the while loop is executed more than once e) all of these f) exiting the loop in the middle of the bodyarrow_forwardassembly language please with comment and screen shot of the out putarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT