Content Frame
Note for screen reader users: There is text between the form elements on this page. To be sure that you do not miss any text, use item by item navigation methods, rather than tabbing from form element to form element.
Skip Breadcrumb Navigation
Home  arrow Student Resources  arrow Quizzes  arrow Chapter 11

Chapter 11

Separate Compilation and Namespaces

This activity contains 10 questions.

Question 1.
How would we include the header file named "myfile.h" in an implementation file?

 
End of Question 1


Question 2.
Which of the following is not an advantage of separating the definition (.h file) from the implementation (.cpp file)?

 
End of Question 2


Question 3.
What is the role of the linker?

 
End of Question 3


Question 4.

If the following class definition is stored in a file called MyInt.h:

class MyInt {
private:
    int *p_num;
public:
	MyInt();
	MyInt(int n);
	int GetNum();
	void SetNum(int n);
	MyInt& operator=(const MyInt &rtSide);
};

What could you add to the file so that it is not included more than once if the file is used in multiple implementation files?
 
End of Question 4


Question 5.
What is the major difference between a directive, such as #define, and a statement such as "if (defined) { ... }" ?

 
End of Question 5


Question 6.

What is the output of the following program?

using namespace std;

namespace Foo
{
	void zot(int i) {
		cout << i << endl; 
	}
}

namespace Bar
{
	void zot(int i) {
		cout << ++i << endl; 
	}
}

int main()
{
	int x=0;
	{
		using namespace Bar;
		zot(x);
	}

	{
		using namespace Foo;
		zot(x);
	}
	
	return 0;
}
 
End of Question 6


Question 7.
When your program only uses cin and cout from namespace std, why is it preferable to use:

using std::cout;
using std::cin;

instead of:

using namespace std;

 
End of Question 7


Question 8.

What will the following program output?

using namespace std;

namespace Foo
{
	void zot(int i) {
		cout << i << endl; 
	}
}

namespace Bar
{
	void zot(int i) {
		cout << ++i << endl; 
	}
}

int main()
{
	int x=0;
	using namespace Bar;
	using namespace Foo;
	zot(x);
	
	return 0;
}
 
End of Question 8


Question 9.
Anything that is defined outside a namespace is automatically put in the:

 
End of Question 9


Question 10.
How could we use cout to output a variable named "var" without adding any "using" directive at all?

i.e. there is no:


using namespace std;

or

using std::cout;

 
End of Question 10





Pearson Copyright © 1995 - 2010 Pearson Education . All rights reserved. Pearson Addison Wesley is an imprint of Pearson .
Legal Notice | Privacy Policy | Permissions

Return to the Top of this Page