Programming Test 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What are the first and last values of i output by this loop? n = 10; i = 0; while ( i++ < n ) { cout << i << endl; }

1 and 10

What are the first and last values of i output by this loop? n = 10; i = 0; while ( ++i < n ) { cout << i << endl; }

1 and 9

Evaluate the following condition. Is it true or false? (3.0 >= 2.0) || (3.0 >= 4.0)

true

Example of integer is -85.

true

If a condition's value is zero, then the condition is evaluated as false ( i.e., if(0) means false)

true

The math function tan will compute tangent when the angle is given in radians.

true

The operator = = is used to determine whether the left hand operand is equivalent to the right hand operand.

true

The preprocessor directive #include copies the file iostream into the program before compilation, so that the program can use cin and cout and operators.

true

Calculate the values of x (integer arithmetic)? x = 5 / (10 / 5) * 5

x = 10

Calculate the values of x (integer arithmetic)? x = 16 / 5 / 2 * 5

x=5

What is the output? for(int i=0; i<=10; i++) { if(i%2) { cout << i << endl; break; } }

1

In integer arithmetic 8%2 returns a value of

0

What is the output? for(int i=0; i<=5; i++) { if(i%2) break; cout << i << endl; }

0

What are the first and last values of i output by this loop? n = 10; i = 0; do { cout << i << endl; } while ( i++ < n );

0 and 10

What are the first and last values of i output by this loop? n = 20; for ( i = 0; i < n; i++ ){ cout << i << endl; }

0 and 19

What are the first and last values of i output by this loop? n = 10; i = 0; while ( i < n ) { cout << i++ << endl; }

0 and 9

What is the output? for(int i=0; i<=5; i++) { if(i%2) continue; cout << i ; }

024

What is the value of i after the do-while statement below? #include using namespace std; int main(){ int n = 10, i = 0; do {i++;} while ( i < n ); return 0;}

10

What is the value of n outside while? That is, what would you see on the screen if these statements are executed? n = 0; while ( n < 10 ) { n++ ; } cout < n <endl;

10

What will be the output of the following code segment? n = 10; x = 0; do { ++x; } while ( x < n ); cout<<x<<endl;

10

What is the result of the following code (i.e., what is the value of a?): int a, b; a = 10; b = 4; a = b; a = a+7; cout << a;

11

Calculate the values of x? Int j = 4, k=7, n=5, m=2, p=8, x; x = j*m/p/k + n/2;

2

In integer arithmetic 5/2 returns a value of

2

Exercise : What is printed? i=0; while ( i<5 ) { if ( i < 3 ) { i +=2; cout << i << endl; continue; } else { cout << ++i << endl; break; } cout << "bottom of loop" << endl; }

2 4 5

What is the output of this code snippet? int sum = 22; sum = sum + 2; cout << sum++; // sum = sum + 1 cout << sum;

2425

How many times is the statement cout<<"Hi 2"<<endl; executed (i.e., print Hi 2 on the screen)? #include using namespace std; int main(){ int I, J; for (I=2; I>=0; I--) {for (J=1; J<3; J++) { cout << "Hi 1"<<endl;} cout<<"Hi 2"<<endl;} return 0; }

3

What is the final value of x if initially x has the value 0? if (x >= 0) { x += 5; } if (x >= 5) { x -= 2; }

3

What is the output for the following program? #include using namespace std; int main(){ int I, J; for (I=3; I>=1; I--) {for (J=1; J<2; J++) { cout << I;} } return 0; }

321

Which of the following declaration would properly define x, y, z as separate three integers object? 1. x, y, z; 2. int xyz; 3. int x = y = z; 4. int x, y, z;

4. int x, y, z;

What is the output of the following code snippet? #include using namespace std; int main() { cout << 2 * 2 << 6; return 0; }

46

Exercise : What is printed? i=0; while ( i<5 ) { if ( i < 3 ) { i +=2; continue; cout << i << endl; } else { cout << ++i << endl; break; } cout << "bottom of loop" << endl; }

5

How many times is the statement cout<<"Hi 1"<<endl; executed (i.e., print Hi 1 on the screen)? #include using namespace std; int main(){ int I, J; for (I=2; I>=0; I--) {for (J=1; J<3; J++) { cout << "Hi 1"<<endl;} cout << "Hi 2"<<endl;} return 0; }

6

If y has the value 5 what will be the value of the variable y after the following piece of C++ is executed? if (y > 0) y += 2; else y = 3;

7

What is the final value of x if initially x has the value 1? if (x >= 0) { x += 5; } if (x >=5) { x += 2; }

8

What is the correct output from the following program?#include <iostream> using namespace std; int main() { int A, B; A = 6; B = 1; if (A < B) { A = A * B + 2; B ++;} else{ A = A / 2; B = B + 4; } cout << "A = " << A << " B = " << B; return 0; }

A = 3 B = 5

What is the correct output from the following program?#include <iostream> using namespace std; int main() { int A, B; A = 6;B = 1; if (A > B) { A = A * B + 2; B ++;} else{ A = A / 2;B = B + 4;} cout << "A = " << A << " B = " << B; return 0; }

A = 8 B = 2

What is the output? n = 8;if (n>=3){cout << "C++ rocks!"; }cout << "End"<<endl;

C++ rocks! End

What is the output? n = 3;if(n>=8){cout<< "C++ rocks!"<<endl; }cout<< "End"<<endl;

End

What would you see on the screen if these statements are executed? x = 4; If ( x >5) { cout <<" Hi 1"<<endl; } cout <<"End"<<endl;

End

What is the output of the following code snippet? #include using namespace std; int main() { cout << "Goodbye" << endl << "Come again" << endl; return 0; }

Goodbye Come again

