Introduction of C++ language. C++ Predecessors Early high level languages or programming languages...

20
Introduction of C++ Introduction of C++ language language

Transcript of Introduction of C++ language. C++ Predecessors Early high level languages or programming languages...

Page 1: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Introduction of Introduction of C++ languageC++ language

Page 2: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

C++ Predecessors Early high level languages or programming

languages were written to address a particular kind of computing problem. Like: FORTRAN: Formula Translation COBOL: Common Business Oriented Language

Other programming languages can be used to solve diverse types of computing programs: BASIC: Beginners All-purpose Symbolic

Instruction Code C

Page 3: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Background C++ is based on C; in fact, C++ is a superset of C. Developed by Bjarne Stroustrup at AT&T Bell

Laboratories Standard C++ Was formally adopted by American National

Standards Institute and ISO to provide a common base in 1998 - our course is based on C++ as represented by “The C++ Programming Language”, Third Edition by B. Stroustrup

Page 4: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

C and C++ C is a procedure oriented language designed to be,

As powerful As fast “Close to the machine” portable

C++ is object oriented language. C++ is the “next generation”. C++ is an extension version of C language. New features for writing programs

C and C++ compilers are very advanced pieces of software

Page 5: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

What is C++

C++ can be “Object Oriented” Describe objects (things) What to do with them

It is very fast and very powerful C++ is EASIER than C C++ is able to map the real world problem.

Page 6: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Applications of C++

C++ allows expression of abstract ideas. C++ has national standards. C++ is reusable and object oriented. C++ is widely used and taught.

Page 7: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

7

The “Hello, World!” program

C notation#include <stdio.h> //include header filevoid main( ){ printf(“Hello, World!”);}

Page 8: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

8

The “Hello, World!” program

C++ notation#include<iostream.h> //include header

filevoid main( ){ cout << “Hello, World!”;}

Page 9: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Basic structure of C++ program The general structure of C++ program is subdivided

into different sections: Documentation section Include files Global Declaration section Main C++ program function Beginning of the program using { End of the program using } Sub-program section having user defined functions

Page 10: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Documentation section

C++ support two ways to insert comments: Line Comment- indicates by symbol // Block comments- start with /* and end with

*/ - apply to as many lines as you like Used to describe the code in English or

provide non-code information E.g. to include the name of the program or

the author’s name

Page 11: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Include files

Pre-compiler statements are divided into two sections. One is link section and other is definition section.

In link section we link the compiler in-built function like cin>>, cout<<, clrscr() etc with INCLUDE subdirectory header files like iostream.h, conio.h etc. Like:

#include <iostream.h>

has operators for performing input and output within the program.

Page 12: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Include files

Ends with a semicolon Follows #include directives in the code Must appear in all programs

Page 13: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Global declaration section

Data type v1,v2,v3…….vn; Data types are int, float, char etc. and

v1,v2….vn are variables. For example, global variables are declared as:

int a,b,c;

float x,y;

Page 14: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Main C++ program function called main Exactly one main function per program A function is a collection of related statements that

perform a specific operation int indicates the return type of the function ( ) indicates no special information passed to the

function by the operating system. Like:

Main() or void main()

Page 15: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Beginning of the program {- the beginning of the main program can

be done by using curly bracket “{“. Local variable declaration -

int a,b,c; Executable statements - specify the actions

the program will take:

cout << “Enter the values of a and b:”;

cin >> a>>b;

Page 16: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

End of the program

Ending of the main program: } – by using this bracket “}” we can end the

main program in C++ language.

Page 17: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Sub-program section having user defined functions Function 1()

{ user defined program or body of the function sub program }

Function 2()

{ Another user defined sub program }

Page 18: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Compiling and linking

Compiler refers to the processing of source code files(.c, .cpp) and creation of an ‘object’ file.

The compiler is a program that takes the code that you write and translates it into machine language

Machine code is made up of many simple instructions composed of 0’s and 1’s

Linking refers to the creation of a single executable file from multiple object files.

Now type the program from first row and the first column. This is called editing.

Page 19: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

Compiling and linking

If you want to save the program, then either press F2 function key from the keyboard or select the save option from the file menu. If you want to compile a C++ program then either select from the Compile menu or press Ctrl+F9.

Page 20: Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.

IDE

Integrated Development Environment. All in one system for developing programs. Can edit, compile, link and execute our programs

all from the comfort of our IDE.