Chapter 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Faculty of Computer Science

Introduction to Programming

Lecturer: Lutfullah “Haqnesar”


Introduction to Programming

Chapter 2

Syntax of C++
Introduction to Programming

Learning outcomes:

History of C++
What is an IDE?
Structure of c++ Program
Introduction to Programming

History of C language
The C programming language was designed by Dennies Ritchie in the early 1970’s at
Bell Laboratories.
The main reason to devised C was to overcome the limitations of B.
It was Derived from the language BCPL (Basic Combined Programming Language).
C was the evolution of B and BCPL.
It was originally intended for use in writing compilers for other languages.

CPL BCPL B C C++


Introduction to Programming
Introduction to Programming

History of C++ language

C++ programming language was developed in 1980 by Bjarne Stroustrup at bell


laboratories of AT&T (American Telephone & Telegraph), located in U.S.A.
Bjarne Stroustrup is known as the founder of C++ language.
It was develop for adding a feature of OOP (Object Oriented Programming) in
C without significantly changing the C component.
C++ programming is called a superset of C, it means any valid C program is also
a valid C++ program.
Introduction to Programming

What is C++?
• C++ is a general purpose, case-sensitive, high level programming
language that supports procedural and object-oriented programming.

• C++ is an object-oriented programming, that supports the concept of


classes and objects..
Introduction to Programming

Integrated Development Environment


• IDE (Integrated Development Environment) is a programming environment that
contains a lot of things in a single package i.e. code editor, compiler and debugger.
• It combines all the basic tools that developers need to write or test software.
• This type of environment allows an application developer to write code while
compiling, debugging and executing it at the same place.
• For example: The IDE for developing Java Application is Eclipse, NetBeans, and
IDE for developing C++ programs are Visual Studio, CodeBlocks, Dev C++ and
etc.
Introduction to Programming

Dev-C++

Dev- C++ is a free full-featured integrated development environment (IDE)


distributed under the General Public License for programming in C and C++.
It was originally developed and first released in 1998.
Introduction to Programming
First C++ Program
#include <iostream.h>
#include<conio.h>
Using namespace std;
void main() {
cout << "Welcome to C++ Programming.";
}
Introduction to Programming
First C++ Program
• #include<iostream.h> is header file that includes the standard input
output library functions. It provides cin and cout object for reading from
input and writing to output respectively.
• #include <conio.h>: includes the console input output library functions. The
getch() function is defined in conio.h file.
• void main(): The main() function is the entry point of every program in C++
language.
• cout << "Welcome to C++ Programming." is used to print the data
"Welcome to C++ Programming." on the console.
Introduction to Programming

Structure of a C++ program

• A C++ program is structured in a specific and particular manner.


• In C++, a program is divided into the following three sections:
1. Standard Libraries Section
2. Main Function Section
3. Function Body Section
Introduction to Programming

Structure of a C++ program

For example, let’s look at the implementation of the Hello World program:

#include <iostream>
using namespace std;

int main() {
cout << "Hello World!" << endl;
}
Introduction to Programming
1. Standard libraries section:
#include <iostream>
using namespace std;
Generally, a program includes various programming elements like built-in
functions, classes, keywords, constants, operators, etc. that are already defined in
the standard C++ library.
In order to use such pre-defined elements in a program, an appropriate header
must be included in the program.
Standard headers are specified in a program through the preprocessor directive
#include.
Introduction to Programming
1. Standard libraries section: (con….)
#include <iostream>
using namespace std;

A namespace permits grouping of various entities like classes, objects, functions,


and various C++ tokens, etc. under a single name.
Any user can create separate namespaces of its own and can use them in any
other program.
Introduction to Programming
2. Main function section
int main() {}

The starting point of all C++ programs is the main function.


This function is called by the operating system when your program is executed by
the computer.
{ signifies the start of a block of code, ​and } signifies the end.
Introduction to Programming
3. Function body section

cout << "Hello World" << endl;


The code and what the function should do comes here.
The name cout is short for character output and displays whatever is between the
<< brackets.
Symbols such as << can also behave like functions and are used with the keyword
cout.
Execution of the code terminates here.
Introduction to Programming

Thank You
For Your Patience

You might also like