COSC
Every computer C++ program must have a
Function named main
A multi line comment
- begins with /* and ends with */ - can be used to mark as many lines as desired as comments - allows everything in the selected lines to be ignored
What is the value of number after the following statements execute? int number, number = 17.9/4+3-5+-6;
-3.525
Given the following code segment, what is the output? int x=(((((7-4)+2)+18)-44)-22)+6; cout<<"x="<<x<<endl;
-37
Given the x=2, y=1, z=0, what will the following cout statement display? cout<<"answer = " <<(!x||!y && z) << endl;
0
What is assigned to the variable result given the statement below with the following assumptions: x=10, y=7, and x, result, and y are all int variables. result = x<=10;
1
What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99){ if (x < 99) cout << y << endl; else cout << z << endl; } else{ if (x == 99) cout << x << endl; else cout << w << endl; }
1
what is the value of result after the following code executes? int result = 6-3+7%2;
1
What will be displayed after the following statements execute? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl;
1 1
in the following statement, what will be executed first according to the order of precedence? int result = 6-3-2+7-10/2
10/2
What is the value of number after the following statements execute? int number, number = 17%4+2*5
11
what is the value of donuts after the following statement executes? int donuts = 10 if (donuts!=10) donuts=2; else donuts +=2;
12
In the following statement, what will be executed first according to the order of precedence? int result = (8-3)*2.1+7-12/2;
8-3
A relational expression is either ___________ or ______________
True or False
Write if statements that allows you to properly check the char variable code to determine whether it is equal to a C and then output This is a check?
if (code=='C') Cout <<"This is a check?";
What is true about the following statement? int num4 = 10; cout << setw(2) << num4 << " ";
it allows two spaces before the value in num4
Briefly describe how the && operator works
it takes two expression as operands and creates a single expression that is true ONLY WHEN BOTH subexpressions are true
Briefly describe how the || operator works
it takes two expressions as operands and creates a single expression that is true when EITHER of the subexpressions are true.
A(n) __________ is a set of instructions that the computer follows to perform a task.
program
Character constants in C++ are always enclosed in
single quotations marks (' ')
After the following code executes, what is the value of my_value if the user enters 0? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else if (my_value > 2) my_value = my_value + 10; else my_value = my_value + 15;
15
Which of the following is not a valid C++ identifier? April2018 employee_number _1user 1user
1user
Given: x = 5, y = 6 , z = 8. Which of the following is false? 1. x==5 2. z<=4; 3. x<(y+2); 4. y>(z-x)
2
Given the following code segment, what is the output? intx=0, y=1, z=1; y=y+z; x=x+y; cout <<"result="<<(x<y?y:x)<<endl;
2 or 3
What will the following code display? int x = 23, y = 34, z = 45; cout << x << " " << y << " " << z << endl;
23 34 45
what is the value of result after the following code executes? int result = 3*5%4+24+2;
29
What is the value of number after the following statements execute? int number, number = 17%4+2*4; number = 17.9/4;
4
which of the following is evaluated first, given the expression A && B || C && D
A && B
Find the Error if (x==1): y=2; else if (x==2); y=3; else if (x==3); y=4;
Each if clause is prematurely terminated by a semicolon
Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed.\n"; 10 else 11 cout << "failed.\n"; 12 return 0; 13 }
Line 6
The two methods used by C++ to write computer programs are:
Procedural programing and object-oriented programming
In purpose of translating a source file into an executable file, which of the following is the correct sequence?
Source code, processor, modified source code, compiler, object code, linker, executable code.
Given the if/else statement: if (a<5) x=10; else y=30; write a Conditional operator to perform the same operation?
a<5?x=10:y=30;
Using C++ What data type does the computer determine for the variable cost in the following statement auto cost = 'H',
char
Write a C++ statement that will allow the user to input the values 15 and 20 and have them stored in variables named base and height, respectively?
cin>>base>>height;
Using C++11: how you declare a double variable named dozen with the value of 12.1?
double dozen = 12.1; double dozen = (12.1); double dozen; dozen=12.1;
Convert the following if-else- if statement into a switch statement if (choice == 1) { cout << "You selected 1."; } else if (choice == 2 || choice == 3) { cout << "You selected 2 or 3."; } else if (choice == 4) { cout << "You selected 4."; } else { cout << "Select again please.\n"; }
switch (choice){ case 1: cout << "You selected 1.\n"; break; case 2: case 3: cout << "you selected 2 or 3.\n"; break; case 4: cout << "You selected 4.\n"; break; default: cout << "Selected again please.\n"; break; }
When the final value of an expression is assigned to a variable, it will be converted to
the data type of the variable
A variable definition tells the computer
the variable name and the type of data it will hold
Write C++ statement that will determine whether x is grater than or equal to y?
x>=y