Pretest (Finals)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Name: Marc Jhon A.

Benzal Course: ES 132


Program and Year: BSCE 2A Instructor: Ma’am Anne Say Morite

LEARNING MODULE NO. 6 – PRETEST

Instructions: For each question, encircle the letter of the correct best answer.
1. What will be the output of the following C++ code?
#include <iostream>

using namespace std;

int main () {

int n ;

for (n = 5; n < 0; n--)

cout << n;

if (n == 3)

break;

return 0;

a) 543
b) 54
c) 5432
d) 53

2. What will be the output of the following C++ code?


#include <iostream>

using namespace std;

int main () {

int a = 10;

if (a = 15)
{ time;

cout << a;

if (n == 3)

goto time;

} break;

return 0;

a) 1010
b) 10
c) infinitely print 10
d) compile time error

3. What will be the output of the following C++ code?


#include <iostream>
using namespace std;

Republic of the Philippines

SURIGAO DEL NORTE STATE UNIVERSITY

Narciso Street, Surigao City 8400, Philippines

“For Nation’s Greater Heights”

Tel. Nos.: (086) 827-3741 Email: [email protected]

URL: snsu.edu.ph

int main () {

int n = 15;

for (; ;)

cout << n;

return 0;

a) error
b) 15
c) infinite times of printing n
d) none of the mentioned

4. What will be the output of the following C++ code?


#include <iostream>

using namespace std;

int main () {

int i;

for (i = 0; i < 10; i++);

cout << i;

return 0;

a) 0123456789
b) 10
c) 012345678910
d) compile time error

5. How many types of loops are there in C++?


a) 4
b) 2
c) 3
d) 1

6. Which looping process is best used when the number of iterations is known?
a) While loop
b) For loop
c) Do while loop
d) all looping processes require that the iterations be known
7. Which of the following must be present in the switch construct?
a) Expression in ( ) after switch
b) default
c) case followed by value
d) All of the above

8. What is the effect of writing a break statement inside a loop?


a) It cancels remaining iterations.
b) It skips a particular iteration.
c) The program terminates immediately.
d) Loop counter is reset.

9. The break statement causes an exit


a) from the innermost loop only.
b) only from the innermost switch.
c) from all loops & switches.
d) from the innermost loop or switch.

10. Choose a correct C++ for loop syntax.


a) for(initalization; condition; inc/dec){ //statements };
b) for(declaration; condition; incrementoperation){ // statements };
c) for(declaration; increment operation;condition){ // statements };
d) for(initialization; condition;increment operation){ // statements };

11. Choose a correct C++ do while syntax.


a) do while(condition){ // statements };
b) do while(condition){ // statements };
c) do{ // statements }while(condition)
d) do{ // statements }while(condition);

12. Choose a correct C++ Statement.


a) a++ is (a= a+1) POST INCREMENT operator
b) a-- is (a = a-1) POST DECREMENT operator. -
-a is (a = a-1) PRE DECREMENT operator
c) ++a is (a = a+1) PRE INCREMENT operator
d) All of the above.

13. Which of the following is an entry-controlled loop?


a) For loop
b) while loop
c) do-while loop
d) both b & c

14. Which of the following is an exit-controlled loop?


a) While loop
b) For loop
c) Do while loop
d) both b & c

15. Which of the following is most suitable for a menu-driven program?


a) For
b) while
c) do-while
d) All of the above
16. Consider the following loop: for(int i = 0; i<5; i++);
a) It will give a compilation error.
b) 5
c) 6
d) Some Garbage value

17. A switch construct can be used with which of the following types of variable?
a) int
b) int, char
c) int, float, char
d) Any basic datatype

18. A for loop is also known as a _____ loop.


a) decrementing
b) incrementing
c) counting
d) recursive

19. If you wanted to start from 100 and loop to 3 in C++, what syntax should be
used?
a) for(int i = 0; i < 100; i+3) {}
b) for(int i = 3; i > 100; i--) {}
c) for(int i = 100; i < 3; i++) {}

20. Examine the following C++ code. What is most likely to happen with this loop?
int i = 1;

