CIS 13 - Computer Information System » Spring 2020 » Test 1

Need help with your exam preparation?

Question #1
What is the output of the following code segment? int N1 = 10 , N2 = 11 ; if ( N1 <= N2) cout << " *** " << endl ; cout << " **" << endl; N1 = N1 + 1 ; if (N1 == N2 ) cout << "***" << endl; else cout << " * " << endl << ++N1;
A.   None of the given answers is correct *** ** ***
B.   ** * 11
C.   *** ** *** * 11
D.   ** ***
Question #2
What is the output of the following code segment? int x=1, y=2, z=0 ; z = z + x / y ; y = y + 1 ; z = z * (x + y - x ); x = x + 1 ; cout << x << " , " << y << " , " << z ;
A.   None of the given answers is correct
B.   4 , 2 , 2
C.   4 , 2 , 3
D.   2 , 3, 0
Question #3
What is the output of the following C++ code? int x = 5 , y = 2; switch (x / y ){ case 0: y = y - 1 ; break ; case 1: x = x * y; y = y +1; case 2: y = y + x ; y = y - 1 ; case 3: y = y + ( x % y + 2) ; x = x + 1 ; break ; case 4: y = y + x / 4 ; break ; default: y = y - 3; break ; } cout << y <<", " << x << endl;
A.   11, 6
B.   None of the given answers is correct
C.   14 , 6
D.   13, 6
E.   7 , 5
Question #4
In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Write a C++ statement to calculate the forth harmonic number. Which option will correctly perform the calculation correctly?
A.   float harmonic = 1 + 1/ 2.0 + 1/ 3.0 + 1/ 4.0 ;
B.   float harmonic = 1.0 + 1/ 2 + 1/ 3 + 1/ 4 ;
C.   None of the given answers is correct
D.   int  harmonic = 1 + 1/ 2.0 + 1/ 3.0 + 1/ 4.0 ;
Question #5
If num is a 3-digit positive integer, such as 100, 989, or 523, which of the will the following code segment verifies that num is a 3-digit positive integer? Leading 0s (001 is 1) are not acctepted. Mark all the correct answers.,,
A.   if (!(num <100 || num >=1000))
B.   if ( num >100 && num <1000)
C.   if( num >= 100) && (num <1000)
D.   if ( num >=100 && num <1000)
Question #6
Given numPeople = 10, numCars = 2, userKey = 'q'. What is the value of flag? ( true or false) bool flag ; flag =(numPeople >= 20 || numCars > 1) && userKey =='q' ;
A.   FALSE
B.   TRUE
Question #7
Assume that: char ch; bool flag ; cin >> ch ; Which of the following C++ code segment assigns true to flag if Ch contains a letter of alphabet (a-z or A-Z)otherwise assign false to flag.,,
A.   flag = (ch >='a' || ch <='z') && (ch >='A' || ch <='Z');
B.   flag = (ch >='a' || ch <='z') || (ch >='A' || ch <='Z');
C.   flag = (ch >='a' && ch <='z') || (ch >='A' && ch <='Z');
D.   flag = ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z';
E.   flag = (ch >='a' && ch <='z') && (ch >='A' && ch <='Z');
Question #8
Write a valid C++ expression for the following algebraic expression. A = ( | x + y 5 | ) 10 Which selection will perform the task correctly in C++.
A.   A = pow(sqrt(fabs(x + pow(y,5))))
B.   A= sqrt(fabs(x, y**5))**10
C.   A = sqrt(fabs(x, y^5)) ^ 10
D.   None of the given answers is correct
Question #9
Which of the following if statement compares the value of the int variable month, and based on the value of month assign an appropriate sport to variable sport of type string. Use the following table for the values. The print the month and sport to the monitor: “Mountain Climbing” for month range from 1 to 3 inclusive, “Swimming” for month range from 4 to 6 inclusive, “Football” for month range from 7 to 9 inclusive, ,,
A.   if( month > 12 ) sport =
B.   if ( month >= 10 && month <=12 ) sport =
C.   if( month > 12 ) sport =
D.   if( month > 12 ) sport =
E.   None of the given answers is correct
Question #10
Given int one; double two; bool four; which of the following assignments are valid? (i) one = 7 * 3 % 4; (ii) 2.3 + 3.5 = two; (iii) four = (2 <= 3);
A.   ii only
B.   i and ii
C.   i only
D.   i and ii and iii
E.   i and iii
F.   iii only
Question #11
What is printed if 3000 is entered as input? cout <<”Enter a positive number: “ ; cin >> num ; if(num > 5000) num = num * 1.5 ; else if (num > 2000) num = num * 1.3 ; else if (num > 1000) num = num * 1.1 ; else if (num >= 0) num = num ; else cout <<” Invalid input. Must be a positive number” << endl ; cout << num ;
A.   Invalid input.  Must be a positive number
B.   3000
C.   None of the given answers are correct
D.   3900
E.   4500
Question #12
  
A.   b < 5 ? b = 12 : d = 30;
B.   a < 5 ? b = 12 : d = 30;
C.   d = 30 ? b = 12 : a = 5;
D.   if ( a >= 5) d = 30;else b = 12;
E.   a >= 5 ? d = 30 : b = 12;
Question #13
What is the value of number after the following statements execute? int number = 10; if (number % 5 == 0) number = number + 5; if (number % 2 == 0) number = number - 2; else number = number * 3;
A.   13
B.   30
C.   15
D.   45
E.   None of these
Question #14
  
A.   cin >> ID;cin >> fullName ;
B.   None of the given choices are correct.
C.   cin >> ID ;getline(cin, fullName);
D.   getline(cin, fullName);cin >> ID ;
E.   cin >> ID ;cin.ignore(10,'\n');getline(cin, fullName);
F.   cin >> ID >> first>>last ;

Need help with your exam preparation?