-
Flashcards
-
Learn
-
Test
-
Match
-
Flashcards
-
Learn
-
Test
-
Match
Terms in this set [22]
Sets with similar termsSets found in the same folderOther sets by this creatorVerified questions
COMPUTER SCIENCE
Verified answer
COMPUTER SCIENCE
Write an algorithm to read in a sequence of values $\mathrm {v} \geq 0$ one at a time, and determine if the list contains at least one adjacent pair of values that are identical. The end of the entire list is marked by the special value V = −1. For example, if you were given the following input: 14, 3, 7, 7, 9, 1, 804, 22, −1, the output of your algorithm should be a ‘Yes’ because there is at least one pair of adjacent numbers that are equal [the 7s]. However, given the following input: 14, 3, 7, 77, 9, 1, 804, 22, −1, the output of your algorithm should be a ‘No’ because there are no adjacent pairs that are equal. You may assume in your solution that there are at least two numbers in the list.
Verified answer
COMPUTER SCIENCE
Verified answer
COMPUTER SCIENCE
Verified answer
Recommended textbook solutions
Home
Subjects
Expert solutions
Create
Log in
Sign up
Upgrade to remove ads
Only SGD 41.99/year
- Science
- Computer Science
- Algorithms
-
Flashcards
-
Learn
-
Test
-
Match
-
Flashcards
-
Learn
-
Test
-
Match
Terms in this set [36]
Repetition structure
More commonly known as a loop, a repetition structure causes a statement or set of statements to execute repeatedly as many times as necessary.
Condition-controlled loop
A
condition-controlled loop causes a statement or set of statements to repeat as long as a condition is true. In Python you use the "while" statement to write a condition-controlled loop.
The while loop gets its name from the way it works: while a condition is true, do some task.
Count-controlled loop
A count-controlled loop iterates a specific number of times. In Python you use the "for" statement to write a count-controlled loop. The for statement is designed to work with a sequence of data items. When the statement executes, it iterates once for each item in the sequence.
Loop iteration
Each execution of the body of a loop.
Does the while loop test its condition before or after it performs an iteration?
Before;
The while loop
is known as a pretest loop, which means it tests its condition before performing an iteration.
What is an accumulator?
The variable used to keep the running total is called an accumulator.
Should an accumulator be initialized to any specific value? Why or why not?
Yes, to 0.
the first step is to set the accumulator variable
to 0. This is a critical step. Each time the loop reads a number, it adds it to the accumulator. If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.
What is a sentinel?
A sentinel is a special value that marks the end of a sequence of values.
Why should you take care to choose a distinctive value as a sentinel?
A sentinel value must be distinctive enough that it will not be mistaken as a regular value in the sequence.
What does the phrase "garbage in, garbage out" mean?
GIGO; refers to the fact that computers cannot tell the difference between good data and bad data. If a user provides bad data as input to a program, the program will process that bad data and, as a result,
will produce bad data as output.
The integrity of a program's output is only as good as the integrity of its input.
Give a general description of the input validation process.
Input validation is the process of inspecting data that has been input to a program, to make sure it is valid before it is used in a computation.
Input validation is commonly done with a loop that iterates as long as an input
variable references bad data.
Describe the steps that are generally taken when an input validation loop is used to validate data.
Get input
Validate input
Input = good? Go to next
Input = bad? Display error, get input again
What is a priming read? What is its purpose?
The first input operation-just before the loop-is called a priming read, and its purpose is to get the first input value that will be tested by the validation loop.
If the input that is read by the priming read is valid, how many times will the input validation loop iterate?
None
A _______-controlled loop uses a true/false condition to control the number of times that it repeats.
a. Boolean
b.
condition
c. decision
d. count
condition
A _______-controlled loop repeats a specific number of times.
a. Boolean
b. condition
c. decision
d. count
count
Each repetition of a loop is known as a[n] _______.
a. cycle
b. revolution
c. orbit
d. iteration
iteration
The while loop is a _______ type of loop.
a. pretest
b. no-test
c. prequalified
d. post-iterative
pretest
A[n] _______ loop has no way of ending and repeats until the program is interrupted.
a. indeterminate
b. interminable
c. infinite
d. timeless
infinite
The -=
operator is an example of a[n] _______ operator.
a. relational
b. augmented assignment
c. complex assignment
d. reverse assignment
augmented assignment
A[n] _______ variable keeps a running total.
a. sentinel
b. sum
c. total
d. accumulator
accumulator
A[n] _______ is a special value that signals when
there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list.
a. sentinel
b. flag
c. signal
d. accumulator
sentinel
GIGO stands for
a. great input, great output
b. garbage in, garbage out
c. GIGahertz Output
d. GIGabyte Operation
garbage in, garbage out
The
integrity of a program's output is only as good as the integrity of the program's
a. compiler .
.b. programming language.
c. input.
d. debugger.
input
The input operation that appears just before a validation loop is known as the
a. prevalidation read.
b. primordial read.
c. initialization read.
d. priming read.
priming read
Validation loops are also known as:
a. error traps.
b. doomsday loops.
c. error avoidance loops.
d. defensive loops.
error traps
A condition-controlled loop always repeats a specific number of times.
T or F
True
The while loop is a pretest loop.
T or F
True
The following statement subtracts 1 from x: x = x - 1
T or F
True
It is not necessary to initialize accumulator variables.
T or F
False
In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loop.
T or F
True
To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.
T or F
False
The process of input validation works as follows: when the user of a program enters invalid data, the program should ask the user "Are you sure you meant to enter that?" If the user answers "yes," the program should accept the data.
T or F
False
What is an infinite loop?
A loop that has no way of ending and repeats until the program is interrupted.
Why is it critical that accumulator variables are properly initialized?
If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.
What is the advantage of using a sentinel?
When processing a long sequence of values with a loop, a better technique is to use a sentinel.
A sentinel is a special value that marks the end of a sequence of items. When a program reads the sentinel value, it knows it has reached the end of the sequence, so the loop terminates.
Electricity
288 terms
ddavidc20
MUS 1500
88 terms
elizabeth_hayden
MUS 1500 mid term
99 terms
jordanfarrel
MUS 1500 - final - Western Michigan University
51 terms
BLipp22
Other sets by this creatorStarting Out With Python Chapter 3
77 terms
Rglave
Physics Ch 23: Gauss' Law
11 terms
Rglave
Calc 2 chapter 11
12 terms
Rglave
Chemistry
115 terms
Rglave
Verified questionsCOMPUTER SCIENCE
Under what circumstances would a client prefer a location transparent DFS? Under what circumstances would she prefer a location-independent DFS? Discuss the reasons for these preferences.
Verified answer
COMPUTER SCIENCE
This program should be designed and written by a team of students. Here are some suggestions: - One student should design function main, which will call the other functions in the program. The remainder of the functions will be designed by other members of the team. - The requirements of the program should be analyzed so each student is given about the same work load. - The parameters and return types of each function should be decided in advance. - The program can be implemented as a multi-file program, or all the functions can be cut and pasted into the main file.
Verified answer
COMPUTER SCIENCE
Which of the following reserved words is used in the class header of a class that implements an interface? a. interface, b. implements, c. abstract, d. void, e. final.
Verified answer
COMPUTER SCIENCE
Write a program that computes the fare on the Copenhagen Transit system given two inputs from the user: The zone number. The passenger type. Your prompts to the user must be : Enter zone number : Enter adult or child : The fare on Copenhagen Transit is specified as follows: If the zone is 2 or smaller and the ticket type is "adult," the fare is 23.0. If the zone is 2 or smaller and the ticket type is "child," the fare is 11.5. If the zone is 3 and the ticket type is "adult," the fare is 34.5. If the zone is 3 or 4 and the ticket type is "child," the fare is 23.0. If the zone is 4 and the ticket type is "adult," the fare is 46.0. If the zone is greater than 4, the fare is -1.00 [since your calculator does not handle inputs that high]. Your output must be of the format: The fare for adultOrChild to zone number zoneNumber is fare. Please note that your class should be named CopenhagenTransit.
Verified answer
Recommended textbook solutions
Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th EditionDavid A. Patterson, John L. Hennessy
220 solutions
Engineering Electromagnetics
8th EditionJohn Buck, William Hayt
483 solutions
Introduction to the Theory of Computation
3rd EditionMichael Sipser
389 solutions
Computer Organization and Architecture
10th EditionWilliam Stallings
497 solutions
Other Quizlet setsQuiz 10
10 terms
jonathan_dennis10
OCE1101 Chapter 5
90 terms
melanie_t_d
Quadrilaterals Review
28 terms
Eugenia_Latka
PERMIT
17 terms
tanyasprague
Related questionsQUESTION
Many tasks, large and small, can be solved by performing a specific set of actions and making a particular set of decisions in very precise ways. These sets of actions and decisions are known as what?
15 answers
QUESTION
What are the 3 types of sort?
10 answers
QUESTION
Check all that apply to dynamic allocation of a broadcast channel with capacity C assuming there are n stations with n ≥ 2.
4 answers
QUESTION
the step of the IPDE where you look ahead and locate a hazard
2 answers