while(i < 100) {

if(i > 50 && i % 25 == 0) {


continue;

i++;

a) The code will run 100 times


b) An infinite loop will occur
c) i will get updated to 0
d)The continue statement will restart the loop
Name: Marc Jhon A. Benzal Course: ES 132
Program and Year: BSCE 2A Instructor: Ma’am Anne Say Morite

LEARNING MODULE NO. 7 – PRETEST

Instructions: For each question, encircle the letter of the correct best answer.

1. Array is a collection of ________.

A. similar type of elements

B. different type of element

C. heterogeneous data

D. Both A and C

2. Array data access using _____.

A. Operator

B. Variable

C. index

D. Pointer

3. At time of array initialization which is necessary to specify?

A. Row

B. Column

C. Row and Column

D. None of the above


4. Array can allocate __________.

A. Dynamic Memory

B. Static Memory

C. Both A and B

D. None of the above

5. Which of the following is an incorrect array declaration?

A. int []. arr = new int[5].

B. int arr[]== = new int[5].

C. int arr[]+ = new int[5].

D. int arr[4];

6. Index in array start with ______.

A. -1

B. 0

C. 1

D. infinite

7. Which of the following is used to declare, construct, and initialize an array?

A. int arr [] [] = {1, 2, 3, 4};

B. int [] arr = (1, 2, 3);

C. int [] arr = {};

D. int arr [] = {1, 2, 3};


8. We can calculate the length of an array using ________.

A. sizeof(array)

B. array.len

C. array.length

D. array.sizeof()

9. Which of the following is advantage of C++ array?

A. Code Optimization

B. Random access

C. Size No-Limit

D. Both A and B

10. In C++, array elements are stored in ________ memory locations.

A. Random

B. Sequential

C. Sequential & Random

D. Binary search

11.What is wrong with the following code fragment?

const int SIZE =5; float scores[SIZE]; for(int i=0; i<=SIZE;i++) { cout << "Enter a score\n"; cin >>

scores[i]; }

A. Array indexes start at 1 not 0

B. Arrays must be integers

C. Array indexes must be less than the size of the array


D. Should be cin >> scores[0];

12. What is the output of the following code fragment? int array[4][4], index1, index2;
for(index1=0;index1<4;index1++) for(index2=0;index2<4;index2++) array[index1][index2]=index1 +
index2; for(index1=0;index1<4;index1++) { for(index2=0;index2<4;index2++) cout <<
array[index1][index2] << " "; cout << endl; }

A. 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6

B. 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3

C. 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3

D. 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9

13. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main() {
for (temp = 0; temp < 5; temp++){
result += array1[temp];
}
for (temp = 0; temp < 4; temp++){
result += array2[temp];
}
cout << result;
return 0;
}

a) 6553

b) 6533

c) 6522

d) 12200
14. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++){
result += array[n];
}
cout << result;
return 0;
}

a) 25

b) 26

c) 27

15. What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {
char str[5] = "ABC";
cout << str [3];
cout << str;

return 0;
}

a) ABC

b) ABCD

c) AB

d) AC
Name: Marc Jhon A. Benzal Course: ES 132
Program and Year: BSCE 2A Instructor: Ma’am Anne Say Morite

LEARNING MODULE NO. 8 – PRETEST

Instructions: For each question, encircle the letter of the correct best answer.
1. Which of the following function / types of function cannot have default parameters?
A. Member function of class
B. Main()
C. Member function of structure
D. Both B and C

2. Correct way to declare pure virtual function in a C++ class is


A. Virtual void foo() =0 ;
B. Void virtual foo()= { 0 }
C. Virtual void foo() {} = 0;
D. None of the above

3. What is the scope of the variable declared in the user defined function?
A. Whole program
B. Only inside the {} block
C. The main function
D. None of the above

4. Which of the following in Object Oriented Programming is supported by Function overloading and
default arguments features of C++.
A. Inheritance
B. Polymorphism
C. Encapsulation
D. None of these

5. Predict the output:


float x= 3.1496;
cout << setprecision(2) << x;