What would you see on the screen if these statements are executed? x = 6; If ( x >5); { cout <<" Hi 1"<<endl; } cout <<"End"<<endl;

Hi 1 End

What will be the output of the following code segment? int x = 0, y = 3; if (x < 1) { cout << "Hi 1 "; x = y; } if (x > 1) { cout << "Hi 2 "; } else { cout << "Hi 3 "; }

Hi 1 Hi 2

Which of the following statements should you include in a C++ program that performs an input or output operation? I. using namespace std; II. #include <iostream> III. int main()

I, II, and III

What would you see on the screen if these statements are executed? rank = 6; if (rank==1 || rank==2) { cout << "Lower division"<<endl; } else if (rank==3 || rank==4) { cout << "Upper division"<<endl; } else if (rank==5) { cout << "Graduate student "<<endl; } else { cout << "Invalid rank"<<endl; }

Invalid rank

What is the output from this code snippet? cout << "The sum is " << "8 + 6";

The sum is 8 + 6

#include using namespace std; int main(){ int Num = 7, X = 10, Y = 8; switch (Num) { case 1: X = Num; break; case 2: Y = Y + 3; case 3: X = Num + 4; case 4: Y = Y - 2; break; case 5: X = X * 3; default: Y = Y - 3; } cout << "X = " << X << " and Y = " << Y <<endl; return 0;}

X = 10 and Y = 5

Which one of the following methodologies is a sequence of precise steps formulated in English for solving a problem? a) Pseudocode b) Flowcharts c) Logic d) Terminations

a) Pseudocode

In the flowchart, the symbol ( → ) a) denotes the direction of flow in the program. b)denotes the beginning and end of the program. c) denotes either an input operation and or an output operation program. d) is an operator.

a) denotes the direction of flow in the program.

The number 7.48 must be stored in: a) double b) string c) long jnt d) int

a) double

Which looping process is best used when the number of iterations is known? a) for b) while c) do-while d) all looping processes require that the iterations be known.

a) for

Example of a Logical Operator: a) == b) && c) >= d) !=

b) &&

What is the error in the following code snippet, which is used for calculating the average score for a student in three subjects? #include <iostream> int main(){ int subject1 = 75;int subject2 = 65; int subject3 = 70; int average = subject1 + subject2 + subject3 / 3 cout << "The average is " << average; return 0; } a)There is no error; the code snippet is completely accurate. b) The code snippet has a logic error. c) The code snippet uses variable names that are not allowed in C++. d) The code snippet has a syntax error from an incorrect use of arithmetic operators.

b) The code snippet has a logic error.

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block? a) parentheses ( ) b) braces { } c) brackets [ ] d) arrows < >

b) braces { }

The file which must appear in a #include preprocessor statement if you are using the sin function is ... a) string b) cmath c) iostream d) iomanip

b) cmath

Which of the following is not a syntactically correct declaration? a) double tax_percent = 0.06; b) double value1 = 4.5; value2 = 3.7; c) int number = 12; d) int x,y,z;

b) double value1 = 4.5; value2 = 3.7;

In a group of nested loops, which loop is executed the most number of times? a) the outermost loop b) the innermost loop c) all loops are executed the same number of times d) cannot be determined without knowing the size of the loops

b) the innermost loop

Which of the following operators is the increment operator a) % b) + c) ++ d) +-

c) ++

Consider the following section of code: if ( base < height ) cout << "Heavy structure" << endl; else cout << "Stable structure" << endl; Which of the following possible values for base and height cause the message "Stable structure" to be printed? a)base = 3, height = 5 b) base = 3, height = 8 c) base = 8, height = 8 d) base = 2, height = 7

c) base = 8, height = 8

What's wrong with the following for statement? for (int k = 2, k <=12, k++) a) the increment should always be ++k b) the variable must always be the letter i when using a for loop c) the commas should be semicolons d) the commas should be colons

c) the commas should be semicolons

Which one of the following code snippets compiles without errors and displays the output "hello" on the screen? a) #include using namespace std; int main(); { cout << hello << endl; return 0; } b) #include using namespace std; int main(); { cout << 'hello' << endl; return 0; } c) #include using namespace std; int main() { cout << "hello" << "endl"; return 0; } d) #include using namespace std; int main() { cout << "hello" << endl; return 0; }

d) #include using namespace std; int main() { cout << "hello" << endl; return 0; }

Which is the wrong variable name? a) side_1 b) side1 c) x1234 d) 1side

d) 1side

Which one of the following statements is true? a)The period terminates statements in C++ b) The colon terminates statements in C++ c) The comma terminates statements in C++ d) The semicolon terminates statements in C++

d) The semicolon terminates statements in C++

Which looping process checks the test condition at the end of the loop? a) for b) if else c) while d) do-while

d) do-while

A continue statement causes execution to skip to a) the return 0; b) the end of the loop. c) the statement following the continue statement d) the next iteration of the loop (beginning of the loop).

d) the next iteration of the loop (beginning of the loop).

You must use a semicolon (;) after...

every C++ statement

A block of code in C++ is defined by a set of bracket [.... ]

false

Constants store specific values that can be modified

false

Evaluate the following condition. Is it true or false? (3.0 >= 2.0) && (3.0 >= 4.0)

false

Identifier (variable name) must begin with a number

false

The break statement is used to terminate the execution of a if-else statement

false


Kaugnay na mga set ng pag-aaral

Geology: Quiz Questions & Answers (Test 3)

View Set

Final Exam Review (Language and Literacy)

View Set

Marketing-Information Management (IM) Pre-test

View Set

Consumer Behavior chapter 8 HW questions

View Set

OCR Level 1/2 GCSE (9-1) in Latin - Defined Vocabulary List page 2

View Set