## The questions of Final Test

### with two model answers - one correct (yes) and one incorrect (no)

Mark the syntax correct/incorrect definition statements.
(yes) int dimes = 3;
(no) pennies = 1;

Mark the arithmetic expressions which have double type of the result. Assume that the following definitions are given:
const int n = 66;
double zen = 6.6;
(yes) zen - n/3
(no) n%3 + 12

We have the following variable definitions:
int ten = 10;
int nine = 9;
int eight = 8;
Calculate the expression and write the result.
(true) ten / nine <= 1
(false) ten / nine / 2 > 0

Mark the correct/incorrect statements about the class Employee (as it is defined in our textbook) and an object merry of this class.
(yes) merry.set_salary(2012);
(no) Employee maya = set_salary(2012.10);

We have the following variable definitions:
string num = "2013";
const string ABC = "abc";
Mark the syntax correct/incorrect statements.
(yes) cout << num.substr(0,2);
(no) cout << length(ABC);

Is the following relation true? For strings use ASCII table.
(yes)"Harry" < "Hurry"
(no) 8 < -5

We have the following function declaration:
int verb(double& x, const double y);
Mark the correct/incorrect statements. We suppose that a double variable mode is defined and initialized with 0.0.
(yes) cout << verb(mode, 2.5);
(no) cout << verb(0, 2.5);

We have the following function definition:
int h(int n, int m)
{
if (n > 10 && m < 10) return n / m;

return n * m;
}
Does the statement prints out a number > 10?
(yes) cout << h(2, 20);
(no) cout << h(12, 2);

We have a class
class Test {
public:
Test();
Test(string n, int l);
string get_name() const;
void print() const;
private:
string name;
int len;
};
and a global object t of this class. Mark the correct/incorrect statements from the body of
main function.
(yes) Test test;
(no) Test tt();

Mark with "yes" infinite loops and with "no" finite loops. The value of the integer variable far is obtained from the input stream.
(yes) do far++; while (far != 0 || far == 0);
(no) do far--; while(far > -3200);

Mark with "yes" the statements in which the loop body executes exactly once. The integer variable beep has value 1.
(yes) while(beep == 1) beep++;
(no) while(false) beep--;

Mark the syntax correct/incorrect loop statements. Variables t, y, h and k have int type.
(yes) for(t = -1; t < 4; t++) cout << t;
(no) for{y = 1; y < 10; y++} cout << h;

Mark with "yes" the equivalent logical expressions (1) and (2).
(yes) (1) country == "USA" and state != "AK" (2) not (country != "USA" or state == "AK")
(no) (1) country == "USA" and state != "HI" (2) not (country != "USA" and state == "HI")
We have:
double a, x;
bool flag1, flag2;
Does C++ run-time system compute the following logical expressions using lazy evaluations?
(yes) cin.fail()||(a < 0)
(no) !(x >= 0)

Mark the correct/incorrect assertions about vectors.
(yes) A vector is a collection of data items of the same type.
(no) The statement vector<int> b; defines a vector of two elements.

We have a vector and values of its elements:
vector<int> sol(2);
sol = 1;
sol = 3;
Mark correct/incorrect statements.
(yes) cout << sol.size();
(no) cin >> sol.size();

We have the following main function:
int main()
{  int count = 0;
string word;
while (cin >> word) count++;
cout << count << " words.\n";
return 0;
}

Is the assertion true?
(yes) count is a variable name.
(no) int count = 0; is assignment statement.