Final Part One
Final Part One
True False:
In C++ you can assign an expression of type double to a variable of type int with no problem.
Answer: TRue
Explanation:
Answer:NO
Explanation:
if
n=1
n=(n++) + (n++) will print 3 after second line is executed as first n++ will be executed after +
operator, and second n++ operator will be executed after the statement is executed.
n=1+2=3
int x = 0;
The following expression causes a divide by zero error:
Answer:
Explanation:
In a do-while loop, a continue statement terminates the loop.
Answer: False
Explanation: The boolean expression is executed before entering the body of the loop
Answer: True
Explanation:
When using an array, it is perfectly legal to access indexed variables with index values less
than 0 or greater than or equal to the declared size of the array.
Answer:
Explanation:
Consider these hierarchical structures.
struct Date
{
int year;
//members
};
struct Person
{
Date birthDay;
//other members
};
Person Bill;
#include <iostream>
struct Date{
};
struct Person{
string name;
Date date;
};
return false;
return true;
return false;
return true;
return false;
int main()
cin>>p1.name>>p1.date.month>>p1.date.day>>p1.date.year;
cin>>p2.name>>p2.date.month>>p2.date.day>>p2.date.year;
if(checkLeapYear(p1.date.year)){
else{
cout<<" a not leap year."<<endl;
if(checkLeapYear(p2.date.year)){
else{
return 0;
Explanation:
The declaration below declares three pointer variables of type pointer to double that is, a
pointer of type (double*)
Explanation: In above code p1 is a pointer where as p2 and p3 are data type double
variable.
Multiple Choice
int j = n;
double sum = 0;
while( j >= 0)
sum += d;
-j;
return sum;
a) returns 7*2
b) returns 7+2
c) returns 7!
d) There is a syntax error in the program so it won’t run.
e) It compiles but computes none of these.
Answer:
Given the function, and the main function calling it: What is the output of the following code if you
omit the ampersand (&) from the first parameter, but not from the second parameter? (You are to
assume this code is embedded in a correct function that calls it.):
#include <iostream>
int t = x;
x = y;
y = t;
int main()
int u = 3; v = 4;
// ...
func ( u, v )
// ...
a) 3 4
33
b) 3 4
43
c) 3 4
34
d) 3 4
44
e) none of the above. If you choose this, you must specify the output.
Answer: B
Answer: A is incorrect
When you define a C++ class, which of the following should be part of the implementation?
a) all declarations of private member variables
b) all declarations for public member functions
c) all explanatory comments for public member declarations.
d) all declarations for private member functions (auxiliary or helping functions)
e) all member function definitions, public and private (implementations of functions).
Answer:
Given the class definition,
class A
{
public:
A(){}
A(int x, char y):xx(x), yy(y) {}
// other members
private:
int xx;
char yy;
};
Tell which definition below is legal.
If legal, tell whether it is a definition of an object of class A.
If the definition is a legal and defines a class A object, tell which constructor is called for
each of the following definitions.
Identify the constructor like this: If the constructor for class A with two int arguments is
called, respond with A(int, int).
a) A x(2, ‘A’);
b) A x;
c) A x = A(2, ‘A’);
d) A x(1);
e) A x( );
Answer: A is correct
Free Form Questions:
What does the line
#include <iostream>
do for your program?
Answer:
{
if (i<5 && i !=2)
i++;
}
Answr
for(i=1;i<=10;i++)
{
If (I < 5 && i != 2)
cout <<
int x;
Answer:
Define function signature:
Answer:
Describe the action of the new operator. What does the new operator return? What are the
indications of error?
Answer: