IKM C++
Assessment
C++ PROGRAMMING
If you lose your internet connection, you will be able to resume the test at the
point at which it was interrupted. Simply close your browser window(s) using the "Alt"
and "F4" keys, reconnect your internet connection and log back on using the above URL
and password (prior to the test expiration date and time). For other helpful hints, see
our Technical Support Tips (which we encourage you to print out before you begin the
test). You must complete these assessments by 2009/01/27 21:16 EST. After this time,
the passwords will no longer work, and you will need to contact your test administrator
to get new working passwords. Good luck!
Ref: http://www.cplusplus.com/doc/
Question 4: Which of the following statements correctly describe the code below in
IKM Assessment Administration
C++?
#define language 437 //Line 1
#if language < 400
#undef language //Line 2
#else //Line 3
#define language 850 //Line 4
#ifdef language //Line 5
printf("%d", language); //Line 6
#endif
#endif
A. An error or warning will occur on Line 6 because a macro cannot be used as
part of a preprocessor directive.
B. An error or warning will occur on Line 2 because #undef is not a valid preprocessor
directive.
C. An error or warning will occur on Line 4 because language has already been defined.
D. If Line 1 is changed to #define language 300, Line 6 will print "850".
E. An error or warning will occur on Line 3 because #else can only be used as the last
conditional in the chain.
Answer: D
Question 5: Which of the following statements regarding the benefits of using template
functions over preprocessor #define macros are correct?
A. A preprocessor macro expansion cannot work when user-defined types are passed to
it as arguments.
B. Since the preprocessor does the macro expansion and not the compiler, the build process
takes a longer period of time.
C. While expanding #define macros, the preprocessor does no type checking on the
arguments to the macro.
D. A preprocessor macro expansion incurs a performance overhead at runtime.
E. It is simple to step into a template function code during the debugging process.
Answer: E
Question 6: Which of the following are container adapters in the STL (Standard Template
Library) in C++?
A. list
B. map
C. stack
D. queue
E. deque
Answer: C D
Question 7: Which of the following correctly identify benefits of the getline() member
B. Delimiters indicating end of input can be specified to the getline() function,
function for cin over the extraction operator in C++?
A. The getline() function by default, accepts whitespace, and returns on seeing the
\n character, whereas the extraction operator returns when it encounters any whitespace
character.
whereas the extraction operator has no such facility.
whereas the extraction operator cannot be overloaded.
it cannot be done with the extraction operator.
extraction operator cannot be used as a manipulator.
E. The getline() function can be used like a manipulator with cin, whereas the
C. The getline() function can be overloaded to accept different argument types,
D. The number of bytes to read can be specified to the getline() function, whereas
invoked?
Question 8: In which of the following scenarios is a Copy Constructor called or
A. When no conversion function exists for converting the class object to another
class object
Answer: B C D E
Question 9: Which of the following statements correctly describe the results of
B. When an existing object is assigned an object of its own class
C. When a function receives as an argument, an object of the class, by value
D. When a function returns an object of the class by value
E. When creating an object and initializing it with an object of its own class
executing the code below in C++?
#include
using namespace std;
class ExBase
{
private:
static int stat;
public:
static int GetStat(){ return stat; }
};
int ExBase::stat = 25;
class ExDer1 : public ExBase
{
public:
friend int Der1Fn(){ return ExBase::stat; }
};
class ExDer2 : public ExBase{};
class ExDer : public ExDer1, public ExDer2{};
{
ExDer d;
cout << d.Der1Fn() << endl;
}
will result in an ambiguity error from the compiler.
{
ExDer d;
cout << d.GetStat() << endl;
}
will display an output as
"25".
{
cout << ExDer1::GetStat() << endl;
}
will result in an ambiguity error from the compiler.
{
public:
friend int Der1Fn(){ return ExBase::stat; }
};
will result in an access error from the compiler.
{
cout << ExDer1::ExBase::GetStat() << endl;
}
will display an output as
"25".
D. class ExDer1 : public ExBase
E. int main()
use of dynamic_cast in C++?
#include
#include
A. int main()
B. int main()
C. int main()
Question 10: Given the following program snippet, what can we conclude about the
//Someone else's code, e.g. library
class IGlyph
{
public:
virtual ~IGlyph(){}
virtual std::string Text()=0;
virtual IIcon* Icon()=0;
//...
};
class IWidgetSelector
{
public:
virtual ~IWidgetSelector(){}
virtual void AddItem(IGlyph*)=0;
virtual IGlyph* Selection()=0;
};
//Your code
class MyItem : public IGlyph
{
public:
virtual std::string Text()
{
return this->text;
}
virtual IIcon* Icon()
{
return this->icon.get();
}
void Activate()
{
std::cout << "My Item Activated" << std::endl;
}
std::string text;
std::auto_ptr icon;
};
void SpiffyForm::OnDoubleClick(IWidgetSelector* ws)
{
IGlyph* gylph = ws->Selection();
MyItem* item = dynamic_cast(gylph);
if(item)
item->Activate();
A. The dynamic_cast ought to be a reinterpret_cast since the concrete type is
unknown.
}
B. The dynamic_cast is unnecessary since we know that the concrete type returned
by IWidgetSelector::Selection() must be a MyItem object.
C. The dynamic_cast is redundant, the programmer can invoke Activate directly,
e.g. ws->Selection()->Activate();
D. The dynamic_cast is necessary since we cannot know for certain what concrete
type is returned by IWidgetSelector::Selection().
E. A polymorphic_cast should be used in place of the dynamic_cast.
Question 11: Which of the following statements describe the result when standard
new cannot allocate the requested storage in C++? (Note: older compilers may not
implement standard behavior).
A. It throws a bad_alloc exception.
B. It returns null.
C. It returns silently with no effect on the expression.
D. It throws an insufficient_memory exception.
E. It logs an error message to the mem_err.log file.
Question 12: In C++, which of the following is the best declaration for an overloaded
operator[] to allow read-only access (and only read-only access) to the data?
template
class MyArray
{
//declaration goes here
};
Answer: C
A. T& operator[](size_t i);
B. const T& operator[](size_t i);
C. const T& operator[](size_t i) const;
D. T& operator[](size_t i)const;
E. T& operator[](const size_t i);
Question 13: Which of the following declarations of function main are standard or
standard conforming extensions? (Please note that some compilers accept ill-formed
main declarations, these should be considered incorrect).
Answer: C
A. int main()
B. void main(char* argv[], int argc)
C. int main(int argc, char* argv[])
D. void main()
E. int main(int argc, char* argv[], char* arge[])
Question 14: What is the correct declaration for a file stream insertion operator
for a class my_stuff::my_class as indicated in the C++ code snippet below?
#include
namespace my_stuff
{
class my_class
{
public:
int i;
};
//Declaration goes here
}//ns my_stuff
A. std::ofstream& operator<<(std::ofstream& ofs, const my_class&);
B. const my_class& operator<<(const my_class&)
C. std::fstream& operator<<(std::fstream& fs, const my_class&)
D. std::ifstream& operator<<(std::ifstream& ifs, const my_class&)
E. void operator<<(const my_class&)
Question 15: Which of the following statements describe the results of executing
the code snippet below in C++?
int var = 1;
void main()
{
int i = i;
}
resolve the declaration of i.
A. The i within main will have an undefined value.
B. The compiler will allow this statement, but the linker will not be able to
C. The i within main will have a value of 1.
D. The compiler will not allow this statement.
E. The result is compiler-dependent.
Question 16: Which of the following methods can a developer use to override the default
terminate() function in C++?
A. Write the terminate() function with two int arguments.
B. Write the terminate() function with a runtime_error argument.
C. Pass the address of the overriding function to the set_terminate() function.
D. Write the terminate() function with one int argument.
E. Write the terminate() function with a runtime_exception argument.
Question 17: Which of the following identify const-correctness failures in the C++
program below?
template
class MyArray
{
public:
MyArray();
MyArray(MyArray& copy);
MyArray& operator=(MyArray& copy);
//...
};
class MyData
{
public:
MyData(MyArray& x, MyArray& y);
//...
const MyArray& x();
const MyArray& y();
};
MyArray read_data(int*, char**);
void make_changes(MyData* edit);
int main(int argc, char* argv[])
{
const MyArray read_x = read_data(&argc, argv);
const MyArray read_y = read_data(&argc, argv);
MyData user_data(read_x, read_y);
MyData edit_buffer(user_data);
make_changes(&edit_buffer);
}
MyData(const MyArray& x, const MyArray& y);
const MyArray& operator=(const MyArray& copy);
void make_changes(const MyData* edit);
MyArray(const MyArray& copy);
const MyArray& operator=(const MyArray& copy) const;
B. MyArray& operator=(MyArray& copy); should be
C. void make_changes(MyData* edit); should be
A. MyData(MyArray& x, MyArray& y); should be
D. MyArray(MyArray& copy); should be
E. const MyArray& operator=(const MyArray& copy); should be
Question 18: In the given C++ code snippet, which of the following statements correctly
identify how Mon of enum DOW can be assigned to a variable named var?
void main()
A. The variable var will have to be of type enum DOW, and then defined as:
B. Mon of enum DOW cannot be assigned because the compiler will give a redefinition
C. Since enum DOW has been declared and defined later, it will be pushed onto
the stack later, but will be accessed first. Hence, the scope resolution operator is
not required and var will be assigned as:
D. Since Mon is of type enum DOW, var will be assigned as:
E. The variable var must be of type const int, and then it can be assigned as:
Question 19: Which of the following are not pre-processor directives in C++?
{
const int Mon = 1, Tue = 2;
enum DOW{ Mon = 11, Tue = 12 };
...
var = Mon;
error.
var = Mon;
var = DOW::Mon;
var = static_cast(Mon);
A. #ifndef
B. #ifdef
C. #elif
D. #define
E. #extern
storage for their elements in C++?
A. std::allocator<>::allocate(size_t)
B. std::allocator<>::malloc(int)
C. std::allocator<>::make(size_t)
D. std::allocator<>::new(size_t)
E. std::allocator<>::acquire(size_t)
Question 20: Which allocator member function do standard containers use to acquire
Question 21: Which of the following statements provide a valid reason not to use
RTTI for distributed (i.e. networked between different platforms) applications in
C++?
A. RTTI does not have standardized run-time behavior.
B. RTTI uses too much memory.
C. RTTI is too slow.
D. RTTI's performance is unpredictable/non-deterministic.
E. RTTI frequently fails to function correctly at run-time.