SlideShare a Scribd company logo
1 of 39
Unit I
Benefits of OOPs
1. Reduced complexity of a problem: The given problem can be viewed as a
collection of different objects. Each object is responsible for a specific task. The objects
of the system closely corresponds and relate in a one-to-one manner to the objects in
the real world.
2. Reusability: Once a class has been developed, implemented and tested, it can be
distributed to other programmers for use in their programs. Inheritance is considered
as an excellent way to organize abstraction and as a tool to support reuse.
3. Less Code redundancy: Through inheritance we can eliminate redundant code and
extend the use of existing classes.
4. Data Hiding: The programmer can hide the data and functions in a class from
other classes. It helps the programmer to build the secure programs. It is achieved by
restricting the members of class as private or protected.
5. Easy to Maintain and Upgrade: OOP makes it easy to maintain and modify
existing code as new objects can be created with small differences to existing ones.
Disadvantages of OOPs
1. Steep learning curve: The thought process involved in object-oriented programming
may not be natural for some people, and it can take time to get used to it.
2. Larger program size: Object-oriented programs typically involve more lines of code
than procedural programs.
3. Slower programs: Object-oriented programs are typically slower than procedure
based programs, as they typically require more instructions to be executed.
4. Not suitable for all types of problems: There are problems that lend themselves well
to functional-programming style, logic-programming style, or procedure-based
programming style, and applying object-oriented programming in those situations will
not result in efficient programs.
Applications of OOPs
The Object oriented approach of software design has been very successful for
applications other than engineering. The areas in which OOPs concepts can be
applied
1. Object Oriented databases
2. CAD and CAM
3. Decision Support and Office automation Systems.
4. Simulation and modeling
5. Distributed Computing and Applications
6. Web based Applications
7. User interface design such as windows, menu ,…
Difference between C and C++
C C++
C is a structural programming language. C++ is an object oriented programming
language.
Emphasis is on procedure or steps to
solve any problem.
Emphasis is on objects rather than
procedure.
Functions are the fundamental building
blocks.
Objects are the fundamental building
blocks.
In C, the data is not secured. Data is hidden and can’t be accessed by
external functions.
C follows top down approach. C++ follows bottom up approach
Variables must be defined at the
beginning in the function.
Variables can be defined anywhere in the
function.
In C, namespace feature is absent. In C++, namespace feature is present.
C doesn’t support exception handling
directly. Can be done by using some
other functions.
C++ supports exception handling. Done
by using try and catch block.
Features like function overloading and
operator overloading is not
present.
C++ supports function overloading and
operator overloading.
C++ Development Environment
To compile a C++ program , you need a C++ compiler. The compiler is a software,
which translates the source code to binary code.
Compilation Process
1. Preprocessor : The C++ preprocessor copies the contents of the included header
files into the source code file, generates macro code, and replaces symbolic constants
defined using #define with their values. The preprocessor also removes the comments.
2. Assembly code: The expanded source code file produced by the C++ preprocessor
is compiled into the assembly language for the platform.
3. Object Code: The assembler code generated by the compiler is assembled into the
object code for the platform.
4. Linker : The object code file generated by the assembler is linked together with the
object code files for any library functions used to produce an executable file.
C++ Language
C++ evolved from C. C++, an extension of C was developed by Bjarne Stroustrup
in the early 1980's at Bell Laboratories.
Earlier C++ was known as "C with Classes". The first complier for "C with Classes"
was called "Cfront".
In 1983 the name of the language was changed from "C with Classes" to "C++". The
++ operator in the C language is an operator for incrementing a variable.
In 1990 Borland's Turbo C++ compiler was released.
Currently there are two versions of C++ is available. The first is the traditional version
based on Stroustrup's originals designs. The second is Standard C++, which was
created by Stroustrup and the ANSI / ISO standardization committee.
The major difference between the two are : new style headers and namespace
International Organization for Standardization
American National Standards Institute
// Old Style
#include <iostream.h>
int main()
{
return 0;
}
// New Style
#include<iostream>
using namespace std;
int main()
{
return 0;
}
The new style headers do not specify the header filenames. Instead they simply
specify standard identifiers that may be mapped to files by the compiler
Namespace
Namespace is simply a declarative region. The purpose of a namespace is
to localize the names of identifiers to avoid name collisions.
Standardization of C++
From 1983 to 1998 C++ was developed by Bjarne Stroustrup in Bell Labs.
In 1998, the ISO working group standardized C++ for the first time and it is known
as C++98. After that four new standards were released in 2003, 2007, 2011
and 2014. The 2014 release is known as C++14. Currently, the work is going on
for the next release in 2017.
The C++ Programming Language was the first book to describe C++, it was
written by Bjarne Stroustrup and till the standardization of C++ in 1998. This
book remained the de facto of C++.
First edition published in 1985
Second edition published in 1991
Third edition published in 1997 and 2000
Fourth edition published in 2013, which incorporates the C++11.
Compilers for C++
1. Turbo C++ / Borland C++
Borland is a company that created the most successful compiler for C++ in late
90's. Turbo C++ was an 16 bit application which ran on DOS. Turbo C++ comes
with an IDE.
Four versions of Turbo C++ was introduced from 1990 to 1994. After the ver 3.0
Turbo C++, Borland segmented their C++ compiler into two product lines:
Turbo C++ and Borland C++. Turbo C++ was for hobbyist and Borland C++ was
for professionals.
The original Turbo C++ was put on hold after 1994. In 2006, again Turbo C++
was released in two variants "Explorer" and "Professional". In 2008 Borland sold
its compiler division to "Embarcadero Technologies" and in 2009 Embarcadero
discontinued the Turbo C++ 2006.
Borland C++ was continued till version 5.02 (1997). After 1997, the Borland
started work on C++ Builder Series. Today Borland C++ 5.5 (Command Line only)
is available for download from the Embarcadero website. The C++ Builder latest
version XE8 (22) is available for download from the Embarcadero Website.
2. DOSBox
TurboC++ ver3.0 / BorlandC++ ver 3.0 are 16 bit compilers, which can run only
on legacy systems like windows 98 and windows XP. To run the ver3.0 compilers
on windows 7 and windows 8, we need to install the DosBox (emulator program
that emulates the environment of DOS windows 7 and 8).
First , install DosBox and then install Turbo C+9 or Borland C++ ver 3.0 on it.
You can also install other old Dos based software in DOSBox
3. GNU Compiler Collection (GCC)
GNU (General Public License) Project is a free software, mass collaboration project
started in 1983 at MIT. GCC is a compiler system produced by the GNU project
supporting various programming languages.
GCC ver 1.0 was released in 1987, originally only for language C. Extended in same
for C++. Later the support for Java, Fortran, Ada and Go was added.
The standard compiler releases since 4.6 include front ends for C (gcc), C++ (g++)
and Java (gcj).
The latest version is 5.2.0 released on July 2015.
4. MinGw
It is an open source development environment targeting Microsoft windows application.
It includes a port of the GNU Compiler Collection (GCC). Using MinGw the
compiler for C, C++, Java and other languages can be downloaded and it uses
the GCC in background.
5. CODEBLOCKS
Code Blocks is a free C, C++ and Fortran IDE built to meet the most demanding
needs of its users. It is designed to be very extensible and fully configurable. It can
use GCC, Borland C++ 5.5, MSVC ++ etc to compile the programs.
6. Dev C++
Bloodshed Dev-C++ is a full-featured Integrated Development Environment
(IDE) for the C/C++ programming language. It uses Mingw port of GCC (GNU
Compiler Collection) as it's compiler. Dev-C++ can also be used in combination
with Cygwin or any other GCC based compiler.
7. MS VC++
It is an C++ compiler available from Microsoft. It is available for both 32 bit and 64 bit.
It provides a very easy to use IDE on windows machine. The latest one is
VC ++ 2015.
S.N
o
Compiler Company Paid /
Free
Platfor
m
IDE C++11
1 C++
Builder
Embarcader
o
Paid Win, OS
X,
Yes No ( via
Clang)
2 Borland
C++ 5.5
Borland /
Embarcader
Free Win Command
Line
No
3 GCC GNU
Project
Free Win,
Unix
Code
Blocks, Net
Beans
Yes
4 Visual C++ Microsoft Paid Window
s
Yes Partial
5 MinGw Under GNU Free Window
s
No Yes
6 Dev C++ BloodShed /
Orwell
Free Window
s
Yes Yes
7 CodeBlock CodeBlock Free Win,
Linux
Yes Yes
C++ Standard Libraries
In the C++ programming language, the C++ Standard Library is a collection of
classes and functions, which are written in the core language and part of the C++
ISO Standard itself.
The C++ Standard Library provides several generic containers, functions to utilize
and manipulate these containers.
Example of Containers:
<array>
<list>
<map>
<queue>
The C++ Standard Library is based upon conventions introduced by the Standard
Template Library (STL), and has been influenced by research in generic
programming
C++ Standard Libraries
In old C++ style header files are included with the extension of .h , but in new
standard style .h extension is removed. Also the C header files like stdio.h , string.h
are written as cstdio and cstring.
The facilities of the standard library are defined in the std namespace and presented
as a set of headers. Below is the brief list of header files given on the basis of
functionality.
Container : <vector> <map> <set> <deque> <list> etc
General Utilities : <ctime> <iterator> <memory>
Diagnostics : <exception> <stdexcept> <cassert>
String and Character : <string> <cstring> <cstdlin> <cctype>
Input / Output : <iostream> <ostream> <iomanip>
Localization : <locale> <clocale>
Language Support : <limits> <new> <ctime>
Important Points about new C++ Standard
1. The main only returns int value.
2. Use "system("cls")" instead of clrscr() in Dev C++ and CodeBlock. In CodeBlock
include <cstdlib> to use system(cls).
3. Use "system("pause") instead of getch() in both Dev C++ and Code Block.
In Code Block we can also use to "cin.get()"
Moving from C to C++
#include <iostream.h>
#include <conio.h>
void main()
{
cout<<"Hello World";
}
1. Output Streams
Output on the standard stream is performed using the cout object.
Cout<<"Hello World".
The word cout is followed by the symbol <<, called the insertion or put-to operator.
Cout << variablename << variablename;
2. Input Stream
void main()
{
char name[25];
int age;
cout<<"Enter name";
cin>>name;
cout<<"Enter age";
cin>>age;
cout<<"Details are "<<endl;
cout<"Name = "<<name <<endl;
cout<<"Age = " <<age<<endl;
}
Write a program to calculate simple interest and Total amount
#include<iostream.h>
void main()
{
int principle,time,rate,si,total;
cout<<"Enter prinicipal";
cin>>principle;
cout<<"Enter Time(in years)";
cin>>time;
cout<<"Enter rate of interest";
cin>>rate;
si = (principle * time * rate ) / 100;
cout<<"Simple Interest = ";
cout<<si;
total = principle + si;
cout<<"Total amount = ";
cout<<total;
}
3. How to declare constants
const [DataType] variablename = constantvalue
e.g.
const float PI = 3.1452;
const int TRUE = 1;
const int FALSE = 0;
Write a program to calculate the area of circle
We cannot change the value of constant variable and the value of constant
value is treated as read only.
#inlcude<iostream.h>
const float PI = 3.1452;
void main()
{
float radius;
float area;
cout<<"Enter radius of circle";
cin>>radius;
area = PI * radius * radius;
cout<<"Area of circle = " <<area;
}
4. Scope Resolution Operator ::
To access a global variable from a function in which a local variable is defined
with the same name as global variable. It it achieved using the scope resolution
operator.
#inlcude<iostream.h>
int num = 20;
void main()
{
int num = 10;
cout<<"Local = "<<num;
cout<<"n Global = "<< ::num;
}
5. Variable definition at the point of use
In C local variable can only be defined at the top of a function. In C++ local variable
can be defined at any position in the code.
#include <iostream.h>
int main()
{
for(int i = 0; i<5;i++)
{
cout<<i<<endl;
}
cout<<i;
return 0;
}
#include <iostream.h>
int a = 10;
void main()
{
cout<<a <<endl;
int a = 20;
{
int a = 30;
cout<<a<<endl;
cout<<::a<<endl;
}
cout<<a<<endl;
cout<<::a<<endl;
}
6. Variable Aliases - Reference variables
In addition to value variable and pointer variable of C. C++ also supports the
reference variable. It acts as an alias for the other value variable. It does not
provide the flexibility supported by the pointer variable. When a reference is
bound to a variable, then its binding cannot be changed.
Syntax:
DataType & ReferenceVariable = ValueVariable;
#include <iostream.h>
void main()
{
int a =1, b = 2;
int &z = a;
cout<<" a = " <<a << " b = " << b<< "z = " <<z <<endl;
z = b;
cout<<" a = " <<a << " b = " << b<< "z = " <<z <<endl;
cout<<" &a = " <<&a << " &b = " << &b<< "&z = " <<&z
<<endl;
}
7. Strict Type Checking
C++ is a strongly typed language and it uses very strict type checking. A prototype
must be known for each function which is called and the call must match the
prototype. In C++ function prototyping is compulsory whereas in C it is optional.
#include <iostream.h>
int main()
{
int x,y;
cout<<"Enter two numbers";
cin>>x>>y;
cout<<"Maxium = " <<max(x,y); // Compile time Error
return o;
}
int max(int a, int b)
{
if (a >b)
return a;
else
return b;
}
8. Passing of Parameters by Reference
#include <iostream.h>
void swap (int & x, int &y)
{
int t;
t = x;
x=y;
y=t;
}
void main()
{
int a,b;
cout<<"Enter two integers";
cin>>a>>b;
swap(a,b);
cout<<"On swapping the numbers " << a << b;
}
9. Inline Functions
Function execution involves the overhead of jumping to and from the calling
statement. When functions are small in size this overhead is unnecessary. So to
avoid this overhead, we can use inline functions which are treated as macros.
The function body is substituted at the point of inline function call.
#inlcude <iostream.h>
inline float square(float x)
{
return x*x;
}
void main()
{
float no;
cout<<"Enter the number ";
cin>>no;
cout<<"Its square is "<<square(no);
}
10. Function Overloading
In C++ two or more functions can be given the same name provided each has a
unique signature ( in either the number or data type of their arguments).
#include <iostream.h>
void print(int i) {
cout << "Printing int: " << i << endl;
}
void print(char*c) {
cout << "Printing character: " << c << endl;
}
void print () {
cout<<"Empty print method";
}
void main()
{
print(5);
print("Hello C++");
print();
}
11. Default Argument
In C++, the function can take default values if the values are not provided during the
function call.
#inlcude <iostream.h>
void showstring(char *str = "Hello World")
{
cout<<str;
}
int main()
{
showstring("function call with arguments");
showstring();
retrun 0;
}
12. Functions as a Part of Struct
Like C structures, C++ structures also provide a mechanism to group different data
types. In addition to it also allows to associate functions as a part of structure.
struct StructName
{
public :
// data and functions
private:
/ / data and functions
protected:
// data and functions
}
All the data and functions are public by default.
13. Runtime Memory Management
The memory management functions such as malloc(), calloc() and free() in C, have
been improved and evolved in C++ with the new and delete operators.
int *a = new int [100]; // In C++
int *a = (int *) malloc (sizeof (int) * 100);

