0% found this document useful (0 votes)
11 views14 pages

Lec 04-05

This document provides an overview of C++ programming, including its history, basic structure, and key features such as object-oriented programming. It discusses the role of pre-processor directives, the main function, and the use of namespaces in C++. Additionally, it explains the compilation process and the types of data supported by C++.

Uploaded by

hijabmemon03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

Lec 04-05

This document provides an overview of C++ programming, including its history, basic structure, and key features such as object-oriented programming. It discusses the role of pre-processor directives, the main function, and the use of namespaces in C++. Additionally, it explains the compilation process and the types of data supported by C++.

Uploaded by

hijabmemon03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Object Oriented Programming:

C++
Lecture – 4-5

C++ Programming Basics


Lecture Outline

• Getting started
– C and C++
– Basic program construction
– Data types
– Library functions
C++
• C++ is a statically typed, compiled, general purpose, case-sensitive
programming language that support procedural, object oriented &
generic purpose.
• C++ Development started in 1979.
• During the creation of Ph.D. thesis, Bjarne Stroustrup worked with
language called Simula.
• Simula was first language to support object-oriented programming
paradigm
• Bjarne Stroustrup identified that this OOP features can be
included in the software development.
• After that Bjarne Stroustrup started working on the C language
and added more extra OOP features to the classic C.
C++
• In this way, C++ was developed by Bjarne Stroustrup at Bell Labs in
Murray hills

• In 1983, it was renamed from C with Classes to C++

• In C we have already used increment operator (++). Therefore we


called C++ as “Incremented C” means Extension to C.
Creator of C++

Bjarne Stroustrup
C and C++
– C++ is advanced version of C language
– Every correct statement in C is also a correct statement in C++
– C++ contains all the features of C language and additionally
contains many other object oriented features like classes,
objects, inheritance and so on.
Functions
– A C++ program may consist of many functions, classes, and other
program elements.

– The first statement executed in any C++ program is at the beginning of


a function called main()
– On start-up control always goes to main(). The program may report an
error if there is no function called main()
Getting Started
#include <iostream> Pre-processor
#include <conio.h> directive
the using directive
using namespace std;
Function
return main function
type
int main()
string constant
{
cout << “Welcome to C++”;
output stream getch(); getch function that keeps
object
} output visible on screen
Output Using cout
– The statement
cout << “Welcome to C++”;
causes the phrase in quotation marks to be displayed on the

screen.
– cout is predefined object that redirects the stream (flow of
data) to output device. cout is predefined in C++ library.
– The operator << is called the insertion or put-to operator. It
directs the contents of the variable on its right to the object on
its left.
Pre-processor Directives

Pre-processor directive header/include file

#include <iostream>
#include <conio.h>

– Program instruction (which end with semicolon) are


instructions to the computer to do something; pre-processor
directives are instruction to the compiler.
– A part of the compiler called the pre-processor deals with
these directives before it begins the real compilation process.
– #include tells the compiler to insert another file into your
source file.
– The type file included by #include is called a header/include file
Pre-processor Directives

Pre-processor directive header/include file

#include <iostream>
#include <conio.h>
• header/include file:
– iostream is an example of a header file.
– The pre-processor directive #include tells the compiler to add the
source file iostream to the source file before compiling.
– iostream is concerned with basic input/output operations and
contains declarations that are needed by the cout and <<
(insertion operator).
– Without iostream compiler won’t regonize cout and << and will
generate an error message.
– iostream file can be found in the include directory of C++
compiler
The using Directive
the using directive using namespace std;

– A C++ program may be divided into different namespaces


– A namespace is a part of the program in which certain names
are recognized; outside of the namespace they are unknown.
– The directive using namespace std; says that all the program
statements that follow are within the std namespace. Various
program components such as cout are declared within this
namespace.
– If we didn’t use the using directive, we would need to add the
std name to many program elements:
std::cout<< “Welcome to C++”
The using Directive
the using directive using namespace std;

std::cout<< “Welcome to C++”


What is a Compiler?
• A program written in a high level language is called the “source code”,
and it does not make sense to a computer.
• The computer understands only one language –the “machine code”.
• Thus, the source-code must be translated into machine code. The
translation process is called compilation and the program is called
compiler.
• This compiled program can then be run/executed. So, on a computer
you can use any programming language for which the computer has a
compiler.

– C++ provides integer, floating-point numbers, and character variable types

You might also like