Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout << “Welcome to C++! \n”; return.

Similar presentations


Presentation on theme: "Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout << “Welcome to C++! \n”; return."— Presentation transcript:

1 Introduction to C++ Programming

2 A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout << “Welcome to C++! \n”; return 0; // indicate that program ended successfully }

3 Let’s look at your program: // - indicates that the remainder of each line is a comment! It is also called a single-line comment because the comment terminates at the end of the line. Note: Programmers insert comments to document programs and improve program readability. They also help other people read and understand your program.

4 If your comment contain more than one line you can use the following: begin with / * and end with */ Example: /* Your Name Computer Science Exercise 1 September 7, 2005 */

5 The line #include is called a preprocessor directive. What does it do? It tells the computer to include the contents of the input/output files in the program! It outputs to the screen and allows the user to input data into the computer using the keyboard.

6 The line int main ( ) is a part of every C++ program. Note: Every C++ contains one or more functions and main is one function that appears in every program.

7 The left and right braces - { } The left brace indicates the beginning of the body of the function main ( ). The right brace indicates the ending of the body of the function main ( ).

8 The line cout << “Welcome to C++! \n”; Tells the computer to print the line of text between the quotation marks. Another name for this line of code is called a statement. This statement consists of cout, << operator, the string “Welcome to C++!”, and a semi-colon.

9 The backslash \ is called an escape character. It indicates that a “special” character is to be output. The next character following the backslash is called an escape sequence as in the \n.

10 The line return 0; // indicate that program ended successfully is used to exit a function! When a return is used at the end of a function it means the value 0 indicates that the program has terminated successfully.

11 Escape SequenceDescription \nNewline. Position the screen cursor to the beginning of the next line. \tHorizontal tab. Move the screen cursor to the tab stop. \rCarriage return. \aAlert. Sound the system bell. \\Backslash. Used to print a backslash character. \*Double quote. Use to print a double quote character.

12 Another Program! //Program #2 #include int main ( ) { cout << “Welcome “; cout << “to C++! \n”; return 0; //indicate that program ended successfully }

13 Program 3! //Program #3 #include int main ( ) { cout << “Welcome\nto\n\nC++! \n “; return 0; //indicate that program ended successfully }

14 Do we have time for another Program? #include // This is a C++ program that will print a // message to the screen. main( ) { cout << “Programming in C++ is fun!”; }

15 Last one! When the following program is compiled and executed, what will the program cause to be displayed on the screen? #include main ( ) { cout << “// This is a C++ program. \n”; }

16 Homework! Read pages 5 to 21 and take notes!


Download ppt "Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout << “Welcome to C++! \n”; return."

Similar presentations


Ads by Google