More Related Content

What's hot

Evolution of programming language
Evolution of programming languageEvolution of programming language
Evolution of programming languageSameer Saini
 
Comparison between python and c++
Comparison between python and c++Comparison between python and c++
Comparison between python and c++ssusera7faf41
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeSAFAD ISMAIL
 
C language myths & secrets
C language myths & secretsC language myths & secrets
C language myths & secretsankush1510
 
Training report of C language
Training report of C languageTraining report of C language
Training report of C languageShashank Kapoor
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++KAUSHAL KUMAR JHA
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Abou Bakr Ashraf
 
1 introduction to c programming language
1 introduction to c programming language1 introduction to c programming language
1 introduction to c programming languageNarendra Soni
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYRajeshkumar Reddy
 

What's hot (19)

Evolution of programming language
Evolution of programming languageEvolution of programming language
Evolution of programming language
 
Introduction to C# Programming
Introduction to C# ProgrammingIntroduction to C# Programming
Introduction to C# Programming
 
Comparison between python and c++
Comparison between python and c++Comparison between python and c++
Comparison between python and c++
 
C++ language
C++ languageC++ language
C++ language
 
IP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG ProgrammeIP Lab Manual for Kerala University 3 Year UG Programme
IP Lab Manual for Kerala University 3 Year UG Programme
 
Programming with c#
Programming with c#Programming with c#
Programming with c#
 
History of c#
History of c#History of c#
History of c#
 
Dot net
Dot netDot net
Dot net
 
C language myths & secrets
C language myths & secretsC language myths & secrets
C language myths & secrets
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
Training report of C language
Training report of C languageTraining report of C language
Training report of C language
 
T2
T2T2
T2
 
Characteristics of c#
Characteristics of c#Characteristics of c#
Characteristics of c#
 
Part 1
Part 1Part 1
Part 1
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
 
Visula C# Programming Lecture 1
Visula C# Programming Lecture 1Visula C# Programming Lecture 1
Visula C# Programming Lecture 1
 
1 introduction to c programming language
1 introduction to c programming language1 introduction to c programming language
1 introduction to c programming language
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDY
 
C compiler-ide
C compiler-ideC compiler-ide
C compiler-ide
 

Viewers also liked

SSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In HindiSSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In Hindikusumafoundation
 
Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented languagefarhan amjad
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesGuido Wachsmuth
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingHaris Bin Zahid
 
Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Saurabh Singh Negi
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Languagedheva B
 
हिन्दी व्याकरण
हिन्दी व्याकरणहिन्दी व्याकरण
हिन्दी व्याकरणChintan Patel
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programmingNgeam Soly
 
