0% found this document useful (0 votes)
3 views

Topic 1 Introduction to C++ Programming

The document provides an overview of C++ programming, detailing its history, similarities and differences with C, and its object-oriented capabilities. It highlights key features such as encapsulation, polymorphism, and inheritance, as well as the structure of C++ programs. Additionally, it discusses the benefits of object-oriented design in software development.

Uploaded by

xediceelili2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Topic 1 Introduction to C++ Programming

The document provides an overview of C++ programming, detailing its history, similarities and differences with C, and its object-oriented capabilities. It highlights key features such as encapsulation, polymorphism, and inheritance, as well as the structure of C++ programs. Additionally, it discusses the benefits of object-oriented design in software development.

Uploaded by

xediceelili2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Programming and

Computer Applications-2

Introduction to C++ Programming

Instructor : PhD, Associate Professor Leyla Muradkhanli


History of C++
• C++ was developed by Bjarne Stroustrup in the early 1980s at
Bell Laboratories
• Originally called “C with classes”
• The name C++ is based on C’s increment operator (++)
• Indicating that C++ is an enhanced version of C

• Widely used in many applications and fields


• The C++ logo endorsed by Standard C++

2
C++
• Improves on many of C's features
• Has object-oriented capabilities
• Increases software quality and reusability
• Superset of C
• Can use a C++ compiler to compile C programs
• Gradually evolve the C programs to C++
C++

4
Similarities Between C And C++
• Both the languages have a similar syntax.
• Code structure of both the languages are same.
• The compilation of both the languages is similar.

5
Differences Between C And C++
• Language Type
C is procedural programming.
C++ supports both procedural and object-oriented
programming paradigms.
• OOPs feature Support
C does not support the OOPs concept so it has no support for
polymorphism, encapsulation, and inheritance.
C++ has support for polymorphism, encapsulation, and
inheritance as it is being an object-oriented programming
language
6
Differences Between C And C++
• Data Security
As C does not support encapsulation so data behave as a free
entity and can be manipulated by outside code.
C++ encapsulation hides the data to ensure that data
structures and operators are used as intended.
• Driven type
C in general known as function-driven language.
C++ is known as object driven language.

7
Differences Between C And C++
• Feature supported
C does not support function and operator overloading also do
not have namespace feature and reference variable
functionality.
C++ supports both function and operator overloading also
have namespace feature and reference variable functionality.

8
Differences Between C And C++
Header file used by C is stdio.h.
Header file used by C++ is iostream.h.

Virtual and friend functions are not supported by C.


Virtual and friend functions are supported by C++.

scanf() and printf() functions are used for input/output in C.


cin>> and cout<< are used for input/output in C++.

9
Differences Between C And C++
Namespace features are not present inside the C.
Namespace is used by C++, which avoid name collisions.

For instance, two students enrolled in the same university


cannot have the same roll number while two students in
different universities might have the same roll number. The
universities are two different namespace & hence contain the
same roll number(identifier) but the same university(one
namespace) cannot have two students with the same roll
number (identifier)
10
C++ program template
/*
* Comment to state the purpose of this program
(filename.cpp)
*/
#include <iostream>
using namespace std;

int main() {
// Your Programming statements HERE!

return 0;
}

11
First C++ program
// Simple C++ program

// Header file for input output functions


#include<iostream>
using namespace std;

int main()
{
cout<<"Welcome to C++ Programming";
cout<<endl;

return 0;
}

12
C++ Program Structure
#include <iostream>
using namespace std;
// main() is where program execution begins.
int main()
{
cout << "Hello World"; // prints Hello World
return 0;
}
Let us look various parts of the above program:
• The C++ language defines several headers, which contain information
that is either necessary or useful to your program. For this program,
the header <iostream> is needed.
• The line using namespace std; tells the compiler to use the std
namespace. Namespaces are a relatively recent addition to C++.
C++ Program Structure
• The next line // main() is where program execution begins. is a
single-line comment available in C++. Single-line comments begin
with // and stop at the end of the line.

• The line int main() is the main function where program execution
begins.

• The next line cout << "This is my first C++ program."; causes the
message "This is my first C++ program" to be displayed on the screen.

• The next line return 0; terminates main( )function and causes it to


return the value 0 to the calling process.
Object-Oriented Programming
• C++ provides capabilities for object-oriented programming.
• Objects are essentially reusable software components that model
items in the real world.
• Objects all have attributes (e.g., size, shape, color and weight), and
they all exhibit behaviors (e.g., a ball rolls, bounces, inflates and
deflates; a baby cries, sleeps, crawls, walks and blinks; a car
accelerates, brakes and turns; a towel absorbs water).
• Modular, object-oriented design and implementation makes
programmers much more productive than can previous popular
programming techniques.
• Object-oriented programs are easier to understand, correct and
modify.
Basic Object Technology Concepts
• Object-oriented design (OOD) models software in terms similar to
those that people use to describe real-world objects.
• Takes advantage of class relationships, where objects of a certain
class, have the same characteristics.
• Takes advantage of inheritance relationships, where new classes
of objects are derived by absorbing characteristics of existing
classes and adding unique characteristics of their own.
• Object-oriented design provides a natural and intuitive way to view
the software design process.
• OOD also models communication between objects.
Basic Object Technology Concepts
• OOD encapsulates attributes and operations into objects.
• Objects have the property of information hiding.
• Objects may know how to communicate with one another
across well-defined interfaces, but normally they’re not
allowed to know how other objects are implemented.
• Information hiding is crucial to good software engineering.
Basic Object Technology Concepts
• Languages like C++ are object oriented.
• Programming in such a language is called object-oriented
programming (OOP), and it allows computer programmers to
implement object-oriented designs as working software
systems.
• C++ classes contain functions that implement operations and
data that implements attributes.

You might also like