The questions of Test_3
with two model
answers - one correct (yes) and one incorrect (no)
We have a class
class Prod {
public:
Prod();
Prod(string n,
int s);
void read();
string
get_name() const;
void print()
const;
private:
string name;
int sc;
};
and a global object p
of this class. Mark the
correct/incorrect statements from the body of main function.
(yes) Prod q;
(no) Prod x();
Mark with "yes" infinite loops and with "no" finite
loops. The value of the integer variable oh is obtained from
the input stream.
(yes) do oh++; while ((oh != 0)
or (oh == 0));
(no) do oh--; while(oh >
-32000);
Mark with "yes" the statements in which the loop body
executes exactly once. The integer variable be has value
1.
(yes) while(be == 1) be++;
(no) while(false) be--;
We have the following function declaration:
int
were(double& me, double you);
Mark the correct/incorrect statements. We suppose that a double
variable is is defined
and initialized with 0.0.
(yes) cout << were(is,
2.5);
(no) cout << were(0, 2.5);
We have the following variable definitions:
int ten = 10;
int nine = 9;
int eight = 8;
Calculate the arithmetic expression and mark it "yes" if it has
value 1.
(yes) ten / nine
(no) ten / nine / 2
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(2000);
(no) Employee maya =
set_salary(2000.00);
We have the following variable definitions:
string num = "1234";
const string ABC = "abc";
Mark the syntax correct/incorrect statements.
(yes) cout <<
num.substr(0,2);
(no) cout << length(ABC);
Mark the correct/incorrect assertions about vectors.
(yes)
A vector is a collection of data items of the same type.
(no)
The statement vector b[2];
defines a vector of two elements.
We have a vector and values of its elements:
vector<int> num(2);
num[0] = 1;
num[1] = 3;
Mark correct/incorrect statements.
(yes) int k = num.size();
(no) cin >> num.size();
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)