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.   ** ***
D.   *** ** *** * 11
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.   2 , 3, 0
C.   4 , 2 , 3
D.   4 , 2 , 2
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.   None of the given answers is correct
B.   11, 6
C.   7 , 5
D.   13, 6
E.   14 , 6
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.   None of the given answers is correct
C.   float harmonic = 1.0 + 1/ 2 + 1/ 3 + 1/ 4 ;
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.   TRUE
B.   FALSE
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 = sqrt(fabs(x, y^5)) ^ 10
B.   A= sqrt(fabs(x, y**5))**10
C.   A = pow(sqrt(fabs(x + pow(y,5))))
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.   None of the given answers is correct
E.   if( month > 12 ) sport =
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.   i and ii
B.   i and iii
C.   i and ii and iii
D.   ii only
E.   iii only
F.   i 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.   3900
B.   3000
C.   4500
D.   Invalid input.  Must be a positive number
E.   None of the given answers are correct
Question #12
  
A.   b < 5 ? b = 12 : d = 30;
B.   a >= 5 ? d = 30 : b = 12;
C.   if ( a >= 5) d = 30;else b = 12;
D.   d = 30 ? b = 12 : a = 5;
E.   a < 5 ? b = 12 : d = 30;
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.   None of these
B.   45
C.   15
D.   13
E.   30
Question #14
Which of the following C++ code segment will read the id (an integer number) and full name of an employee correctly. Assume all variables are declared correctly. Select as many as you like.,  ,  
A.   getline(cin, fullName);cin >> ID ;
B.   cin >> ID ;cin.ignore(10,'\n');getline(cin, fullName);
C.   None of the given choices are correct.
D.   cin >> ID;cin >> fullName ;
E.   cin >> ID >> first>>last ;
F.   cin >> ID ;getline(cin, fullName);

Need help with your exam preparation?