0% found this document useful (0 votes)
32 views12 pages

CS101 SecondExam Form1

The document appears to be a practice exam for an Introduction to Programming course. It contains 25 multiple choice questions related to C++ programming concepts like conditionals, loops, arrays, and more.

Uploaded by

klpxsnest1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views12 pages

CS101 SecondExam Form1

The document appears to be a practice exam for an Introduction to Programming course. It contains 25 multiple choice questions related to C++ programming concepts like conditionals, loops, arrays, and more.

Uploaded by

klpxsnest1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Jordan University of Science and Technology

Department of Computer Science


First Semester 2023-2024
HSS101CS - INTRODUCTION TO PROGRAMMING
Second Exam - Form ( 1 )

1. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int x = 2, y = 5, z = 1;
if( x < y )
z = y - x;
else;
z = x * y;
cout<<z;
return 0;
}
(Total Points: 1)
a. 10
b. 3
c. -3
d. 1
e. syntax error

2. What is the output of the following C++ code?


#include<iostream>
using namespace std;
int main( )
{
if( 120 % 5 == 2 )
cout<<"true"<<" ";
else
cout<<"false"<<" ";
cout<<"true"<<" ";
return 0;
}
(Total Points: 1)
a. 1 0
b. 0 1
c. true true
d. false true

3. What is the output of the following code?


#include<iostream>
using namespace std;
int main( )
{
int age = 40;
if ( age > 30 )
if ( age > 55 )
cout<<"Turning age";
else
cout<<"Middle age";
else
cout<<"Young age";
return 0;
}
(Total Points: 1)
a. Young age
b. Middle age
c. Turning age
d. Turning ageYoung age

4. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int a = 5, b = 10, c = 12;
if( a < b )
if( a < c )
a += 2;
else
a += 1;
else
if( b < c )
{
if( b > 0 )
b++;
}
else
b += 2;
cout<<a<<" "<<b<<" "<<c;
return 0;
}
(Total Points: 1)
a. 7 10 12
b. 5 10 12
c. 6 10 12
d. 7 11 12
e. 7 12 12

5. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int x = 2, y = 5, z;
char a = 'y';
z = ( x <= y && a == 'y' ) ? ++x : --y;
cout<<x<<" "<<y<<" "<<z;
return 0;
}
(Total Points: 1)
a. 3 5 3
b. 3 4 3
c. 3 4 2
d. 2 4 4
e. 2 5 4

6. What is the output of the following C++ code?


#include<iostream>
using namespace std;
int main( )
{
int x = 10 ;
int y = 5 ;
switch( x == 2 && y == 5 )
{
case 0 : cout<<"A" ;
case 1 : cout<<"B" ;
default: cout<<"C" ;
// cout<<"D" ;
}
return 0 ;
}
(Total Points: 1)
a. ABC
b. A
c. BC
d. C
e. BCD

7. What will the value of "a" be after the following C++ code executes?
#include<iostream>
using namespace std;
int main( )
{
int a = 7, b = 5;
switch( a % b )
{
case 1: a = a-b;
case 2: a = a+b;
case 3: a = a*b;
case 4: a = a/b;
default: a = a;
}
return 0;
}
(Total Points: 1)
a. 7
b. 5
c. 9
d. 12

8. What is the output of the following C++ code?


#include<iostream>
using namespace std;
int main( )
{
int x ;
x = -10 ;
switch( x )
{
case true : cout<< x ; break;
case false : cout<< -x ; break;
}
cout<<x;
return 0 ;
}
(Total Points: 1)
a. -10
b. 10
c. -1010
d. Nothing will be printed

9. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int n = 63;
int i;
int s = 0;
while( n != 0 )
{
i = n % 10;
n = n / 10;
cout<< i <<" ";
s = s + i;
}
cout<< s <<endl;
return 0;
}
(Total Points: 1)
a. 3 6 9
b. 3 6
c. 3 11
d. 3
e. infinite loop

10. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int x = 9;
while ( x > 1 )
x--;
cout<<x;
return 0;
}
(Total Points: 1)
a. 1
b. -1
c. 9876543210
d. 987654321

11. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int x=7;
while (--x >3)
cout<<x;
return 0;
}
(Total Points: 1)
a. 6543
b. 76543
c. 654
d. 7654

12. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int i = 0;
while ( i < 5 )
{
int k = (i < 3);
if ( k )
cout<< i << ", ";
i++;
}
cout<<"Done";
return 0;
}
(Total Points: 1)
a. 1, 2, Done
b. 0, 1, 2, Done
c. 0, 1, 2, 3, 4, Done
d. 3, Done
e. Done

13. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int x, t = 0;
x = 2;
do
{
cout<< x <<" ";
if( x % 5 == 0 )
t = t + x;
x = x * 2;
} while( x++ <= 22 );
return 0;
}
(Total Points: 1)
a. 2 5 11 23
b. 2 5 11 9
c. 2 5 8 11 14
d. 2 4 8 16 340
e. Infinite loop

14. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int x = 1;
do{
cout << x;
x += 2;
} while (x <= 9);
return 0;
}
(Total Points: 1)
a. 02468
b. 13579
c. 123456789
d. 012345678
e. 0246810

15. What is the output of the following C++ code?


#include<iostream>
using namespace std;
int main( )
{
int x = 1;
for ( ; ; )
{
if (x % 4 == 0) break;
cout << x++;
}
return 0;
}
(Total Points: 1)
a. 123
b. 234
c. 23
d. 1234
e. Infinite loop

16. What is the output of the following C++ code?


#include<iostream>
using namespace std;
int main( )
{
for (int i = 1; i < 10; i += i % 4)
cout << i++;
return 0;
}
(Total Points: 1)
a. 146
b. 257
c. 14610
d. Infinite loop
e. Syntax Error

17. What is the output of the following C++ code?


#include<iostream>
using namespace std;
int main( )
{
for (int i = 5; i <= 6; i -= 1)
cout << i;
return 0;
}
(Total Points: 1)
a. Infinite loop
b. Syntax Error
c. 56
d. 543210
e. 65

18. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
for (int var = 0; var < 5; var++)
{
if ( var % 2 == 0 )
{
cout << var << " ";
continue;
}
if ( var == 3 )
break;
}
return 0;
}
(Total Points: 1)
a. 0 1 2 3 4
b. 0 1 2
c. 0 2
d. 0 2 4

19. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
for (int i = 1; i <= 3; i++)
{
if ( i * 2 == 2 )
{
cout << i * 2 << " ";
continue;
}
cout << i << " ";
}
return 0;
}
(Total Points: 1)
a. 2 2 3 4
b. 2 2 3
c. 2 2 3 4 5
d. 1 2 3

20. What is the output of the following C++ code?


#include<iostream>
using namespace std;
int main( )
{
for(int i = 1; i <= 2; ++i)
for(int j = 1; j <= 2; j *= 2)
if( i - j)
cout << i << "," << j << " ";
return 0;
}
(Total Points: 1)
a. 1,1 1,2
b. 1,2 2,2
c. 1,1 2,2
d. 1,2 2,1

21. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int a[ 3 ] = {1, 2, 3, 4};
for(int i = 0; i < 3; i++)
cout<<a[ i ];
return 0;
}
(Total Points: 1)
a. 1234
b. 123
c. Syntax Error
d. 12
e. 1

22. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
int a[ 5 ] = {1, 2};
a[ 1 ] = 3;
a[ 2 ] = 5;
for(int i = 0; i < 5; i++)
cout<<a[ i ]<<" ";
return 0;
}
(Total Points: 1)
a. 1 2 5 0 0
b. 1 3 5 0 0
c. 1 0 5 0 0
d. 1 2 5
e. 1 3 5

23. Which of the following assigns the value 5 to the fourth element in
(myArray)? (Total Points: 1)
a. myArray[ 3 ] = 5;
b. myArray[ 5 ] = 4;
c. myArray[ 0 ] = {4};
d. myArray[ 5 ] = {3};

24. Which of the following is not a correct array declaration? (Total Points: 1)
a. char a[ 1 ] = 'B';
b. bool a[ 5 ];
c. double a[ 3 ] = {12.5, 1.6};
d. int a[ ] = {'A', 20};

25. What is the output of the following C++ code?


#include <iostream>
using namespace std;
int main( )
{
bool A[ 3 ] = {true, false, true};
int c = 0;
for(int j = 0; j < 3 ; j++)
if( A[ j ] == true)
c++;
if( !c )
cout<<"zero";
else
cout<<"No Zero";
return 0;
}
(Total Points: 1)
a. No Zero.
b. zero.
c. Nothing will be printed.
d. SYntax error.

You might also like