41. Executing the "continue" statement from within a loop
causes control to go
A. to the next line of code
B. out of the loop
C. to the beginning of the loop
D. to check the loop condition for repeating the loop
E. none of the above
42. The 'default' statement inside a 'switch()' is optional.
T__ F__
43. The following 'switch' implementation is legal:
int i = 2;
switch(i)
{
case 1:
case 2:
case 3:
cout << "i is 1, 2 or 3\n";
break;
}
T__ F__
44. The following program is logically incorrect:
switch ( n )
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
T__ F__
45. The following code-segment of ‘main()’ is not a legal switch implementation:
switch(grade)
{
case 'A' : case 'a': a_count++; break;
case 'B' : case 'b': b_count++; break;
case 'C' : case 'c': c_count++; break;
case 'D' : case 'd': d_count++; break;
case 'F' : case 'f': f_count++; break;
case '\n': case ' ': break;
default: cout << "Not a grade. Enter a new grade \n";
}
T__ F__
46. The following code-segment of ‘main()’ is not accepted by the compiler:
for ( int x = 1; x <= 20; ++x )
{
if ( x % 5 == 0 )
cout << x << endl;
else
cout << x << '\t';
}
cout << x << endl;
T__ F__
47. The following code is incorrect:
int x;
for (x = 100, x >= 1, ++x )
cout << x << endl;
T__ F__
48. The following code-segment of ‘main()’ is considered illegal:
for (int i{1}; i < 10; i++)
{
cout << i << ' ';
if (i == 4) break;
}
T__ F__
49. The following code-segment of ‘main()’ is considered legal:
for (int i{}; i < 10; i++) {
if (i != 5) continue;
cout << i << " "; }
T__ F__
50. The following loop implementation is accepted by the compiler:
for ( int i = 0; i<5; (cout << "i = " << i << ' '), i++ );
T__ F__
(41) Executing the "continue" statement from within a loop causes control to go
Answer: (C) to the beginning of the loop
When the compile encounters the statement “continue” inside the loop then control of the program will jump to the beginning of the given loop for compiling the next iteration. It skips the current iteration statements.
(42) The 'default' statement inside a 'switch()' is optional.
Answer: True
(43) The following 'switch' implementation is legal:
int i = 2;
switch(i)
{
case 1:
case 2:
case 3:
cout << "i is 1, 2 or 3\n";
break;
}
Answer: True
(44) The following program is logically incorrect:
switch ( n )
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Answer: False
(45) The following code-segment of ‘main()’ is not a legal switch implementation:
switch(grade)
{
case 'A' : case 'a': a_count++; break;
case 'B' : case 'b': b_count++; break;
case 'C' : case 'c': c_count++; break;
case 'D' : case 'd': d_count++; break;
case 'F' : case 'f': f_count++; break;
case '\n': case ' ': break;
default: cout << "Not a grade. Enter a new grade \n";
}
Answer: False
(46) The following code-segment of ‘main()’ is not accepted by the compiler:
for ( int x = 1; x <= 20; ++x )
{
if ( x % 5 == 0 )
cout << x << endl;
else
cout << x << '\t';
}
cout << x << endl;
Answer: False
(47) The following code is incorrect:
int x;
for (x = 100, x >= 1, ++x )
cout << x << endl;
Answer: True
(48) The following code-segment of ‘main()’ is considered illegal:
for (int i{1}; i < 10; i++)
{
cout << i << ' ';
if (i == 4) break;
}
Answer: False
(49) The following code-segment of ‘main()’ is considered legal:
for (int i{}; i < 10; i++)
{
if (i != 5) continue;
cout << i << " ";
}
Answer: True
(50) The following loop implementation is accepted by the compiler:
for ( int i = 0; i<5; (cout << "i = " << i << ' '), i++ );
Answer: True
41. Executing the "continue" statement from within a loop causes control to go A....
31. The following code segment is syntactically correct: int number{20}; cout << number << setbase(16) << " " << number << setbase(10) << " " << number << showpos << " " << number << endl; T__ F__ 32. The following statement wants to determine if ‘count’ is outside the range of 0 through 100: if (count < 0 && count > 100) T__ F__ 33. There is...
1. Every C++ program must have: A. a cout statement B. function main C. a #include D. All of the above 2. main() is a method that is part of the ‘Standard Library’. T__ F__ 3. Inside a ‘Console Application’, a ‘Project’ may implement multiple ‘Solutions’. T__ F__ 4. The C++ source-code files are listed with the extension .sln. T__ F__ 5. It is recommended to start...
3. Inside a ‘Console Application’, a ‘Project’ may implement multiple ‘Solutions’. T__ F__ 6. The following declaration is legal in C++: int sample{23.5}; T__ F__ 7. The following functional-declaration-style is no longer legal in C++: int sample(23.5); T__ F__ 8. The following statement is not accepted by the compiler: char c{500}; T__ F__ 9. But the following statement is accepted by the compiler: char c(500); ...
81. The following function call doesn’t agree with its prototype: cout << BoxVolume( 10, 5 ); int BoxVolume(int length = {1}, int width = {1}, int height = {1}); T__ F__ 82. The following function is implemented to swap in memory the argument-values passed to it: void swap(int a, int b) { int temp; temp = a; a = b; b = temp; ...
61. The following program is accepted by the compiler: int sum( int x, int y ) { int result; result = x + y; } T__ F__ 62. The following implementation is accepted by the compiler: void product() { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; ...
Could use some help with this, Instructions: You will need to add an input statement for the grade variable to this code. Also add a for loop so that you can enter more than one grade. Code the for loop so that at least 7 grades can be entered. #include <iostream> #include <string> using namespace std; void main() { char grade; for (int x = 0; x < 7; x++) { cout << "Enter a...
The switch Statement C++program This lab work with the switch statement. • Remove the break statements from each of the cases. What is the effect on the execution of the program? • Add an additional switch statement that allows for a Passing option for a grade of D or better. Use the sample run given below to model your output. Sample Run: What grade did you earn in Programming I? YOU PASSED! An A - excellent work! The following is...
I am working on this switch program everything seems to be ok but the compiler is giving me an error on the final closing brace and wanted to know where I am making an error #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int choice; char repeat; double MidTerm = 0; double FinalExam = 0; double Quiz1 = 0; double Quiz2 = 0; double MidTermGrade = 1, FinalExamGrade = 2, Quiz1Grade = 3, Quiz2Grade = 4,...
Find the errors in following program. //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score. #include <iostream> uisng namespace std; int main() { int testScore; cout<<"Enter your test score and I will tell you\n"; cout<<"the letter grade you earned: "; cin>>testScore; switch (testScore) { case (testScore < 60) cout<<"Your grade is F.\n"; break; case (testScore <70) cout<<"Your grade is D.\n" break; case (testScore <80) cout<<"Your grade is...
Find the errors in following program. //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score. #include <iostream> uisng namespace std; int main() { int testScore; cout<<"Enter your test score and I will tell you\n"; cout<<"the letter grade you earned: "; cin>>testScore; switch (testScore) { case (testScore < 60) cout<<"Your grade is F.\n";...