COSC 1315

Programming Fundamentals

 Practice Text #105

Global main Function, Includes, Using, Code Blocks, Comments, and Simple Output

Revised: February 3, 2007
By Richard G. Baldwin

File Pfsg00105.htm
Practice Text Index


Welcome

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.

Questions



105-1.  True or False:  You write your program in source code, which is a low level computer programming language that is understood by humans.

Answer and Explanation

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.

Answer and Explanation

105-3.  True or False:  The program in Listing 105-3 illustrates the following programming elements:

Listing 105-3. 
#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

Answer and Explanation

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:

Listing 105-4. 
#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

Answer and Explanation

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:

Listing 105-5. 
#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

Answer and Explanation

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:

Listing 105-6. 
#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

Answer and Explanation

105-7.  True or False:  C++ programs typically require compiler directives of the form:

import ...

Answer and Explanation

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.

Answer and Explanation

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;

Answer and Explanation

105-10.  True or False.  The following is a general explanation of the purpose of the using directive in 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."

Listing 105-10.
#include <iostream>

using namespace std;

Answer and Explanation

105-11.  True or False:  All C++ programs require a function named main.

Answer and Explanation

105-12.  True or False.  The main function contains at least one block of code.

Answer and Explanation

105-13.  Just like in Java, only one format is allowed for the signature of the main function in C++.

Answer and Explanation

105-14.  True or False.  The main function may not be global in C++.

Answer and Explanation

105-15.  Which of the following is an insertion operator?

Answer and Explanation

105-16.  True or False.  A right operand normally appears to the left of the insertion operator.

Answer and Explanation

105-17.  True or False.  Something that gets operated on is called an operator.

Answer and Explanation

105-18.  An operand is a symbol, or combination of symbols (such as <<),  that operates on something to cause something to happen.

Answer and Explanation

105-19.  Which of the following is the newline escape character?

Answer and Explanation

105-20.  True or False.  Code blocks may not be nested inside other code blocks.

Answer and Explanation

105-21.  True or False.  A code block always begins with /* and ends with a */.

Answer and Explanation

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.

Answer and Explanation

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
*/

Answer and Explanation

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

Answer and Explanation

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.

Answer and Explanation



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

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.

Baldwin@DickBaldwin.com


Answers and Explanations

Answer 25

False

Back to Question 25

Explanation 25

Answer 24

False

Back to Question 24

Explanation 24

Answer 23

True

Back to Question 23

Explanation 23

Answer 22

True

Back to Question 22

Explanation 22

Answer 21

False

Back to Question 21

Explanation 21

Answer 20

False

Back to Question 20

Explanation 20

Answer 19

D.  None of the above.

Back to Question 19

Explanation 19

Answer 18

False

Back to Question 18

Explanation 18

Answer 17

False

Back to Question 17

Explanation 17

Answer 16

False

Back to Question 16

Explanation 16

Answer 15

B.  <<

Back to Question 15

Explanation 15

Answer 14

False

Back to Question 14

Explanation 14

The statement is false because the main function is global in C++.

Answer 13

False

Back to Question 13

Explanation 13

Answer 12

True

Back to Question 12

Explanation 12

Answer 11

True.

Back to Question 11

Explanation 11

Answer 10

False.

Back to Question 10

Explanation 10

Note the incorrect use of the word surname.

Answer 9

False..

Back to Question 9

Explanation 9

Answer 8

False.

Back to Question 8

Explanation 8

The purpose of the include compiler directive is to cause the system to find and to include the source code for various prewritten library functions in your source code before attempting to compile your program.

Answer 7

False.

Back to Question 7

Explanation 7

C++ programs typically require import directives of the form:

#include <iostream>
using namespace std;

Answer 6

Either of the following:

Back to Question 6

Explanation 6

The Dev C++ compiler produces an output executable file named Includes01.exe.  You can run the program by entering the name of the executable file at the command prompt, and you can drop the extension if you care to do so.

Answer 5

A.  A single output file named Includes01.exe

Back to Question 5

Explanation 5

Answer 4

C.  Hello World

Back to Question 4

Explanation 4

Answer 3

False

Back to Question 3

Explanation 3

The given code does not illustrate either of the following:

Answer 2

True

Back to Question 2

Explanation 2

Answer 1

False

Back to Question 1

Explanation 1



Copyright 2007, Richard G. Baldwin.  Reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.

About the author

Richard Baldwin is a college professor (at Austin Community College in Austin, TX) and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

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.

Baldwin@DickBaldwin.com

-end-