• Introduction toC
• C Statements
• Operators in C
• Functions in C
• C Arrays
• Pointers in C
• File Handling in C
Content
• Introduction to C++
• Class & Object
• Constructors & Destructors
• Encapsulation in C++
• Polymorphism in C++
• Inheritance in C++
3.
• Any personwants to become a software professional must start with C.
• C is the only language having capability of transforming a inexperienced person into a software
professional.
• To communicate with others, we use human languages like English, Hindi, etc.
• Similarly, to communicate with computers, we should use computer languages like C.
• PROGRAM
• INPUT: OUTPUT:
• #include <stdio.h> Hello, World!
• int main() {
• printf("Hello, World!");
• return 0;
• }
Introduction to C
4.
• There aretwo types of Statements: Input Statements & Output Statements.
• The data given to a program is called Input.
• The result given by the program is called Output.
• In writing any statements, functions generally used.
• Input and Output statements are also a function ( scanf(),printf() etc).
C Statements
5.
• To displayuseful results and reports, we need to perform operations on data. This is achieved by
operators.
• We can define an operator as a symbol that can perform some operation. An operator acts on variables,
called operands.
Operators in C
Operator Category Operator symbols
Arithmetic Operators +,-,*,/,%
Assignment Operators += , -=, *=, /=, %=, =
Unary Operators -, ++, —
Ternary Operators ?:
Relational Operators <, <=, >, >=, ==, !=
Logical Operators &&, ||, !
Bitwise Operators -, &, |, ^, <<, >>
Miscellaneous Operators sizeof(), &, *,,
6.
• Writing aprogram is to solve a given Task.
• A Task is given to the programmer and he should divide the main task into sub-tasks.
• To represent the main Task and the sub Tasks, a separate pieces of code is written, which
is known as function.
• Main Task is represented by main() function and the sub Tasks are represented by other
functions.
• C program is nothing but a group of functions.
• A function represents a group of statements that performs a specific Task.
Functions in C
7.
• An arrayis a collection of elements of the same type that are referenced by a
common name.
• Compared to the basic data type (int, float & char) it is an aggregate or derived
data type.
• All the elements of an array occupy a set of contiguous memory locations.
• Why need to use array type?
• Consider the following issue:
C Arrays
“We have a list of 100 students’ marks of an
integer type. If using the basic data type ( int ) ,
we will declare something like the following…”
int studMark0, studMark1, studMark2, …, studMark99;
8.
• A pointeris useful to store the memory address of the variable.
• To declare a pointer, we should use * symbol before the name of the pointer.
• To store the address of the variable in the pointer, we can use ‘address of’ operator.
• To retrieve the value of the variable through pointer, we can use ‘value at’ or ‘indirection’
operator (*).
Pointers in C
int *x, *ptr;
char *name;
x = &v; /* store the address of v into x */
name = &empname; /* store address of employee name into name */
*x; /* gives the value at the variable referenced by x */
*name; /* gives the value at the variable referenced by name */
9.
• File handlingin C enables us to create, update, read and delete the files stored
on the local file system through our C program.
• The following operations can be performed on a file:
★ Creation of the new file
★ Opening an existing file
★ Reading from the file
★ Writing to the file
★ Deleting the file
File Handling in C
fopen()
fscanf(), fgetc(), fgetw()
fprintf(), fputc(), fputw()
10.
• C++ isa cross-platform language that can be used to create high-performance applications.
• It was developed by Bjarne Stroustrup, as an extension to the C language.
• The language was updated 3 major times in 2011, 2014, and 2017 to C++11, C++14, and C+
+17.
Why Use C++?
1. C++ is one of the world’s most popular programming language.
2. C++ can be found in today’s operating systems, Graphical User Interfaces, and
embedded systems.
3. C++ is an object-oriented programming language which gives a clear structure to
programs and allows code to be reused, lowering development costs.
Introduction to C++
11.
• The buildingblock of C++ that leads to Object Oriented programming is a Class.
• A Class is a user defined data-type which has data members and member
functions.
• An Object is an instance of a Class. When a class is defined, no memory is
allocated but when it is instantiated (i.e. an object is created) memory is
allocated.
• A class is like a blueprint for an object.
Class & Object
12.
• The constructorfunction is responsible for creation of object.
• There is no need to write any statement to invoke the constructor function.
• If a ‘normal’ member function is defined for initialisation, we need to invoke that
function for each and every objects separately.
• A destructor is used to destroy the objects that have been created by a constructor.
• Like constructor, the destructor is a member function whose name is the same as the
class name but is preceded by a tilde.
eg: ~integer() { }
• A destructor never takes any argument nor does it return any value.
Constructors & Destructors
13.
• The object-orientedmeaning of encapsulation is to enclose related data, routines
and definitions in a class capsule. This does not necessarily mean hiding.
• Encapsulation is the ‘bundling together’ of data and behaviour so that they are
inseparable.
• Encapsulation (also called information hiding) consists of separating the external
aspects of an object, from the internal implementation details of the object,
which are hidden from other objects.
• Encapsulation prevents a program from becoming to interdependent that a small
change has massive ripple effects.
Encapsulation in C++
14.
• The processof representing one Form in multiple forms is known as
Polymorphism. Here one form represent original form or original method always
resides in base class and multiple forms represents overriden method which
resides in derived classes.
• Polymorphism is derived from 2 Greek words: poly and morphs. The word “poly”
means many and morphs means forms. So polymorphism means many forms.
• Suppose if you are in class room that time you behave like a student, when you
are in market that time you behave like customer, when you at your home at that
time you behave like a son or daughter, Here one person have different-different
behaviours.
Polymorphism in C++
Real life example of Polymorphism in C++
15.
• The capabilityof a class to derive properties and characteristics from another
class is called Inheritance.
• Inheritance is one of the most important feature of Object Oriented
Programming.
• Sub Class: The class that inherits properties from another class is called Sub class
or Derived Class.
• Super Class: The class whose properties are inherited by sub class is called Base
Class or Super class.
Inheritance in C++