OOPs concept and implementation
OOPs concept and implementationOOPs concept and implementation
OOPs concept and implementationSandeep Kumar P K
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic Manzoor ALam
 
Vakya parichay
Vakya parichayVakya parichay
Vakya parichaysonia -
 

Viewers also liked (20)

Labsheet2
Labsheet2Labsheet2
Labsheet2
 
SSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In HindiSSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In Hindi
 
Oops
OopsOops
Oops
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Oops Concepts
Oops ConceptsOops Concepts
Oops Concepts
 
Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented language
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
हिन्दी व्याकरण
हिन्दी व्याकरणहिन्दी व्याकरण
हिन्दी व्याकरण
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
 
OOPs concept and implementation
OOPs concept and implementationOOPs concept and implementation
OOPs concept and implementation
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
कारक
कारककारक
कारक
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Vakya parichay
Vakya parichayVakya parichay
Vakya parichay
 

Similar to Unit i

Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++Manoj Kumar
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...bhargavi804095
 
Summer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxSummer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxshokeenk14
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocksTech Bikram
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitcbenDesigning
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
C++ language basic
C++ language basicC++ language basic
C++ language basicWaqar Younis
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Shujaat Abbas
 

Similar to Unit i (20)

Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 
Session 1 - c++ intro
Session   1 - c++ introSession   1 - c++ intro
Session 1 - c++ intro
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
C++ was developed by Bjarne Stroustrup, as an extension to the C language. cp...
 
