Revised: February 3, 2007
By Richard G. Baldwin
File Pfsg00105.htm
Practice Text Index
The practice tests in this series were written specifically for the benefit of my students in COSC 1315, Fundamentals of Programming. They consists of questions, answers, and explanations. The questions are based on the material covered in my series of online lecture notes for the course. Each practice test is keyed to a specific lecture. This practice test is keyed to lecture #105 titled Global main Function, Includes, Using, Code Blocks, Comments, and Simple Output.
105-2. True or False: You submit your source code to a compiler program that translates your source code into machine code. Machine code is a low-level programming language that is understood by the computer. Very few humans can understand machine code.
105-3. True or False: The program in Listing 105-3 illustrates the following programming elements:
#include <iostream> using namespace std; //Every C++ program requires a main // function. int main(){ //Everything inside this matching pair of // curly braces constitutes a block of // code. //Everything inside the following matching // pair of curly braces constitutes a // nested block of code with no purpose other // than to illustrate the nesting of code // blocks. {//Begin nested code block //Display something on the screen cout << "Hello World\n"; }//end nested code block return 0; }//end main |
105-4. If you use the program named Dev C++ to compile the code in Listing 105-4, and run the program from the command prompt, the output will be:
#include <iostream> using namespace std; //Every C++ program requires a main // function. int main(){ //Everything inside this matching pair of // curly braces constitutes a block of // code. //Everything inside the following matching // pair of curly braces constitutes a // nested block of code with no purpose other // than to illustrate the nesting of code // blocks. {//Begin nested code block //Display something on the screen cout << "Hello World\n"; }//end nested code block return 0; }//end main |
105-5. If you store the code from Listing 105-5 in a file named Includes01.cpp and use the program named Dev C++ to compile the file, the result of the compilation will be:
#include <iostream> using namespace std; //Every C++ program requires a main // function. int main(){ //Everything inside this matching pair of // curly braces constitutes a block of // code. //Everything inside the following matching // pair of curly braces constitutes a // nested block of code with no purpose other // than to illustrate the nesting of code // blocks. {//Begin nested code block //Display something on the screen cout << "Hello World\n"; }//end nested code block return 0; }//end main |
105-6. After saving the code from Listing 105-6 in a file named Includes01.cpp and using the program named Dev C++ to compile the program, you can execute the program by entering which of the following at the command prompt:
#include <iostream> using namespace std; //Every C++ program requires a main // function. int main(){ //Everything inside this matching pair of // curly braces constitutes a block of // code. //Everything inside the following matching // pair of curly braces constitutes a // nested block of code with no purpose other // than to illustrate the nesting of code // blocks. {//Begin nested code block //Display something on the screen cout << "Hello World\n"; }//end nested code block return 0; }//end main |
105-7. True or False: C++ programs typically require compiler directives of the form:
import ...
105-8. True or False: The purpose of the include compiler directive is to cause the system to find and to include the executable code for various prewritten library functions in your code before attempting to compile your program.
105-9. True or False: The code in Listing 105-9 causes a set of functions necessary to support floating point arithmetic to be located and inserted into the program before an attempt is made to compile the program.
Listing 105-9.
#include <iostream> using namespace std; |
105-10. True or False. The following is a general explanation of the purpose of the using directive in Listing 105-10.
Listing 105-10."All the elements of the standard C++ library are declared within what is called a surname, the surname with the name std. So in order to access its functionality we declare with this expression that we will be using these entities."
#include <iostream> using namespace std; |
105-11. True or False: All C++ programs require a function named main.
105-12. True or False. The main function contains at least one block of code.
105-13. Just like in Java, only one format is allowed for the signature of the main function in C++.
105-14. True or False. The main function may not be global in C++.
105-15. Which of the following is an insertion operator?
105-16. True or False. A right operand normally appears to the left of the insertion operator.
105-17. True or False. Something that gets operated on is called an operator.
105-18. An operand is a symbol, or combination of symbols (such as <<), that operates on something to cause something to happen.
105-19. Which of the following is the newline escape character?
105-20. True or False. Code blocks may not be nested inside other code blocks.
105-21. True or False. A code block always begins with /* and ends with a */.
105-22. True or False. Comments are not intended to have any impact on the execution of the program, and in fact are completely ignored by the compiler.
105-23. True or False. Listing 105-23 contains a valid multi-line comment.
Listing 105-23.
/* One or more lines of comments can appear between the comment indicators Another comment line */ |
105-24. True or False. Listing 105-24 contains a pair of valid single-line comments.
Listing 105-24.
int main()/*A single-line comment /*Another single-line comment |
105-25. True or False. A successful compilation and execution using Dev C++ will produce a file named Includes01.exe. It will also create a new directory named Debug containing a large number of files.
Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two. He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.
The statement is false because the main function is global in C++.
Note the incorrect use of the word surname.
#include <iostream>
using namespace std;
Either of the following:
Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two. He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.
Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.
-end-