Deck 2: Flow of Control

ملء الشاشة (f)
exit full mode
سؤال
Write multiway if-else statements for which the output is "Alarm: Boiler Pressure: TOO HIGH" if the value of the variable boiler_pressure is greater than 1000 (psi),and the output is "Boiler Pressure: TOO LOW" if the value of boiler_pressure is below 100(psi),otherwise the output is "Boiler Pressure: within normal limits."
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
In a do-while loop,a continue statement terminates the loop.
سؤال
In a while loop,the Boolean_Expression is executed before each execution of the loop body.
سؤال
Write Boolean expressions that represent the given English expressions.Assume any variables used have been declared and initialized.
a)alpha is greater than 1
b)x is odd
c)x and y are odd
d)ch is an upper case alphabetic character (between 'A' and 'Z').
e)digit,which is f type char,has value that is indeed a digit.
سؤال
A break statement is used in loops only.
سؤال
A numeric integer grade is between 50 and 99.Using integer division or otherwise obtain a int value that is 5,6,7,8,or 9 from the numeric grade.Write code using a switch statement using this number in the selector expression that assigns letter grades based on this 10 point scheme:
if the numeric_grade is not less than 90,the letter_grade is an A,
if the numeric_grade is not less than 80,the letter_grade is a B,
if the numeric_grade is not less than 70,the letter_grade is C,
if the numeric_grade is not less than 60,the letter_grade is D,
otherwise the letter_grade is F.
سؤال
The if,while and for statements control only one statement.
سؤال
Assume variables first,second,and max are declared to be double and are initialized.Write a sequence of lines of code that cause the larger of the values in first and second to be stored in max.
سؤال
Assume variables first and second are declared to be double and are initialized.Write a sequence of lines of code that cause the values stored in first and second to be exchanged if the value of first is not less than second.
سؤال
Write multiway if-else statements in which letter grades are assigned based a numeric grade based on this "ten point" scheme:
if the numeric grade is not less than 90,the letter grade is an A,
if the numeric grade is not less than 80,the letter grade is a B,
if the numeric grade is not less than 70,the letter grade is C,
if the numeric grade is not less than 60,the letter grade is D,
otherwise the letter grade is F.
سؤال
The value of count is 0;limit is 10.Evaluate:
(count == 0)&&(limit < 20)
سؤال
Suppose we have these declarations,
int x = -1,y = 0,z = 1;
This Boolean expression is correct and it does what the programmer intends.
x < y < z
سؤال
Given the declaration
int x = 0;
The following expression causes a divide by zero error:
(x !=0)|| (2/x < 1);
سؤال
Write Boolean expressions that represent the given English expressions.Assume any variables used have been declared and initialized.
a)at least one of x or y is odd
b)at least one of x or y is non-negative (x is non-negative is written x >= 0)
c)The hit is no more than 2.5 units away from target
d)x is 1 or x is equal to y
e)t is strictly between 3.2 and 3.3
سؤال
You want to determine whether time has run out.The following code correctly implements this.
!time > limit
سؤال
When a loop is nested in side another loop,a break or continue statement terminates or restarts the outermost loop of the nested loop structure.
سؤال
The value of count is 0;limit is 10.Evaluate:
count == 0 && limit < 20
سؤال
Use the condition operator (x?y:z)to write a very compact expression that assigns the maximum of variables n1 and n2 to the variable max.You should assume that any variables you use have been declared and initialized appropriately.
سؤال
Explain the programmer's saying from the text,section 2.2,"Garbage in means garbage out."
سؤال
The value of count is 0;limit is 10.Evaluate:
(count != 0)||(limit < 20)
سؤال
A switch statement must have

A)a default case
B)more than one non-default case
C)a break statement
D)none of the above
E)all of the above
سؤال
If the following code fragment is executed in an otherwise complete and correct program,which expression will be executed? Why? x = 0;
If (x = 12)
Yes_statement;
Else
No_statement;

A)The no_statement will be executed because x is not 12.
B)The statement has incorrect syntax so will not compile at all.
C)x=12 is illegal in the Boolean expression of an if statement.
D)The yes_statement will be executed.
سؤال
Write the following do-while statement with a while construct,and maybe some extra code.
x = 10;
do
{
cout << x << endl;
x = x - 3;
} while ( x > 0 );
سؤال
In the expression (j > 0 && j+1 == 10),which operator executes last?

A)>
B)&&
C)+
D)==
سؤال
For each of the following situations,tell which type loop (while,do-while,or for)would be best in that situation:
a)Reading a list of an unknown number of homework grades for a single student.
b)Summing a series such as 1 +1/2 +1/(22)+ 1/(23)+ … + 1/(28)
c)Testing a newly coded library function to see how it performs for different values of its arguments.
d)Reading in the number of days of vacation taken by an employee.
سؤال
Write a program that reads in and sums the squares of positive integers until a value that 0 or less is read in.
سؤال
Consider the if statement: if(condition)yes_clause;else no_clause;
Under which of the following circumstances will both the yes_clause and the no_clause will be executed?

A)When the condition is true.
B)When the condition is false.
C)When the condition is ambiguous.
D)This will not happen.
سؤال
Which of the following determines the operator that is processed prior to another operator?

A)Operator associativity
B)Operator precedence
C)Whether the operator is an arithmetic operator
D)None of these determine the order in which operators are processed.
سؤال
What is the output of the following,if it were embedded in an otherwise correct and complete program and run? int x = 10;
While (x > 0)
{
Cout << x << " ";
X = x + 3;
}
Cout << endl;

A)10 13 16 19 ...
B)The compiler detects that this will be an infinite loop,so it does not compile. Insert lowercase be
C)This is an infinite loop.When compiled and run,it runs until machine limitations stop it,or you get tired of it and kill the process.
D)0 3 6 9.
سؤال
Write a program that reads in exactly 10 integers and outputs the sum.
سؤال
Which of the following control structures requires curly braces?

A)if-else
B)while
C)do-while
D)switch
E)for
سؤال
Which of the following loop statements is guaranteed to iterate the body of the loop at least once?

A)while(control)body;
B)do body while(control);
C)for (initialize;test;update)body;
D)none of the above
E)all of the above
سؤال
Predict the output of the following nested loops:
int n = 1;
while(n <= 10)
{
int m = 10;
while(m>=1)
{
cout << n << " times " << m
<< " = " << n*m << endl;
m--;
}
n++;
}
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/33
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 2: Flow of Control
1
Write multiway if-else statements for which the output is "Alarm: Boiler Pressure: TOO HIGH" if the value of the variable boiler_pressure is greater than 1000 (psi),and the output is "Boiler Pressure: TOO LOW" if the value of boiler_pressure is below 100(psi),otherwise the output is "Boiler Pressure: within normal limits."
if (boiler_pressure > 1000)
cout << "Boiler Pressure: TOO LOW\n";
else if (boiler_pressure < 100)
cout << "Boiler Pressure: TOO LOW\n";
else
cout << "Boiler Pressure: within normal limits.\n";
2
In a do-while loop,a continue statement terminates the loop.
False
3
In a while loop,the Boolean_Expression is executed before each execution of the loop body.
True
4
Write Boolean expressions that represent the given English expressions.Assume any variables used have been declared and initialized.
a)alpha is greater than 1
b)x is odd
c)x and y are odd
d)ch is an upper case alphabetic character (between 'A' and 'Z').
e)digit,which is f type char,has value that is indeed a digit.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
5
A break statement is used in loops only.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
6
A numeric integer grade is between 50 and 99.Using integer division or otherwise obtain a int value that is 5,6,7,8,or 9 from the numeric grade.Write code using a switch statement using this number in the selector expression that assigns letter grades based on this 10 point scheme:
if the numeric_grade is not less than 90,the letter_grade is an A,
if the numeric_grade is not less than 80,the letter_grade is a B,
if the numeric_grade is not less than 70,the letter_grade is C,
if the numeric_grade is not less than 60,the letter_grade is D,
otherwise the letter_grade is F.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
7
The if,while and for statements control only one statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
8
Assume variables first,second,and max are declared to be double and are initialized.Write a sequence of lines of code that cause the larger of the values in first and second to be stored in max.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
9
Assume variables first and second are declared to be double and are initialized.Write a sequence of lines of code that cause the values stored in first and second to be exchanged if the value of first is not less than second.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
10
Write multiway if-else statements in which letter grades are assigned based a numeric grade based on this "ten point" scheme:
if the numeric grade is not less than 90,the letter grade is an A,
if the numeric grade is not less than 80,the letter grade is a B,
if the numeric grade is not less than 70,the letter grade is C,
if the numeric grade is not less than 60,the letter grade is D,
otherwise the letter grade is F.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
11
The value of count is 0;limit is 10.Evaluate:
(count == 0)&&(limit < 20)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
12
Suppose we have these declarations,
int x = -1,y = 0,z = 1;
This Boolean expression is correct and it does what the programmer intends.
x < y < z
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
13
Given the declaration
int x = 0;
The following expression causes a divide by zero error:
(x !=0)|| (2/x < 1);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
14
Write Boolean expressions that represent the given English expressions.Assume any variables used have been declared and initialized.
a)at least one of x or y is odd
b)at least one of x or y is non-negative (x is non-negative is written x >= 0)
c)The hit is no more than 2.5 units away from target
d)x is 1 or x is equal to y
e)t is strictly between 3.2 and 3.3
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
15
You want to determine whether time has run out.The following code correctly implements this.
!time > limit
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
16
When a loop is nested in side another loop,a break or continue statement terminates or restarts the outermost loop of the nested loop structure.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
17
The value of count is 0;limit is 10.Evaluate:
count == 0 && limit < 20
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
18
Use the condition operator (x?y:z)to write a very compact expression that assigns the maximum of variables n1 and n2 to the variable max.You should assume that any variables you use have been declared and initialized appropriately.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
19
Explain the programmer's saying from the text,section 2.2,"Garbage in means garbage out."
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
20
The value of count is 0;limit is 10.Evaluate:
(count != 0)||(limit < 20)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
21
A switch statement must have