A. 3.14
B. 3.15
C. 3
D. 3.1
6. Which of the following statement is correct?
A. Only one parameter of a function can be a default parameter.
B. Minimum one parameter of a function must be a default parameter.
C. All the parameters of a function can be default parameters.
D. No parameter of a function can be default.

7. Which of the following function declaration using default arguments is incorrect?


A. int foo(int x, int y =5, int z=10)
B. int foo(int x=5, int y =10, int z)
C. int foo(int x=5, int y, int z=10)
D. All are correct

8. How are many minimum numbers of functions need to be presented in c++?


A. 0
B. 1
C. 2
D. 3

9. Inline functions may not work. i) If function contain static variables. ii) If function contain
global and register variables. iii) If function returning value consists looping construct (i.e. for, while).
iv) If inline functions are recursive. v) If function contains const value.
A. Only i,iv & v
B. Only ii,iii & v
C. Only i,iii & iv
D. All of the above

10. Unary scope resolution operator is denoted by


A. ! !
B. % %
C. :
D. : :

11. What is the output of this program?

#include <iostream>
using namespace std; void find()
void find()
{
cout<<"course";
}
int main()
{
find(); return 0;
}
A. course
B. coursecourse
C. compile time error
D. none of the mentioned

12. What is the output of this program?


Note: Include all required header files using namespace std;

void fun(int p, int q)


{
p = 20;
q = 10;
}
int main()
{
}
int p = 10; fun(p, p); cout << p; return 0;

A. 10
B. 20
C. compile time error
D. none of the mentioned

13. What is the output of this program?


Note: Include all required header files using namespace std;

void copy (int& a, int& b, int& c)


{
a *= 2;
b *= 2;
c *= 2;
}
int main ()
{
int x = 2, y = 5, z = 7; copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}

A. x =3, y =7, z =10


B. x =3, y =6, z =5
C. x =4, y =10, z =14
D. None of the above
14. What is the output of this program?
Note: Include all required header files using namespace std;

void fun(int &p)


{
p = 30;
}
int main()
{
int p = 5; fun(p);
cout << "New value of p is " << p; return 0;
}

A. New value of p is 5
B. New value of p is 30
C. New value of p is 15
D. None of the above

15. Which of the following is true about the following program Note: Include all required header
files.

using namespace std; long factorial (long p)


{
if (p > 1)
return (p * factorial (p + 1)); else
return (1);
}
int main ()
{
long q = 3;
cout << q << "! = " << factorial ( q ); return 0;
}

A. 6
B. 24
C. segmentation fault
D. compile time error

16. What will be the output of this program?


Note: Include all required header files using namespace std;
void square (int *p)
{
*p = (*p + 1) * (*p);
}
int main ( )
{
int q = 5;
square(&q); cout << q; return 0;
}
A. 25
B. compile time error
C. 36
D. 30

17. What will be the output of this program?


Note: Include all required header files using namespace std;
int max(int p, int q )
{
return ( p > q ? p : q );
}
int main()
{
int x = 25; int y = 50;
cout << max(x, y ); return 0;
}
A. 25
B. 50
C. either 25 or 50
D. none of the mentioned

18. What will be the output of the following program?


Note: Include all required header files using namespace std;
int gcd (int a, int b)
{
int temp; while (b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return(a);
}
int main ()
{ int x = 7, y = 13; cout << gcd(x, y); return(0);

A. 7
B. 13
C. 91
D. 1
19. What will be the output of the following program?

#include <iostream>
using namespace std; void lfc(int p)
{
cout << p;
}
void lfc(double q)
{
cout << q;
}
int main(void)
{
lfc(5);
lfc(555.263);
return 0;
}

A. 5555.263
B. 555.2635
C. 555.263
D. None of the mentioned

20. What will be the output of the following program?


#include <iostream>
using namespace std; int lfc (int a, int b)
{
return (a * b);
}
float lfc (float a, float b)
{
return (a / b);
}
int main()
{
int x = 5, y = 2;
float n = 5.0, m = 2.0; cout << lfc(x, y) <<" "; cout << lfc (n, m);
return 0;
}

A. 10.0 5.0
B. 5.0 2.5
C. 10.0 5
D. 10 2.5

You might also like