CE144
OBJECT ORIENTED PROGRAMMING
WITH C++
UNIT-2
Introduction of C++
N. A. Shaikh
[email protected]
Topics to be covered
What is C++
Simple C++ Program
Applications of C++
Introduction to class, object
Creating simple program using class
Structure of C++ program
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
2
What is C++
C++ is an object-oriented programming language.
C++ is an extension of C with a major addition of the
class construct feature.
That’s why initially this language was known as 'C with
classes‘, later the name was changed to C++.
The idea of C++ comes from the C increment operator
++, thereby suggesting that C++ is an augmented
(incremented) version of C.
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
3
What is C++
The most important facilities that C++ adds on to C are
classes, inheritance, function overloading, and operator
overloading.
Those features enable creating of abstract data types,
inherit properties from existing data types and support
polymorphism, thereby making C++ a truly object-
oriented language.
The addition of new features has transformed C from a
language that currently facilitates top-down, structured
design, to one that provides bottom-up, object-oriented
design.
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
4
Simple C++ Program
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
5
Simple C++ Program
The iostream File
• It contains declarations for the identifier cout and the
operator <<
• Some old versions of C++ use a header file called
iostream.h
Namespace
• using and namespace are the new keywords of c++
• This defines a scope for the identifiers that are used
in a program
Comments
• // Single line comment
• /*….*/ Multiline comment
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
6
Simple C++ Program
main()
• Execution begins at main()
• Every program must have a main()
• In C++, main() returns an integer type value to OS
• Therefore, main() should end with a return 0
• Default type of main() is int
NOTE:
The multiple use of << in one statement is called
cascading
cin can read only one word and therefore we cannot use
names with blank spaces.
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
7
Simple C++ Program
Output using insertion operator Input using extraction operator
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
8
Applications of C++
Since C++ allows us to create hierarchy-related objects,
we can build special object oriented libraries which can
be used later by many programmers.
While C++ is able to map the real-world problem
properly, the C part of C++ gives the language the ability
to get close to the machine-level details.
C++ programs are easily maintainable and expandable.
When a new feature needs to be implemented, it is very
easy to add to the existing structure of an object.
It is expected that C++ will replace C as a general-
purpose language in the near future.
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
9
An Example with class
Major feature of C++ which binds data and function
Like structure, classes are user defined data types
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
10
Structure of C++ program
Structure of C++ program The client-server model
Unit 2: Introduction of C++ Prepared By: Nishat Shaikh
11
End of Unit-2