A)a default case
B)more than one non-default case
C)a break statement
D)none of the above
E)all of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
22
If the following code fragment is executed in an otherwise complete and correct program,which expression will be executed? Why? x = 0;
If (x = 12)
Yes_statement;
Else
No_statement;

A)The no_statement will be executed because x is not 12.
B)The statement has incorrect syntax so will not compile at all.
C)x=12 is illegal in the Boolean expression of an if statement.
D)The yes_statement will be executed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
23
Write the following do-while statement with a while construct,and maybe some extra code.
x = 10;
do
{
cout << x << endl;
x = x - 3;
} while ( x > 0 );
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
24
In the expression (j > 0 && j+1 == 10),which operator executes last?

A)>
B)&&
C)+
D)==
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
25
For each of the following situations,tell which type loop (while,do-while,or for)would be best in that situation:
a)Reading a list of an unknown number of homework grades for a single student.
b)Summing a series such as 1 +1/2 +1/(22)+ 1/(23)+ … + 1/(28)
c)Testing a newly coded library function to see how it performs for different values of its arguments.
d)Reading in the number of days of vacation taken by an employee.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
26
Write a program that reads in and sums the squares of positive integers until a value that 0 or less is read in.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
27
Consider the if statement: if(condition)yes_clause;else no_clause;
Under which of the following circumstances will both the yes_clause and the no_clause will be executed?

A)When the condition is true.
B)When the condition is false.
C)When the condition is ambiguous.
D)This will not happen.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
28
Which of the following determines the operator that is processed prior to another operator?

A)Operator associativity
B)Operator precedence
C)Whether the operator is an arithmetic operator
D)None of these determine the order in which operators are processed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
29
What is the output of the following,if it were embedded in an otherwise correct and complete program and run? int x = 10;
While (x > 0)
{
Cout << x << " ";
X = x + 3;
}
Cout << endl;

A)10 13 16 19 ...
B)The compiler detects that this will be an infinite loop,so it does not compile. Insert lowercase be
C)This is an infinite loop.When compiled and run,it runs until machine limitations stop it,or you get tired of it and kill the process.
D)0 3 6 9.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
30
Write a program that reads in exactly 10 integers and outputs the sum.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which of the following control structures requires curly braces?

A)if-else
B)while
C)do-while
D)switch
E)for
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
32
Which of the following loop statements is guaranteed to iterate the body of the loop at least once?

A)while(control)body;
B)do body while(control);
C)for (initialize;test;update)body;
D)none of the above
E)all of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
33
Predict the output of the following nested loops:
int n = 1;
while(n <= 10)
{
int m = 10;
while(m>=1)
{
cout << n << " times " << m
<< " = " << n*m << endl;
m--;
}
n++;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.