Presentation is loading. Please wait.

Presentation is loading. Please wait.

Learners Support Publications www.lsp4you.com Introduction to C++

Similar presentations


Presentation on theme: "Learners Support Publications www.lsp4you.com Introduction to C++"— Presentation transcript:

1 Learners Support Publications www.lsp4you.com Introduction to C++

2 Learners Support Publications www.lsp4you.com Objectives of this session What is C++ What is C++ A Simple Program A Simple Program Comments in C++ Comments in C++ Output Operator Output Operator Input Operator Input Operator Cascading of I/O Operator Cascading of I/O Operator Structure of a C++ Program Structure of a C++ Program

3 Learners Support Publications www.lsp4you.com C++ C++ is an object-oriented programming language. C++ is an object-oriented programming language. Developed by Bjarne Stroustrup at AT&T Bell Laboratories, USA in the early 1980’s. Developed by Bjarne Stroustrup at AT&T Bell Laboratories, USA in the early 1980’s. Simule 67 + C language  C++ Simule 67 + C language  C++ 1997 November ANSI/ISO standards committee standardised C++. 1997 November ANSI/ISO standards committee standardised C++. For developing editors, compilers, databases, communication systems, etc. For developing editors, compilers, databases, communication systems, etc.

4 Learners Support Publications www.lsp4you.com A Simple Program C++ works by giving (separate) instructions to the computer. C++ works by giving (separate) instructions to the computer. These instructions can be written as functions. These instructions can be written as functions. The primary function used in C++ is called main. This means that every C++ program should have the main() function. Because a function is an assignment, in order to perform its job, a function has a body. The body of a function starts with an opening curly bracket "{" and closes with a closing curly bracket "}". The primary function used in C++ is called main. This means that every C++ program should have the main() function. Because a function is an assignment, in order to perform its job, a function has a body. The body of a function starts with an opening curly bracket "{" and closes with a closing curly bracket "}".

5 Learners Support Publications www.lsp4you.com A Simple Program // my first program in C++ #include #include int main ( ) { cout << "Hello World!"; return 0; } Hello World! continue…

6 Learners Support Publications www.lsp4you.com Comments in C++ The most basic documentation you have to perform is to put comments as much as you can. Comments help you and other people who read your code to figure out what you were doing. The most basic documentation you have to perform is to put comments as much as you can. Comments help you and other people who read your code to figure out what you were doing. Comments are not read by the compiler while executing your program. Comments are not read by the compiler while executing your program. C++ supports two ways to insert comments: C++ supports two ways to insert comments: o // line comment o /* block comment */

7 Learners Support Publications www.lsp4you.com Comments in C++ // The hello.cpp program // Include the iostream library #include #include int main( ) { /* Here is a simple sentence that I want to display when the program starts. It doesn't do much. I am planning to do more stuff in the future. */ cout << "Hi, this is my program!"; return 0; } // The end of my program continue…

8 Learners Support Publications www.lsp4you.com Output Operator cout << "Hi, this is my program!"; cout is a predefined object that represents the standard output stream in C++, here the standard output stream is screen. scree n cout << C++ variable ObjectInsertion Operator

9 Learners Support Publications www.lsp4you.com Output Operator The operator << is called insertion or put to operator. The operator << is called insertion or put to operator. It inserts ( or sends ) the contents of the variable on its right to the object on its left. It inserts ( or sends ) the contents of the variable on its right to the object on its left. cout << "Hi, this is my program!"; cout << number ; scree n cout << C++ variable ObjectInsertion Operator continue…

10 Learners Support Publications www.lsp4you.com Input Operator cin >> number1; cin is a predefined object that corresponds to the standard input stream in C++, here the standard input stream is keyboard. cin >> 50.55 ObjectExtraction Operator C++ variable Keyboard

11 Learners Support Publications www.lsp4you.com Input Operator The operator >> is known as extraction or get from operator. The operator >> is known as extraction or get from operator. It extracts ( or takes ) the value from the keyboard and assigns it to the variable on its right. It extracts ( or takes ) the value from the keyboard and assigns it to the variable on its right. cin >> 50.55 ObjectExtraction Operator C++ variable Keyboard continue…

12 Learners Support Publications www.lsp4you.com Cascading of I/O Operators Multiple use of > in one statement is called cascading. Multiple use of > in one statement is called cascading.eg:- cout << “Sum = ” << sum << “\n”; cin >> number1 >> number2;

13 Learners Support Publications www.lsp4you.com Structure of a C++ Program Better to organize a program file into three separate files. o Class declarations in a header file. o Definition of member function in a separate file. o The main program that uses the class is placed in a third file which includes the previous two files. Include files Class declaration Member functions declaration Main function program


Download ppt "Learners Support Publications www.lsp4you.com Introduction to C++"

Similar presentations


Ads by Google