1stexam Sol
1stexam Sol
____ the algorithm refers to the process of translating the algorithm into a language that the computer can understand. a. Assembling b. Tracing c. Translating d. Coding
2. a.
A programmer evaluates a program by ____ it on the computer. desk-checking b. running c. hand-tracing d. compiling
3. a. c.
Which of the following is true about the ALU? It is considered the brain of the computer. It caries out logical and arithmetic operations b. d. The control unit is one of its components It stores the program counter
4. a. b. c.
The function of the compiler is to check if there is no syntax error translate the program code from high level language to machine language load the executable code to main memory d. a and b
5. a. b. c. d.
To process a C++ program it should follow the following procedures Editor, Preprocessor, Linker, Compiler, Loader, Execution Editor, Preprocessor, Compiler, Linker, Loader, Execution Editor, Compiler, Preprocessor, Linker, Loader, Execution Editor, Linker, Compiler, Preprocessor, Loader, Execution
6.
The statement ____ tells the computer to get the current weekly pay from the keyboard, and store that amount in the currentPay variable.
a. c.
b. d.
7.
What is the output of the following code? void main(){ int x; // double y; x= 4; y=5; cout<<x+y<<endl; }
a.
b.
c.
9.00
d.
9.0
8. a.
9. a.
Which of the following is an illegal C++ identifier (variable)? 7_bottles b. _7_Bottles c. seven_bottles d. _Bott
10.
a.
26.3
b.
22
c.
22.3
d.
11.
What is the result of following code? int x=2, y=4; x *= (2+y)*x; cout << x;
a.
24
b.
30
c.
18
d.
27
12. a. c.
A C++ program that prints 3 lines must contain 3 cout statements. must contain 1 cout statement. b. d. must contain 2 cout statements. may contain 1 or more cout statements
13. a. c.
Which of the following is a correct C++ statement? if x==1 cout << mustafa if(x==1) cin << Just_just b. d. if(x==2) cout << 55; if(x==6) cout >> cs155;
14. a. c.
Which one of the following is a valid assignment? 7edu = edu +1 edu *= edu +7 b. d. edu +7 = edu edu =* edu +7
15. a.
16.
What is the output of the following code? const int x=5; x++; cout<<x<<endl; //line #1 //line #2 //line #3 c. Error with line #2 d. Error with line #1
a.
b.
17. a. b. c. d.
value += sum++;
sum = sum + 1;
sum = sum + 1; value = value + sum; value = value + sum; value = value + ++sum;
18.
What is the output produced by the following code fragment int i = 1, j = 2, k = 3; cout << i + static_cast<double>(5 % (j + 2)) / k << endl;
a.
b.
1.33333
c.
d.
0.33333
19. a. c.
____ is an example of a selection structure. "drop the balloon in the red box" "repeat 20 times" b. d. "repeat until you are directly in front of the chair" "if the balloon is red, do this"
20. a. c.
The following is true about the logical expression It can be true or false, depending on the value of x It is always false d.
x%10 > 9 b.
It is always true
21.
The statement that compares the value of an integer called sum against the value 65, and if it is less, prints the text string "Sorry, try again", is
a. b. c. d.
if (sum < "65") if (sum <= 65) if (65 == sum) if (sum < 65)
cout << "Sorry, try again"; cout << "Sorry, try again"; cout << "Sorry, try again"; cout << "Sorry, try again";
22.
The statement that compares total for equality to good_guess, and if equal prints the value of total, and if not equal prints the value of good_guess, is
a. b. c. d.
if (total < good_guess) cout << total; else cout << good_guess; if (total == good_guess) cout << good_guess; else cout << total; if (total = good_guess) cout << total); else cout << good_guess; if (total == good_guess) cout << total; else cout << good_guess;
23.
Consider the following C++ code. How much is added to premiumDue if driverAge is 22 and numTickets is 0? if(driverAge < 26) if(driverAge > 50) if(numTickets == 2) premiumDue += 100; premiumDue -= 50; premiumDue += 60.25; c. 60.25 d. 100
a.
-50
b.
10.25
24.
a. c.
b. d.
25.
What is the output of the following code int x=5, y=7; if(x < y++ || y++ <=10) cout<<x<<" else "<<y<<endl;
a.
5 9
26. a. c.
The expression if (num != 65) cannot be replaced by if (num > 65 || num < 65) if (num 65) b. d. if ( !(num == 65)) if ( !(num 65))
27.
What is the output of the following? int a = 5, b = 0; if (a) cout<< 7; cout<< 6; if (b){ cout<< 3; cout<< 5; }
a.
76
b.
35
c.
635
d.
7635
28.
What is the output of the following code? if(5) cout<<"OK"; else cout<<Cancel;
a.
OK
b.
Cancel
c.
OK Cancel
d.
Nothing
29.
Consider the following pseudo code. If the sales amount is 15000, the value of the bonus amount at the end of the algorithm will be ____. 1. enter sales amount 2. calculate the bonus amount by multiplying the sales amount by .08 3. if (the sales are greater than or equal to 10000) else 4. display the bonus amount add 150 to the bonus amount add 125 to the bonus amount
a.
720
b.
845
c.
1200
d.
1350
30.
Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative, or zero. #include <iostream> using namespace std; void main(){ int number; cout << " Enter a number<<endl; cin >> number; cout << "The number "<< number; if ( number > 0 ) cout << " is positive" << endl; if ( number < 0 ) cout << " is negative" << endl; if ( number == 0 ) cout << " is zero" << endl; }
31.
Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is even, odd, or zero. #include <iostream> using namespace std; void main(){ int number; cout << " Enter a number<<endl; cin >> number; cout << "The number "<< number; if ( number % 2 == 0 ) cout << " is Even" << endl; if ( number % 2 != if ( number == 0 ) } 0 ) cout << " is Odd" << endl; cout << " is zero" << endl;
32.
Find the errors in the following program? Re-write the code making it free from syntax errors.
Line1:
include <iostream>
// missing #
// missing using namespace std; Line2: { Line3: Line4: Line5: Line6: Line7: } int x; cout << "Enter a value for x" << endl; cin > x; x = 5 - 3 return 0; // missing > // missing ; int main( // missing );
33.
Find the errors in the following program? Re-write the code making it free from syntax errors. Line1: #include <iostream> Line2: using namespace std; Line3: int mian() { Line4: Line5: Line6: Line7: Line8: Line9: Line10: } const char ch = 'A'; int x; x = ch; y = x++ ch = 'B'; // missing ; // assign to a constant identifier // change mian to main // remove const or
cout << "x: " << x << "\ty: " << y << "\tch: " << ch; return 0;