Summer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxSummer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptx
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Programming in c plus plus2
Programming in c plus plus2Programming in c plus plus2
Programming in c plus plus2
 
basics of c++
basics of c++basics of c++
basics of c++
 
basics of c++
basics of c++basics of c++
basics of c++
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 

Unit i

  • 2. Benefits of OOPs 1. Reduced complexity of a problem: The given problem can be viewed as a collection of different objects. Each object is responsible for a specific task. The objects of the system closely corresponds and relate in a one-to-one manner to the objects in the real world. 2. Reusability: Once a class has been developed, implemented and tested, it can be distributed to other programmers for use in their programs. Inheritance is considered as an excellent way to organize abstraction and as a tool to support reuse. 3. Less Code redundancy: Through inheritance we can eliminate redundant code and extend the use of existing classes. 4. Data Hiding: The programmer can hide the data and functions in a class from other classes. It helps the programmer to build the secure programs. It is achieved by restricting the members of class as private or protected. 5. Easy to Maintain and Upgrade: OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
  • 3. Disadvantages of OOPs 1. Steep learning curve: The thought process involved in object-oriented programming may not be natural for some people, and it can take time to get used to it. 2. Larger program size: Object-oriented programs typically involve more lines of code than procedural programs. 3. Slower programs: Object-oriented programs are typically slower than procedure based programs, as they typically require more instructions to be executed. 4. Not suitable for all types of problems: There are problems that lend themselves well to functional-programming style, logic-programming style, or procedure-based programming style, and applying object-oriented programming in those situations will not result in efficient programs.
  • 4. Applications of OOPs The Object oriented approach of software design has been very successful for applications other than engineering. The areas in which OOPs concepts can be applied 1. Object Oriented databases 2. CAD and CAM 3. Decision Support and Office automation Systems. 4. Simulation and modeling 5. Distributed Computing and Applications 6. Web based Applications 7. User interface design such as windows, menu ,…
  • 5. Difference between C and C++ C C++ C is a structural programming language. C++ is an object oriented programming language. Emphasis is on procedure or steps to solve any problem. Emphasis is on objects rather than procedure. Functions are the fundamental building blocks. Objects are the fundamental building blocks. In C, the data is not secured. Data is hidden and can’t be accessed by external functions. C follows top down approach. C++ follows bottom up approach Variables must be defined at the beginning in the function. Variables can be defined anywhere in the function. In C, namespace feature is absent. In C++, namespace feature is present. C doesn’t support exception handling directly. Can be done by using some other functions. C++ supports exception handling. Done by using try and catch block. Features like function overloading and operator overloading is not present. C++ supports function overloading and operator overloading.
  • 6. C++ Development Environment To compile a C++ program , you need a C++ compiler. The compiler is a software, which translates the source code to binary code.
  • 8. 1. Preprocessor : The C++ preprocessor copies the contents of the included header files into the source code file, generates macro code, and replaces symbolic constants defined using #define with their values. The preprocessor also removes the comments. 2. Assembly code: The expanded source code file produced by the C++ preprocessor is compiled into the assembly language for the platform. 3. Object Code: The assembler code generated by the compiler is assembled into the object code for the platform. 4. Linker : The object code file generated by the assembler is linked together with the object code files for any library functions used to produce an executable file.
  • 9.
  • 10. C++ Language C++ evolved from C. C++, an extension of C was developed by Bjarne Stroustrup in the early 1980's at Bell Laboratories. Earlier C++ was known as "C with Classes". The first complier for "C with Classes" was called "Cfront". In 1983 the name of the language was changed from "C with Classes" to "C++". The ++ operator in the C language is an operator for incrementing a variable. In 1990 Borland's Turbo C++ compiler was released. Currently there are two versions of C++ is available. The first is the traditional version based on Stroustrup's originals designs. The second is Standard C++, which was created by Stroustrup and the ANSI / ISO standardization committee. The major difference between the two are : new style headers and namespace International Organization for Standardization American National Standards Institute
  • 11. // Old Style #include <iostream.h> int main() { return 0; } // New Style #include<iostream> using namespace std; int main() { return 0; } The new style headers do not specify the header filenames. Instead they simply specify standard identifiers that may be mapped to files by the compiler Namespace Namespace is simply a declarative region. The purpose of a namespace is to localize the names of identifiers to avoid name collisions.
  • 12. Standardization of C++ From 1983 to 1998 C++ was developed by Bjarne Stroustrup in Bell Labs. In 1998, the ISO working group standardized C++ for the first time and it is known as C++98. After that four new standards were released in 2003, 2007, 2011 and 2014. The 2014 release is known as C++14. Currently, the work is going on for the next release in 2017. The C++ Programming Language was the first book to describe C++, it was written by Bjarne Stroustrup and till the standardization of C++ in 1998. This book remained the de facto of C++. First edition published in 1985 Second edition published in 1991 Third edition published in 1997 and 2000 Fourth edition published in 2013, which incorporates the C++11.
  • 13. Compilers for C++ 1. Turbo C++ / Borland C++ Borland is a company that created the most successful compiler for C++ in late 90's. Turbo C++ was an 16 bit application which ran on DOS. Turbo C++ comes with an IDE. Four versions of Turbo C++ was introduced from 1990 to 1994. After the ver 3.0 Turbo C++, Borland segmented their C++ compiler into two product lines: Turbo C++ and Borland C++. Turbo C++ was for hobbyist and Borland C++ was for professionals. The original Turbo C++ was put on hold after 1994. In 2006, again Turbo C++ was released in two variants "Explorer" and "Professional". In 2008 Borland sold its compiler division to "Embarcadero Technologies" and in 2009 Embarcadero discontinued the Turbo C++ 2006. Borland C++ was continued till version 5.02 (1997). After 1997, the Borland started work on C++ Builder Series. Today Borland C++ 5.5 (Command Line only) is available for download from the Embarcadero website. The C++ Builder latest version XE8 (22) is available for download from the Embarcadero Website.
  • 14. 2. DOSBox TurboC++ ver3.0 / BorlandC++ ver 3.0 are 16 bit compilers, which can run only on legacy systems like windows 98 and windows XP. To run the ver3.0 compilers on windows 7 and windows 8, we need to install the DosBox (emulator program that emulates the environment of DOS windows 7 and 8). First , install DosBox and then install Turbo C+9 or Borland C++ ver 3.0 on it. You can also install other old Dos based software in DOSBox
  • 15. 3. GNU Compiler Collection (GCC) GNU (General Public License) Project is a free software, mass collaboration project started in 1983 at MIT. GCC is a compiler system produced by the GNU project supporting various programming languages. GCC ver 1.0 was released in 1987, originally only for language C. Extended in same for C++. Later the support for Java, Fortran, Ada and Go was added. The standard compiler releases since 4.6 include front ends for C (gcc), C++ (g++) and Java (gcj). The latest version is 5.2.0 released on July 2015. 4. MinGw It is an open source development environment targeting Microsoft windows application. It includes a port of the GNU Compiler Collection (GCC). Using MinGw the compiler for C, C++, Java and other languages can be downloaded and it uses the GCC in background.
  • 16. 5. CODEBLOCKS Code Blocks is a free C, C++ and Fortran IDE built to meet the most demanding needs of its users. It is designed to be very extensible and fully configurable. It can use GCC, Borland C++ 5.5, MSVC ++ etc to compile the programs. 6. Dev C++ Bloodshed Dev-C++ is a full-featured Integrated Development Environment (IDE) for the C/C++ programming language. It uses Mingw port of GCC (GNU Compiler Collection) as it's compiler. Dev-C++ can also be used in combination with Cygwin or any other GCC based compiler. 7. MS VC++ It is an C++ compiler available from Microsoft. It is available for both 32 bit and 64 bit. It provides a very easy to use IDE on windows machine. The latest one is VC ++ 2015.
  • 17. S.N o Compiler Company Paid / Free Platfor m IDE C++11 1 C++ Builder Embarcader o Paid Win, OS X, Yes No ( via Clang) 2 Borland C++ 5.5 Borland / Embarcader Free Win Command Line No 3 GCC GNU Project Free Win, Unix Code Blocks, Net Beans Yes 4 Visual C++ Microsoft Paid Window s Yes Partial 5 MinGw Under GNU Free Window s No Yes 6 Dev C++ BloodShed / Orwell Free Window s Yes Yes 7 CodeBlock CodeBlock Free Win, Linux Yes Yes
  • 18. C++ Standard Libraries In the C++ programming language, the C++ Standard Library is a collection of classes and functions, which are written in the core language and part of the C++ ISO Standard itself. The C++ Standard Library provides several generic containers, functions to utilize and manipulate these containers. Example of Containers: <array> <list> <map> <queue> The C++ Standard Library is based upon conventions introduced by the Standard Template Library (STL), and has been influenced by research in generic programming
  • 19. C++ Standard Libraries In old C++ style header files are included with the extension of .h , but in new standard style .h extension is removed. Also the C header files like stdio.h , string.h are written as cstdio and cstring. The facilities of the standard library are defined in the std namespace and presented as a set of headers. Below is the brief list of header files given on the basis of functionality. Container : <vector> <map> <set> <deque> <list> etc General Utilities : <ctime> <iterator> <memory> Diagnostics : <exception> <stdexcept> <cassert> String and Character : <string> <cstring> <cstdlin> <cctype> Input / Output : <iostream> <ostream> <iomanip> Localization : <locale> <clocale> Language Support : <limits> <new> <ctime>
  • 20. Important Points about new C++ Standard 1. The main only returns int value. 2. Use "system("cls")" instead of clrscr() in Dev C++ and CodeBlock. In CodeBlock include <cstdlib> to use system(cls). 3. Use "system("pause") instead of getch() in both Dev C++ and Code Block. In Code Block we can also use to "cin.get()"
  • 21. Moving from C to C++ #include <iostream.h> #include <conio.h> void main() { cout<<"Hello World"; }
  • 22. 1. Output Streams Output on the standard stream is performed using the cout object. Cout<<"Hello World". The word cout is followed by the symbol <<, called the insertion or put-to operator. Cout << variablename << variablename;
  • 23. 2. Input Stream void main() { char name[25]; int age; cout<<"Enter name"; cin>>name; cout<<"Enter age"; cin>>age; cout<<"Details are "<<endl; cout<"Name = "<<name <<endl; cout<<"Age = " <<age<<endl; }
  • 24. Write a program to calculate simple interest and Total amount
  • 25. #include<iostream.h> void main() { int principle,time,rate,si,total; cout<<"Enter prinicipal"; cin>>principle; cout<<"Enter Time(in years)"; cin>>time; cout<<"Enter rate of interest"; cin>>rate; si = (principle * time * rate ) / 100; cout<<"Simple Interest = "; cout<<si; total = principle + si; cout<<"Total amount = "; cout<<total; }
  • 26. 3. How to declare constants const [DataType] variablename = constantvalue e.g. const float PI = 3.1452; const int TRUE = 1; const int FALSE = 0; Write a program to calculate the area of circle We cannot change the value of constant variable and the value of constant value is treated as read only.
  • 27. #inlcude<iostream.h> const float PI = 3.1452; void main() { float radius; float area; cout<<"Enter radius of circle"; cin>>radius; area = PI * radius * radius; cout<<"Area of circle = " <<area; }
  • 28. 4. Scope Resolution Operator :: To access a global variable from a function in which a local variable is defined with the same name as global variable. It it achieved using the scope resolution operator. #inlcude<iostream.h> int num = 20; void main() { int num = 10; cout<<"Local = "<<num; cout<<"n Global = "<< ::num; }
  • 29. 5. Variable definition at the point of use In C local variable can only be defined at the top of a function. In C++ local variable can be defined at any position in the code. #include <iostream.h> int main() { for(int i = 0; i<5;i++) { cout<<i<<endl; } cout<<i; return 0; }
  • 30. #include <iostream.h> int a = 10; void main() { cout<<a <<endl; int a = 20; { int a = 30; cout<<a<<endl; cout<<::a<<endl; } cout<<a<<endl; cout<<::a<<endl; }
  • 31. 6. Variable Aliases - Reference variables In addition to value variable and pointer variable of C. C++ also supports the reference variable. It acts as an alias for the other value variable. It does not provide the flexibility supported by the pointer variable. When a reference is bound to a variable, then its binding cannot be changed. Syntax: DataType & ReferenceVariable = ValueVariable;
  • 32. #include <iostream.h> void main() { int a =1, b = 2; int &z = a; cout<<" a = " <<a << " b = " << b<< "z = " <<z <<endl; z = b; cout<<" a = " <<a << " b = " << b<< "z = " <<z <<endl; cout<<" &a = " <<&a << " &b = " << &b<< "&z = " <<&z <<endl; }
  • 33. 7. Strict Type Checking C++ is a strongly typed language and it uses very strict type checking. A prototype must be known for each function which is called and the call must match the prototype. In C++ function prototyping is compulsory whereas in C it is optional. #include <iostream.h> int main() { int x,y; cout<<"Enter two numbers"; cin>>x>>y; cout<<"Maxium = " <<max(x,y); // Compile time Error return o; } int max(int a, int b) { if (a >b) return a; else return b; }
  • 34. 8. Passing of Parameters by Reference #include <iostream.h> void swap (int & x, int &y) { int t; t = x; x=y; y=t; } void main() { int a,b; cout<<"Enter two integers"; cin>>a>>b; swap(a,b); cout<<"On swapping the numbers " << a << b; }
  • 35. 9. Inline Functions Function execution involves the overhead of jumping to and from the calling statement. When functions are small in size this overhead is unnecessary. So to avoid this overhead, we can use inline functions which are treated as macros. The function body is substituted at the point of inline function call. #inlcude <iostream.h> inline float square(float x) { return x*x; } void main() { float no; cout<<"Enter the number "; cin>>no; cout<<"Its square is "<<square(no); }
  • 36. 10. Function Overloading In C++ two or more functions can be given the same name provided each has a unique signature ( in either the number or data type of their arguments). #include <iostream.h> void print(int i) { cout << "Printing int: " << i << endl; } void print(char*c) { cout << "Printing character: " << c << endl; } void print () { cout<<"Empty print method"; } void main() { print(5); print("Hello C++"); print(); }
  • 37. 11. Default Argument In C++, the function can take default values if the values are not provided during the function call. #inlcude <iostream.h> void showstring(char *str = "Hello World") { cout<<str; } int main() { showstring("function call with arguments"); showstring(); retrun 0; }
  • 38. 12. Functions as a Part of Struct Like C structures, C++ structures also provide a mechanism to group different data types. In addition to it also allows to associate functions as a part of structure. struct StructName { public : // data and functions private: / / data and functions protected: // data and functions } All the data and functions are public by default.
  • 39. 13. Runtime Memory Management The memory management functions such as malloc(), calloc() and free() in C, have been improved and evolved in C++ with the new and delete operators. int *a = new int [100]; // In C++ int *a = (int *) malloc (sizeof (int) * 100);