common programming errors

Post on 12-Jan-2017

31 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Common Programming Errors

1. Omitting the parentheses after main().

2. Omitting or incorrectly typing the opening brace, {, that signifies the start of a function body.3. Omitting or incorrectly typing the closing brace, }, that signifies the end of a function.

4. Omitting the semicolon at the end of each C++ executable statement.

5. Adding a semicolon after the #include <iostream> preprocessor command.

6. Misspelling the name of an object or function, such as typing cot instead of cout.

7. Forgetting to enclose a string sent to cout with double quotation marks.

8. Forgetting the \n to indicate a new line.

Chapter Summary 1. A computer program is a self-contained unit of instructions and data used to operate a computer to produce a specific result. 2. An algorithm is a step-by-step procedure that must terminate; it describes how a computation or task is to be performed. 3. A C++ program consists of one or more modules called functions. One of these functions must be called main(). The main() function identifies the starting point of a C++ program.

4. The simplest C++ program consists of the single function main() and has this form:

#include <iostream> using namespace std;int main() { program statements in here; return 0; }

This program consists of a preprocessor #include statement, a using statement, a header line for the main() function, and the body of the main() function. The body of the function begins with the opening brace, {, and ends with the closing brace, }.

5. All executable C++ statements within a function body must be terminated by a semicolon.

6. Many functions and classes are supplied in a standard library provided with each C++ compiler. One set of classes, used to create input and output capabilities, is defined in the iostream header file. 7. The cout object is used to display text or numerical results. A stream of characters can be sent to cout by enclosing the characters in quotation marks and using the insertion symbol, <<, as in the statement cout << “Hello World!”;. The text in the string is displayed onscreen and can include newline escape sequences for controlling the format.

top related