Programs


  1. What is the purpose of #include <iostream.h> ?

  2. What is a source program? An executable?

  3. Is a semi-colon required after a comment?

  4. What is wrong with the following statement?
    cout << Hello World\n;
    
  5. What is wrong with the following statement?
    COUT << "Hello World\n";
    
  6. What is wrong with the following statement?
    cout  >> "Hello World\n";
    
  7. What is the purpose of the \n ?

  8. What is wrong with the following statement?
    
    cout << "Hello World"\n;
    


Answers


































  1. It includes the header file iostream.h into the source code. This file is required for input and output to the program. Therefore, if the cout statement is used to output text/data to the screen it is required.

  2. Source code is the actual C++ program which is typed into the file. This is then compiled into machine code which can be executed by the computer.

  3. No - a comment is not a program statement, so does not require to be terminated by a semi-colon.

  4. The text to be printed must be within double quotes.
    
    cout << "Hello World\n";
    
  5. Keywords in C++ must be lowercase COUT must be written as cout

  6. The output operator is << and not >>

  7. The \n causes the a new line. It is required at the end of Hello WOrld to ensure the cursor returns to the next line.

  8. The \n (newline) is text to be printed and must be within the double quotes.


Back to Questions Back to Main Page for Lecture 1