SlideShare una empresa de Scribd logo
1 de 65
Descargar para leer sin conexión
INTRODUCTION TO C++
Prof. K ADISESHA (Ph. D)
INTRODUCTION TO
C++
PROGRAMMING
introduction
Characteristics of C++
C++ Character Set
C++ Tokens
Data Types of C++
2
C++ PROGRAMMING
Prof. K. Adisesha (Ph. D)
I/O Operators of C++
Introduction
Prof. K. Adisesha (Ph. D)
3
History of C++:
The C++ programming language was created by Bjarne Stroustrup and his team at
Bell Laboratories (AT&T, USA) to help implement simulation projects in an object-
oriented and efficient way.
➢ C++ is a superset of C because; any valid C program is valid C++ program too but not
the vice versa is not true.
➢ C++ can make use of existing C software libraries with major addition of “Class
Construct”.
➢ This language was called “C with classes” and later in 1983, it was named “C++” by
Rick Mascitii. As the name C++ implies, C++ was derived from the C programming
language: ++ is the increment operator in C.
Introduction
Prof. K. Adisesha (Ph. D)
4
OOPs characteristics
➢ Modularity: Module is a logically self-contained unit that can be tested and executed independently.
➢ Abstraction: It represents the essential features of an entity without including explanations or any
background details about it.
➢ Data Encapsulation: Wrapping of data and functions into a single unit is called data encapsulation.
➢ Inheritance: The process by which objects of one class acquires the properties of the objects of
another class.
➢ Polymorphism: The ability for a message to be processed in more than one form.
➢ Dynamic Binding: Linking of a procedure call to the code to be executed when it is called.
➢ Message Passing: Passing message objects and invoking the function by the object by sending a
message is known as message passing.
Introduction
Prof. K. Adisesha (Ph. D)
5
OOPs Benefits
➢ OOPs model the real world entity very well.
➢ Inheritance eliminates the redundancy (repetition) of code and hence supports code
reusability.
➢ Data hiding helps to build secured programs.
➢ Multiple instances (objects) can be created.
➢ Work can be divided easily.
➢ OOPs can be easily upgraded from small to large systems.
➢ Complexity can be easily managed.
➢ Message passing concept helps the objects to communicate and share data.
Introduction
Prof. K. Adisesha (Ph. D)
6
OOPs Applications
➢ Object oriented databases.
➢ Hypermedia, expert text and hypertext.
➢ Artificial intelligence and expert systems.
➢ Decision support systems and office automation systems.
➢ Parallel programming and neural networks.
➢ CAD, CAM, CIM systems.
➢ Simulation and modeling.
Introduction
Prof. K. Adisesha (Ph. D)
Why Use C++
➢ C++ is one of the world's most popular programming languages.
➢ C++ can be found in today's operating systems, Graphical User Interfaces, and embedded
systems.
➢ C++ is an object-oriented programming language which gives a clear structure to programs
and allows code to be reused, lowering development costs.
➢ C++ is portable and can be used to develop applications that can be adapted to multiple
platforms.
➢ C++ is fun and easy to learn!
➢ As C++ is close to C# and Java, it makes it easy for programmers to switch to C++ or vice
versa
7
Introduction
Prof. K. Adisesha (Ph. D)
8
Translating a C++ program
➢ Computers execute binary instructions.
➢ These binary instructions are known as machine instructions or machine code.
➢ The program creation process consists of the following steps:
Step 1 – Write the program in a computer language humans can read and understand (like C++),
Step 2 – Save the programs in text files as (.cpp) extension. Programs can be a few lines long and
reside in one file or can consist of many millions of lines of code and span thousands of files,
Step 3 – Run the source code files through a program called a compiler to generate object code for the
target computer,
Step 4 – Run the object files through a program called a linker to produce an executable image.
Introduction
Prof. K. Adisesha (Ph. D)
9
Translating a C++ program
➢ C++ Install IDE: download and Install Turbo C++ or Install Codeblocks
➢ The program execution process consists of the following steps:
Introduction
Prof. K. Adisesha (Ph. D)
10
General Structure of C++ Program.
 Different programming languages have their own format of coding.
 The basic components of a C++program are:
◼ Comments or Documentation Section
◼ Pre-processor Directives (Linker Section):
◼ Definition
◼ Global Declaration
◼ main ( ) function
◼ Declarations
◼ Statements
Introduction
Prof. K. Adisesha (Ph. D)
11
General Structure of C++ Program
➢ The basic components of a C++program are:
Characteristics of C++
Prof. K. Adisesha (Ph. D)
12
Characteristics of C++:
Object-Oriented Programming:
➢ It allows the programmer to design applications like a communication between object
rather than on a structured sequence of code. It allows a greater reusability of code in a
more logical and productive way.
Portability:
➢ We can compile the same C++ code in almost any type of computer & operating
system without making any changes.
Modular Programming:
➢ An application’s body in C++ can be made up of several source code files that are
compiled separately and then linked together saving time.
Characteristics of C++
Prof. K. Adisesha (Ph. D)
13
Characteristics of C++:
C Compatibility:
➢ Any code written in C can easily be included in a C++ program without making any
changes.
Speed:
➢ The resulting code from a C++ compilation is very efficient due to its duality as high-
level and low-level language.
Machine independent:
➢ It is a Machine Independent Language.
Characteristics of C++
Prof. K. Adisesha (Ph. D)
14
Characteristics of C++:
Flexibility:
➢ It is highly flexible language and versatility.
Wide range of library functions:
➢ It has huge library functions; it reduces the code development time and also reduces
cost of software development.
System Software Development:
➢ It can be used for developing System Software Viz., Operating system, Compilers,
Editors and Database.
C++ Character Set
Prof. K. Adisesha (Ph. D)
15
C++ Character Set:
Character Set means the valid set of characters that a language can recognizes.
➢ The character set of C++ includes the following:
C++ Tokens
Prof. K. Adisesha (Ph. D)
16
C++ Tokens:
The smallest individual unit in a program is known as token.
➢ These elements help us to construct statements, definitions, declarations, and so on,
which in turn helps us to construct complete program.
➢ Tokens used in C++ are:
❖ Identifier
❖ Reserved Keywords
❖ Constants or Literals
❖ Punctuators
❖ Operators
C++ Tokens
Prof. K. Adisesha (Ph. D)
17
C++ Identifier:
Identifiers is a name given to programming elements such as variables, functions,
arrays, objects, classes, etc.
➢ It contains letters, digits and underscore.
➢ C++ is a case sensitive; it treats uppercase and lowercase characters differently.
➢ The following are some valid identifiers:
▪ Adisesha
▪ time_table
▪ s2e2r3
▪ _dos _HJI3_JK
C++ Tokens
Prof. K. Adisesha (Ph. D)
18
C++ Identifier:
Rules to be followed while creating identifiers.
➢ Identifiers are a sequence of characters which should begin with the alphabet either
from A-Z (uppercase) or a-z (lowercase) or _ (underscore).
➢ C++ treats uppercase and lowercase characters differently. For example, DATA is not
same as data.
➢ No Special character is allowed except underscore “_”.
➢ Identifier should be single words i.e. blank spaces cannot be included in identifier.
➢ Reserved Keywords should not be used as identifiers.
➢ Identifiers should be of reasonable length.
C++ Tokens
Prof. K. Adisesha (Ph. D)
19
C++ Keywords:
Keyword is a predefined word that gives special meaning to the complier. The
programmer is not allowed to change its meaning.
➢ These are reserve for special purpose and must not be used as identifier name.
➢ Example:
cin, cout, for, if, else, this,
do, float, while, switch etc.,
C++ Tokens
Prof. K. Adisesha (Ph. D)
20
C++ Keywords:
There are keywords in C++ as mentioned below:
C++ Tokens
Prof. K. Adisesha (Ph. D)
21
Literals: A Literals/ constant are identifiers whose value does not change
during program execution.
➢ Constants are sometimes referred to as literal.
➢ A constant or literal my be any one of the following:
❖ Integer Constant
❖ Floating Constant
❖ Character Constant
❖ String Constant
Integer Constant:
➢ An integer constant is a whole number, which can be either positive or negative.
➢ They do not have fractional part or exponents.
➢ We can specify integer constants in:
❖ Decimal Integer Constant int a = 120; //Decimal Constant
❖ Octal Integer Constant int b = 0374; //Octal Constant
❖ Hexadecimal Integer Constant int c = -0XABF; //Hexadecimal Constant
❖ Unsigned Constant unsigned d = 328u; //Unsigned value
C++ Tokens
Prof. K. Adisesha (Ph. D)
22
C++ Tokens
Prof. K. Adisesha (Ph. D)
23
Floating Point Constant:
➢ Floating point constants are also called as “real constants”.
➢ These values contain decimal points (.) and can contain exponents.
➢ They are used to represent values that will have a fractional part and can be
represented in two forms (i.e. fractional form and exponent form)
➢ We can specify Floating Point constants in:
❖ float a=23.46 // equal to 23.46 x 100 = 23.46 x 1 = 23.46
❖ float b=26.126
Character constants: are specified as single character enclosed in pair of single
quotation marks.
❖ For example char ch = ‘P’;
➢ There are certain characters used in C++ which represents character constants called as
escape sequence which starts with a back slash (  ) followed by a character.
C++ Tokens
Prof. K. Adisesha (Ph. D)
24
C++ Tokens
Prof. K. Adisesha (Ph. D)
25
String Constants:
➢ A string constant consists of zero or more character enclosed by double quotation
marks (“ ”).
➢ Multiple character constants are called string constants and they are treated as an array
of char.
➢ By default compiler adds a special character called the “Null Character” (0) at the end
of the string to mark the end of the string.
➢ Example:
◼ char str[25] = “Hello Adisesha” ;
◼ This is actually represented as char str[25] = “Hello Adisesha0” in the memory
C++ Operators: Operators are used to perform operations on variables and values.
❖ Example: int x = 100 + 50;
➢ C++ Operators Types:
❖ C++ divides the operators into the following groups.
❖ Arithmetic operators
❖ Assignment operators
❖ Comparison operators
❖ Logical operators
❖ Bitwise operators
.
C++ Operators
Prof. K. Adisesha (Ph. D)
26
Arithmetic Operators
Prof. K. Adisesha (Ph. D)
27
➢ Arithmetic operators are used to perform common mathematical operations.
Assignment Operators
Prof. K. Adisesha (Ph. D)
28
➢ Assignment operators are used to assign values to variables.
Relational Operator
Prof. K. Adisesha (Ph. D)
29
➢ Comparison operators are used to compare two values.
➢ The return value of a comparison is either true (1) or false (0).
Logical Operators
Prof. K. Adisesha (Ph. D)
30
➢ Logical operators are used to determine the logic between variables or values.
Bitwise Operators
Prof. K. Adisesha (Ph. D)
31
➢ A Bitwise operators are used in bit level programming.
Classification of Operators
Prof. K. Adisesha (Ph. D)
32
➢ Operators may also be classified on the number of operands they act on either:
❖ Unary Operators
◼ Example: a++, a+1
❖ Binary Operators
◼ Example: x = x – 10;
❖ Ternary Operators
◼ Example: x = (a>b) ? a:b;
C++ Operators
Prof. K. Adisesha (Ph. D)
33
Special Operator :
➢ An expression is a combination of opcode and operand.
➢ Some special operators used in C++ programming are:
Punctuators
Prof. K. Adisesha (Ph. D)
34
➢ Punctuators in C++ have syntactic and semantic meaning to the compiler.
Structure of C++ Program
Prof. K. Adisesha (Ph. D)
35
General Structure of C++ Program.
 Different programming languages have their own format of coding.
 The basic components of a C++program are:
◼ Comments or Documentation Section
◼ Pre-processor Directives (Linker Section):
◼ Definition
◼ Global Declaration
◼ main ( ) function
◼ Declarations
◼ Statements
Structure of C++ Program
Prof. K. Adisesha (Ph. D)
36
General Structure of C++ Program
➢ Different programming languages have their own format of coding.
➢ The basic components of a C++program are:
C++ Comments
Prof. K. Adisesha (Ph. D)
37
C++ Comments
Comments can be used as non-executable statement to explain C++ code, and to make
it more readable.
➢ It can also be used to prevent execution when testing alternative code.
➢ Comments can be:
❖ singled-lined: Single-line comments start with two forward slashes (//).
Example:
❖ multi-lined.: Multi-line comments start with /* and ends with */.
Example:
C++ Linker Section
Prof. K. Adisesha (Ph. D)
38
Linker Section in C++
The linker is a program that makes executable files.
➢ The linker resolves linkage issues, such as the use of symbol hash (#) defined in one
translation unit.
➢ The C++ preprocessor directives programming skills that should be acquired:
❖ Able to understand and use #include.
❖ Able to understand and use #define.
❖ Able to understand and use macros and inline functions.
Library Functions in C++
Built-in functions are also known as library functions.
➢ We need not to declare and define these functions as they are already written in the
C++ libraries such as iostream, cmath etc.
C++ Library Functions
Prof. K. Adisesha (Ph. D)
39
Library Functions in C++
Built-in functions for String manipulation are:
C++ Library Functions
Prof. K. Adisesha (Ph. D)
40
Library Functions in C++
C++ Library Functions
Prof. K. Adisesha (Ph. D)
41
C++ Main function
Prof. K. Adisesha (Ph. D)
42
Main function section in C++
The starting point of all C++ programs is the main function.
➢ This function is called by the operating system when your program is executed by the
computer.
int main( )
{
cout << "Hello World" << endl; //Function body section
return 0;
}
❖ { signifies the start of a block of code, ​and } signifies the end.
Data Types
Prof. K. Adisesha (Ph. D)
43
Data Types in C++:
Data Types can be defined as the set of values, which can be stored in a variable along
with the operations that can be performed on those values.
 C++ defines several types of data and each type has unique characteristics.
 C++ data types can be classified as:
❖ The fundamental data type(built-in data)
❖ Derived Data type
❖ User-defined data type
Data Types:
➢ C++ defines several types of data and each type has unique characteristics.
➢ C++ data types can be classified as:
Data Types
Prof. K. Adisesha (Ph. D)
44
Data Types
Prof. K. Adisesha (Ph. D)
45
Basic Data Types:char type
The char type: It is character data type to store any character from the basic character set.
➢ Characters are enclosed in single quotation marks (‘). ‘A’, ‘a’, ‘b’, ‘9’, ‘+’ etc. are
character constants.
❖ When a variable of type char is declared, the compiler converts the character to its equivalent
ASCII code.
❖ A character is allocated only 1 byte (8 bits) of memory space.
❖ The general form of a character declaration is: char variable_list;
➢ Example: char alpha=’a’;
Data Types
Prof. K. Adisesha (Ph. D)
46
Basic Data Types:int type
The int type: The int type is used to store integers. Integers are whole numbers without
any fractional parts.
➢ An integer is allocated 2 bytes (16 bits) of memory space.
➢ The operations include addition, subtraction, multiplication, division, remainder etc.
➢ The integer can be positive or negative values and the ranges of number we can store
are from - 32786 to 32767.
➢ This includes number such as:
❖ 45 and -9 are integers.
❖ 5.2 is not an integer because it contains a decimal point.
Data Types
Prof. K. Adisesha (Ph. D)
47
Basic Data Types:float type
The float type: This represents the number with fractional part i.e. real numbers.
➢ The float type is used to store real numbers.
➢ Float is allocated 4 bytes (32 bits) of memory space.
➢ Number such as 1.8, 4.5, 12e-5 and -9.66 are all floating-point numbers.
➢ The range of numbers we can store from -34e-38 to 3.4e38.
➢ The general form of a float declaration is: float variable_name;
➢ Example:
❖ float a=5.5;
Data Types
Prof. K. Adisesha (Ph. D)
48
Basic Data Types:double type
The double type: The double and float are very similar.
➢ The float type allows you to store single precision floating point numbers, while the
double keyword allows you to store double precision floating point numbers.
➢ Its size is typically 8 bytes of memory space. The range of numbers we can store are
from -1.7e308 to 1.7e308.
➢ The general form of a double declaration is: double variable_list;
➢ Example: double a = 5.5e-7; //a is equivalent to 5.5x10-7
❖ float a=5.5;
Data Types
Prof. K. Adisesha (Ph. D)
49
Basic Data Types:bool type
The bool type: The bool type has logical value true or false.
➢ The identifier true has the value 1, and the identifier false has the value 0.
➢ The general form of a bool declaration is: bool variable_name;
➢ Example:
❖ bool legal_age=true;
❖ The statement legal_age= (age>=21);
✓ assigns the value true if age is greater than or equal to 21 or else it returns the value
false
Data Types
Prof. K. Adisesha (Ph. D)
50
Basic Data Types:void type
The void type : The void data type has no values and no operations.
➢ In other words, both the set of values and set of operations are empty.
➢ In this declaration the main function does not return any value.
➢ Example:
❖ void main( )
{
Statements;
}
Basic Data Types:
➢ The data type specifies the size and type of information the variable will
store.
➢ Example:
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
double myDoubleNum = 9.98; // Floating point number
char myLetter = ‘A'; // Character
bool myBoolean = true; // Boolean
string myText = "Hello"; // String
Data Types
Prof. K. Adisesha (Ph. D)
51
Data Types
Prof. K. Adisesha (Ph. D)
52
Basic Data Types:
➢ The data type specifies the size and type of information the variable will
store.
Data Types
Prof. K. Adisesha (Ph. D)
53
Derived data types:
These data types are constructed using simple or fundamental data types.
➢ Derived data types emphasize on structuring of a group of homogeneous (same type)
data items.
➢ These data types includes:
❖ Arrays
❖ Functions
❖ Pointers
❖ References
Data Types
Prof. K. Adisesha (Ph. D)
54
User defined data types:
These data types are constructed by user using simple or fundamental data types.
➢ User defined data types emphasize on structuring of a group of homogeneous (same
type) or heterogeneous (different type) data items.
➢ Some user defined data types include
❖ Enumerated
❖ Structure
❖ Union
❖ Class
Data Types
Prof. K. Adisesha (Ph. D)
55
Enumerated data type:
Enumerated data type: An enumeration is a user defined type consisting of a set of named
constants called enumerators.
➢ enum is a keyword that assigns values 0, 1, 2…… automatically.
➢ This helps in providing an alternative means for creating symbolic constants.
➢ The syntax for enum is as follows:
enum [tag] { enum – list} ; //for definition for enumerated type
➢ Example : enum choice { bad, satisfactory, good, very_good};
choice mychoice;
Data Types
Prof. K. Adisesha (Ph. D)
56
C++ Modifier Types:
A modifier is used to alter the meaning of the base type so that it more precisely fits the
needs of various situations.
➢ C++ allows the char, int, and double data types to have modifiers preceding them.
➢ The data type modifiers are listed here −
❖ Signed Ex: unsigned x;
❖ Unsigned unsigned int y;
❖ long
❖ Short
Converting an expression of a given type into another type is known as typecasting or
type conversion.
➢ Type conversions are of two types, they are:
◼ Implicit Conversion: They are automatically performed when a value is copied to a
compatible type.
 Example: short a = 2000;
int b;
b = a;
◼ Explicit Conversion: Many conversions, especially those that imply a different
interpretation of the value, require an explicit conversion.
 Example: short a = 2000;
int b;
b = (int) a; //c-like cast notation
Type Conversion
Prof. K. Adisesha (Ph. D)
57
Input & Output Operators
Prof. K. Adisesha (Ph. D)
58
Input & Output Operators
➢ The input output operations are done using library functions cin and cout objects of
the class iostream.
➢ Using the standard input and output library, we will able to interact with the user by
printing message on the screen and getting the user’s input from the keyboard.
❖ A stream is an object where a program can either insert/extract characters to/from
it.
❖ The standard C++ library includes the header file iostream, where the standard
input and output stream objects are declared.
Input & Output Operators
Prof. K. Adisesha (Ph. D)
59
Input Operators:
➢ Input Operator “>>”: The standard input device is usually the keyboard.
➢ Input in C++ is done by using the “stream extraction” (>>) on the cin stream.
➢ “cin” stands for “console input”.
➢ Example: int age;
cin>>age;
Input & Output Operators
Prof. K. Adisesha (Ph. D)
60
Output Operator:
 Output Operator “<<”: The standard output device is the screen (Monitor).
 Outputting in C++ is done by using the object followed by the “stream insertion”
(<<).
 “cout” stands for console output
 Example: cout<<”sum”; //prints sum
cout<<sum; //prints the content of the variable sum;
Input & Output Operators
Prof. K. Adisesha (Ph. D)
61
Cascading of I/O Operators:
 If a program requires more than one input variable then it is possible to input these
variables in a single cin statement using multiple stream extraction “>>” operators.
 Example: cout<<”Enter the two number”;
cin>>a>>b;
 If a program requires more than one output result then this can be done using a single
cout statement with multiple stream insertion “<<“ operators.
 This is called cascading of input & output operators.
 Example: cout<<”Entered the two number”<<a<<b<<endl;
cout<<”The sum of two number is”<<sum<<endl;
Manipulators
Prof. K. Adisesha (Ph. D)
62
Formatted Output (Manipulators): :
➢ Manipulators are the operators used with the insertion operator “<<“ to format the data
display.
➢ To use manipulator it is must to include header file <iomanip.h>
❖ endl
❖ setw()
➢ Example: endl manipulator: causes a line feed to be inserted. It has same effect as using new
line character “n”.
cout<<”Entered the two number”<<a<<b<<endl;
The setw( ) manipulator sets the width of the field assign for the output.
cout<<setw(6)<<”R” ; Output: _ _ _ _ _ R
Formatted Output (Manipulators):
➢ Manipulators are the operators used with the insertion operator “<<“ to format the data display.
➢ Program: To find the sum of two numbers:
#include<iostream.h>
#include<iomanip.h>
void main( )
{ int a, b, add;
clrscr( );
cout<<”Enter the two numbers”<<endl;
cin>>a>>b;
add = a + b;
cout<<”The sum of two number is”<<setw(6)<<sum<<endl;
getch(); }
Manipulators
Prof. K. Adisesha (Ph. D)
63
Formatted Output (Manipulators):
Manipulators
Prof. K. Adisesha (Ph. D)
64
Discussion
Prof. K. Adisesha (Ph. D)
65
Queries ?
Prof. K. Adisesha
9449081542

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Data types
Data typesData types
Data types
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
History of c++
History of c++ History of c++
History of c++
 
Structure in C
Structure in CStructure in C
Structure in C
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
C functions
C functionsC functions
C functions
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
Function in C program
Function in C programFunction in C program
Function in C program
 
History of c
History of cHistory of c
History of c
 
Programming in c
Programming in cProgramming in c
Programming in c
 

Similar a Introduction to c++ ppt 1

Summer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxSummer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptx
shokeenk14
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
ANUSUYA S
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
Rajb54
 

Similar a Introduction to c++ ppt 1 (20)

object oriented programming language fundamentals
object oriented programming language fundamentalsobject oriented programming language fundamentals
object oriented programming language fundamentals
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Summer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxSummer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptx
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
Part 1
Part 1Part 1
Part 1
 
C language
C languageC language
C language
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
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
 
1 puc programming using c++
1 puc programming using c++1 puc programming using c++
1 puc programming using c++
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
C tutorials
C tutorialsC tutorials
C tutorials
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
 

Más de Prof. Dr. K. Adisesha

Más de Prof. Dr. K. Adisesha (20)

Software Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdfSoftware Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdf
 
Software Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdfSoftware Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdf
 
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdfSoftware Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
 
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdfSoftware Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
 
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdfSoftware Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
 
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdfSoftware Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
 
Computer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. AdiseshaComputer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. Adisesha
 
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. AdiaeshaCCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
 
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. AdiseshaCCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
 
CCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. AdiseshaCCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. Adisesha
 
CCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdfCCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdf
 
Introduction to Computers.pdf
Introduction to Computers.pdfIntroduction to Computers.pdf
Introduction to Computers.pdf
 
R_Programming.pdf
R_Programming.pdfR_Programming.pdf
R_Programming.pdf
 
Scholarship.pdf
Scholarship.pdfScholarship.pdf
Scholarship.pdf
 
Operating System-2 by Adi.pdf
Operating System-2 by Adi.pdfOperating System-2 by Adi.pdf
Operating System-2 by Adi.pdf
 
Operating System-1 by Adi.pdf
Operating System-1 by Adi.pdfOperating System-1 by Adi.pdf
Operating System-1 by Adi.pdf
 
Operating System-adi.pdf
Operating System-adi.pdfOperating System-adi.pdf
Operating System-adi.pdf
 
Data_structure using C-Adi.pdf
Data_structure using C-Adi.pdfData_structure using C-Adi.pdf
Data_structure using C-Adi.pdf
 
JAVA PPT -2 BY ADI.pdf
JAVA PPT -2 BY ADI.pdfJAVA PPT -2 BY ADI.pdf
JAVA PPT -2 BY ADI.pdf
 
JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
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
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Introduction to c++ ppt 1

  • 1. INTRODUCTION TO C++ Prof. K ADISESHA (Ph. D)
  • 2. INTRODUCTION TO C++ PROGRAMMING introduction Characteristics of C++ C++ Character Set C++ Tokens Data Types of C++ 2 C++ PROGRAMMING Prof. K. Adisesha (Ph. D) I/O Operators of C++
  • 3. Introduction Prof. K. Adisesha (Ph. D) 3 History of C++: The C++ programming language was created by Bjarne Stroustrup and his team at Bell Laboratories (AT&T, USA) to help implement simulation projects in an object- oriented and efficient way. ➢ C++ is a superset of C because; any valid C program is valid C++ program too but not the vice versa is not true. ➢ C++ can make use of existing C software libraries with major addition of “Class Construct”. ➢ This language was called “C with classes” and later in 1983, it was named “C++” by Rick Mascitii. As the name C++ implies, C++ was derived from the C programming language: ++ is the increment operator in C.
  • 4. Introduction Prof. K. Adisesha (Ph. D) 4 OOPs characteristics ➢ Modularity: Module is a logically self-contained unit that can be tested and executed independently. ➢ Abstraction: It represents the essential features of an entity without including explanations or any background details about it. ➢ Data Encapsulation: Wrapping of data and functions into a single unit is called data encapsulation. ➢ Inheritance: The process by which objects of one class acquires the properties of the objects of another class. ➢ Polymorphism: The ability for a message to be processed in more than one form. ➢ Dynamic Binding: Linking of a procedure call to the code to be executed when it is called. ➢ Message Passing: Passing message objects and invoking the function by the object by sending a message is known as message passing.
  • 5. Introduction Prof. K. Adisesha (Ph. D) 5 OOPs Benefits ➢ OOPs model the real world entity very well. ➢ Inheritance eliminates the redundancy (repetition) of code and hence supports code reusability. ➢ Data hiding helps to build secured programs. ➢ Multiple instances (objects) can be created. ➢ Work can be divided easily. ➢ OOPs can be easily upgraded from small to large systems. ➢ Complexity can be easily managed. ➢ Message passing concept helps the objects to communicate and share data.
  • 6. Introduction Prof. K. Adisesha (Ph. D) 6 OOPs Applications ➢ Object oriented databases. ➢ Hypermedia, expert text and hypertext. ➢ Artificial intelligence and expert systems. ➢ Decision support systems and office automation systems. ➢ Parallel programming and neural networks. ➢ CAD, CAM, CIM systems. ➢ Simulation and modeling.
  • 7. Introduction Prof. K. Adisesha (Ph. D) Why Use C++ ➢ C++ is one of the world's most popular programming languages. ➢ C++ can be found in today's operating systems, Graphical User Interfaces, and embedded systems. ➢ C++ is an object-oriented programming language which gives a clear structure to programs and allows code to be reused, lowering development costs. ➢ C++ is portable and can be used to develop applications that can be adapted to multiple platforms. ➢ C++ is fun and easy to learn! ➢ As C++ is close to C# and Java, it makes it easy for programmers to switch to C++ or vice versa 7
  • 8. Introduction Prof. K. Adisesha (Ph. D) 8 Translating a C++ program ➢ Computers execute binary instructions. ➢ These binary instructions are known as machine instructions or machine code. ➢ The program creation process consists of the following steps: Step 1 – Write the program in a computer language humans can read and understand (like C++), Step 2 – Save the programs in text files as (.cpp) extension. Programs can be a few lines long and reside in one file or can consist of many millions of lines of code and span thousands of files, Step 3 – Run the source code files through a program called a compiler to generate object code for the target computer, Step 4 – Run the object files through a program called a linker to produce an executable image.
  • 9. Introduction Prof. K. Adisesha (Ph. D) 9 Translating a C++ program ➢ C++ Install IDE: download and Install Turbo C++ or Install Codeblocks ➢ The program execution process consists of the following steps:
  • 10. Introduction Prof. K. Adisesha (Ph. D) 10 General Structure of C++ Program.  Different programming languages have their own format of coding.  The basic components of a C++program are: ◼ Comments or Documentation Section ◼ Pre-processor Directives (Linker Section): ◼ Definition ◼ Global Declaration ◼ main ( ) function ◼ Declarations ◼ Statements
  • 11. Introduction Prof. K. Adisesha (Ph. D) 11 General Structure of C++ Program ➢ The basic components of a C++program are:
  • 12. Characteristics of C++ Prof. K. Adisesha (Ph. D) 12 Characteristics of C++: Object-Oriented Programming: ➢ It allows the programmer to design applications like a communication between object rather than on a structured sequence of code. It allows a greater reusability of code in a more logical and productive way. Portability: ➢ We can compile the same C++ code in almost any type of computer & operating system without making any changes. Modular Programming: ➢ An application’s body in C++ can be made up of several source code files that are compiled separately and then linked together saving time.
  • 13. Characteristics of C++ Prof. K. Adisesha (Ph. D) 13 Characteristics of C++: C Compatibility: ➢ Any code written in C can easily be included in a C++ program without making any changes. Speed: ➢ The resulting code from a C++ compilation is very efficient due to its duality as high- level and low-level language. Machine independent: ➢ It is a Machine Independent Language.
  • 14. Characteristics of C++ Prof. K. Adisesha (Ph. D) 14 Characteristics of C++: Flexibility: ➢ It is highly flexible language and versatility. Wide range of library functions: ➢ It has huge library functions; it reduces the code development time and also reduces cost of software development. System Software Development: ➢ It can be used for developing System Software Viz., Operating system, Compilers, Editors and Database.
  • 15. C++ Character Set Prof. K. Adisesha (Ph. D) 15 C++ Character Set: Character Set means the valid set of characters that a language can recognizes. ➢ The character set of C++ includes the following:
  • 16. C++ Tokens Prof. K. Adisesha (Ph. D) 16 C++ Tokens: The smallest individual unit in a program is known as token. ➢ These elements help us to construct statements, definitions, declarations, and so on, which in turn helps us to construct complete program. ➢ Tokens used in C++ are: ❖ Identifier ❖ Reserved Keywords ❖ Constants or Literals ❖ Punctuators ❖ Operators
  • 17. C++ Tokens Prof. K. Adisesha (Ph. D) 17 C++ Identifier: Identifiers is a name given to programming elements such as variables, functions, arrays, objects, classes, etc. ➢ It contains letters, digits and underscore. ➢ C++ is a case sensitive; it treats uppercase and lowercase characters differently. ➢ The following are some valid identifiers: ▪ Adisesha ▪ time_table ▪ s2e2r3 ▪ _dos _HJI3_JK
  • 18. C++ Tokens Prof. K. Adisesha (Ph. D) 18 C++ Identifier: Rules to be followed while creating identifiers. ➢ Identifiers are a sequence of characters which should begin with the alphabet either from A-Z (uppercase) or a-z (lowercase) or _ (underscore). ➢ C++ treats uppercase and lowercase characters differently. For example, DATA is not same as data. ➢ No Special character is allowed except underscore “_”. ➢ Identifier should be single words i.e. blank spaces cannot be included in identifier. ➢ Reserved Keywords should not be used as identifiers. ➢ Identifiers should be of reasonable length.
  • 19. C++ Tokens Prof. K. Adisesha (Ph. D) 19 C++ Keywords: Keyword is a predefined word that gives special meaning to the complier. The programmer is not allowed to change its meaning. ➢ These are reserve for special purpose and must not be used as identifier name. ➢ Example: cin, cout, for, if, else, this, do, float, while, switch etc.,
  • 20. C++ Tokens Prof. K. Adisesha (Ph. D) 20 C++ Keywords: There are keywords in C++ as mentioned below:
  • 21. C++ Tokens Prof. K. Adisesha (Ph. D) 21 Literals: A Literals/ constant are identifiers whose value does not change during program execution. ➢ Constants are sometimes referred to as literal. ➢ A constant or literal my be any one of the following: ❖ Integer Constant ❖ Floating Constant ❖ Character Constant ❖ String Constant
  • 22. Integer Constant: ➢ An integer constant is a whole number, which can be either positive or negative. ➢ They do not have fractional part or exponents. ➢ We can specify integer constants in: ❖ Decimal Integer Constant int a = 120; //Decimal Constant ❖ Octal Integer Constant int b = 0374; //Octal Constant ❖ Hexadecimal Integer Constant int c = -0XABF; //Hexadecimal Constant ❖ Unsigned Constant unsigned d = 328u; //Unsigned value C++ Tokens Prof. K. Adisesha (Ph. D) 22
  • 23. C++ Tokens Prof. K. Adisesha (Ph. D) 23 Floating Point Constant: ➢ Floating point constants are also called as “real constants”. ➢ These values contain decimal points (.) and can contain exponents. ➢ They are used to represent values that will have a fractional part and can be represented in two forms (i.e. fractional form and exponent form) ➢ We can specify Floating Point constants in: ❖ float a=23.46 // equal to 23.46 x 100 = 23.46 x 1 = 23.46 ❖ float b=26.126
  • 24. Character constants: are specified as single character enclosed in pair of single quotation marks. ❖ For example char ch = ‘P’; ➢ There are certain characters used in C++ which represents character constants called as escape sequence which starts with a back slash ( ) followed by a character. C++ Tokens Prof. K. Adisesha (Ph. D) 24
  • 25. C++ Tokens Prof. K. Adisesha (Ph. D) 25 String Constants: ➢ A string constant consists of zero or more character enclosed by double quotation marks (“ ”). ➢ Multiple character constants are called string constants and they are treated as an array of char. ➢ By default compiler adds a special character called the “Null Character” (0) at the end of the string to mark the end of the string. ➢ Example: ◼ char str[25] = “Hello Adisesha” ; ◼ This is actually represented as char str[25] = “Hello Adisesha0” in the memory
  • 26. C++ Operators: Operators are used to perform operations on variables and values. ❖ Example: int x = 100 + 50; ➢ C++ Operators Types: ❖ C++ divides the operators into the following groups. ❖ Arithmetic operators ❖ Assignment operators ❖ Comparison operators ❖ Logical operators ❖ Bitwise operators . C++ Operators Prof. K. Adisesha (Ph. D) 26
  • 27. Arithmetic Operators Prof. K. Adisesha (Ph. D) 27 ➢ Arithmetic operators are used to perform common mathematical operations.
  • 28. Assignment Operators Prof. K. Adisesha (Ph. D) 28 ➢ Assignment operators are used to assign values to variables.
  • 29. Relational Operator Prof. K. Adisesha (Ph. D) 29 ➢ Comparison operators are used to compare two values. ➢ The return value of a comparison is either true (1) or false (0).
  • 30. Logical Operators Prof. K. Adisesha (Ph. D) 30 ➢ Logical operators are used to determine the logic between variables or values.
  • 31. Bitwise Operators Prof. K. Adisesha (Ph. D) 31 ➢ A Bitwise operators are used in bit level programming.
  • 32. Classification of Operators Prof. K. Adisesha (Ph. D) 32 ➢ Operators may also be classified on the number of operands they act on either: ❖ Unary Operators ◼ Example: a++, a+1 ❖ Binary Operators ◼ Example: x = x – 10; ❖ Ternary Operators ◼ Example: x = (a>b) ? a:b;
  • 33. C++ Operators Prof. K. Adisesha (Ph. D) 33 Special Operator : ➢ An expression is a combination of opcode and operand. ➢ Some special operators used in C++ programming are:
  • 34. Punctuators Prof. K. Adisesha (Ph. D) 34 ➢ Punctuators in C++ have syntactic and semantic meaning to the compiler.
  • 35. Structure of C++ Program Prof. K. Adisesha (Ph. D) 35 General Structure of C++ Program.  Different programming languages have their own format of coding.  The basic components of a C++program are: ◼ Comments or Documentation Section ◼ Pre-processor Directives (Linker Section): ◼ Definition ◼ Global Declaration ◼ main ( ) function ◼ Declarations ◼ Statements
  • 36. Structure of C++ Program Prof. K. Adisesha (Ph. D) 36 General Structure of C++ Program ➢ Different programming languages have their own format of coding. ➢ The basic components of a C++program are:
  • 37. C++ Comments Prof. K. Adisesha (Ph. D) 37 C++ Comments Comments can be used as non-executable statement to explain C++ code, and to make it more readable. ➢ It can also be used to prevent execution when testing alternative code. ➢ Comments can be: ❖ singled-lined: Single-line comments start with two forward slashes (//). Example: ❖ multi-lined.: Multi-line comments start with /* and ends with */. Example:
  • 38. C++ Linker Section Prof. K. Adisesha (Ph. D) 38 Linker Section in C++ The linker is a program that makes executable files. ➢ The linker resolves linkage issues, such as the use of symbol hash (#) defined in one translation unit. ➢ The C++ preprocessor directives programming skills that should be acquired: ❖ Able to understand and use #include. ❖ Able to understand and use #define. ❖ Able to understand and use macros and inline functions.
  • 39. Library Functions in C++ Built-in functions are also known as library functions. ➢ We need not to declare and define these functions as they are already written in the C++ libraries such as iostream, cmath etc. C++ Library Functions Prof. K. Adisesha (Ph. D) 39
  • 40. Library Functions in C++ Built-in functions for String manipulation are: C++ Library Functions Prof. K. Adisesha (Ph. D) 40
  • 41. Library Functions in C++ C++ Library Functions Prof. K. Adisesha (Ph. D) 41
  • 42. C++ Main function Prof. K. Adisesha (Ph. D) 42 Main function section in C++ The starting point of all C++ programs is the main function. ➢ This function is called by the operating system when your program is executed by the computer. int main( ) { cout << "Hello World" << endl; //Function body section return 0; } ❖ { signifies the start of a block of code, ​and } signifies the end.
  • 43. Data Types Prof. K. Adisesha (Ph. D) 43 Data Types in C++: Data Types can be defined as the set of values, which can be stored in a variable along with the operations that can be performed on those values.  C++ defines several types of data and each type has unique characteristics.  C++ data types can be classified as: ❖ The fundamental data type(built-in data) ❖ Derived Data type ❖ User-defined data type
  • 44. Data Types: ➢ C++ defines several types of data and each type has unique characteristics. ➢ C++ data types can be classified as: Data Types Prof. K. Adisesha (Ph. D) 44
  • 45. Data Types Prof. K. Adisesha (Ph. D) 45 Basic Data Types:char type The char type: It is character data type to store any character from the basic character set. ➢ Characters are enclosed in single quotation marks (‘). ‘A’, ‘a’, ‘b’, ‘9’, ‘+’ etc. are character constants. ❖ When a variable of type char is declared, the compiler converts the character to its equivalent ASCII code. ❖ A character is allocated only 1 byte (8 bits) of memory space. ❖ The general form of a character declaration is: char variable_list; ➢ Example: char alpha=’a’;
  • 46. Data Types Prof. K. Adisesha (Ph. D) 46 Basic Data Types:int type The int type: The int type is used to store integers. Integers are whole numbers without any fractional parts. ➢ An integer is allocated 2 bytes (16 bits) of memory space. ➢ The operations include addition, subtraction, multiplication, division, remainder etc. ➢ The integer can be positive or negative values and the ranges of number we can store are from - 32786 to 32767. ➢ This includes number such as: ❖ 45 and -9 are integers. ❖ 5.2 is not an integer because it contains a decimal point.
  • 47. Data Types Prof. K. Adisesha (Ph. D) 47 Basic Data Types:float type The float type: This represents the number with fractional part i.e. real numbers. ➢ The float type is used to store real numbers. ➢ Float is allocated 4 bytes (32 bits) of memory space. ➢ Number such as 1.8, 4.5, 12e-5 and -9.66 are all floating-point numbers. ➢ The range of numbers we can store from -34e-38 to 3.4e38. ➢ The general form of a float declaration is: float variable_name; ➢ Example: ❖ float a=5.5;
  • 48. Data Types Prof. K. Adisesha (Ph. D) 48 Basic Data Types:double type The double type: The double and float are very similar. ➢ The float type allows you to store single precision floating point numbers, while the double keyword allows you to store double precision floating point numbers. ➢ Its size is typically 8 bytes of memory space. The range of numbers we can store are from -1.7e308 to 1.7e308. ➢ The general form of a double declaration is: double variable_list; ➢ Example: double a = 5.5e-7; //a is equivalent to 5.5x10-7 ❖ float a=5.5;
  • 49. Data Types Prof. K. Adisesha (Ph. D) 49 Basic Data Types:bool type The bool type: The bool type has logical value true or false. ➢ The identifier true has the value 1, and the identifier false has the value 0. ➢ The general form of a bool declaration is: bool variable_name; ➢ Example: ❖ bool legal_age=true; ❖ The statement legal_age= (age>=21); ✓ assigns the value true if age is greater than or equal to 21 or else it returns the value false
  • 50. Data Types Prof. K. Adisesha (Ph. D) 50 Basic Data Types:void type The void type : The void data type has no values and no operations. ➢ In other words, both the set of values and set of operations are empty. ➢ In this declaration the main function does not return any value. ➢ Example: ❖ void main( ) { Statements; }
  • 51. Basic Data Types: ➢ The data type specifies the size and type of information the variable will store. ➢ Example: int myNum = 5; // Integer (whole number) float myFloatNum = 5.99; // Floating point number double myDoubleNum = 9.98; // Floating point number char myLetter = ‘A'; // Character bool myBoolean = true; // Boolean string myText = "Hello"; // String Data Types Prof. K. Adisesha (Ph. D) 51
  • 52. Data Types Prof. K. Adisesha (Ph. D) 52 Basic Data Types: ➢ The data type specifies the size and type of information the variable will store.
  • 53. Data Types Prof. K. Adisesha (Ph. D) 53 Derived data types: These data types are constructed using simple or fundamental data types. ➢ Derived data types emphasize on structuring of a group of homogeneous (same type) data items. ➢ These data types includes: ❖ Arrays ❖ Functions ❖ Pointers ❖ References
  • 54. Data Types Prof. K. Adisesha (Ph. D) 54 User defined data types: These data types are constructed by user using simple or fundamental data types. ➢ User defined data types emphasize on structuring of a group of homogeneous (same type) or heterogeneous (different type) data items. ➢ Some user defined data types include ❖ Enumerated ❖ Structure ❖ Union ❖ Class
  • 55. Data Types Prof. K. Adisesha (Ph. D) 55 Enumerated data type: Enumerated data type: An enumeration is a user defined type consisting of a set of named constants called enumerators. ➢ enum is a keyword that assigns values 0, 1, 2…… automatically. ➢ This helps in providing an alternative means for creating symbolic constants. ➢ The syntax for enum is as follows: enum [tag] { enum – list} ; //for definition for enumerated type ➢ Example : enum choice { bad, satisfactory, good, very_good}; choice mychoice;
  • 56. Data Types Prof. K. Adisesha (Ph. D) 56 C++ Modifier Types: A modifier is used to alter the meaning of the base type so that it more precisely fits the needs of various situations. ➢ C++ allows the char, int, and double data types to have modifiers preceding them. ➢ The data type modifiers are listed here − ❖ Signed Ex: unsigned x; ❖ Unsigned unsigned int y; ❖ long ❖ Short
  • 57. Converting an expression of a given type into another type is known as typecasting or type conversion. ➢ Type conversions are of two types, they are: ◼ Implicit Conversion: They are automatically performed when a value is copied to a compatible type.  Example: short a = 2000; int b; b = a; ◼ Explicit Conversion: Many conversions, especially those that imply a different interpretation of the value, require an explicit conversion.  Example: short a = 2000; int b; b = (int) a; //c-like cast notation Type Conversion Prof. K. Adisesha (Ph. D) 57
  • 58. Input & Output Operators Prof. K. Adisesha (Ph. D) 58 Input & Output Operators ➢ The input output operations are done using library functions cin and cout objects of the class iostream. ➢ Using the standard input and output library, we will able to interact with the user by printing message on the screen and getting the user’s input from the keyboard. ❖ A stream is an object where a program can either insert/extract characters to/from it. ❖ The standard C++ library includes the header file iostream, where the standard input and output stream objects are declared.
  • 59. Input & Output Operators Prof. K. Adisesha (Ph. D) 59 Input Operators: ➢ Input Operator “>>”: The standard input device is usually the keyboard. ➢ Input in C++ is done by using the “stream extraction” (>>) on the cin stream. ➢ “cin” stands for “console input”. ➢ Example: int age; cin>>age;
  • 60. Input & Output Operators Prof. K. Adisesha (Ph. D) 60 Output Operator:  Output Operator “<<”: The standard output device is the screen (Monitor).  Outputting in C++ is done by using the object followed by the “stream insertion” (<<).  “cout” stands for console output  Example: cout<<”sum”; //prints sum cout<<sum; //prints the content of the variable sum;
  • 61. Input & Output Operators Prof. K. Adisesha (Ph. D) 61 Cascading of I/O Operators:  If a program requires more than one input variable then it is possible to input these variables in a single cin statement using multiple stream extraction “>>” operators.  Example: cout<<”Enter the two number”; cin>>a>>b;  If a program requires more than one output result then this can be done using a single cout statement with multiple stream insertion “<<“ operators.  This is called cascading of input & output operators.  Example: cout<<”Entered the two number”<<a<<b<<endl; cout<<”The sum of two number is”<<sum<<endl;
  • 62. Manipulators Prof. K. Adisesha (Ph. D) 62 Formatted Output (Manipulators): : ➢ Manipulators are the operators used with the insertion operator “<<“ to format the data display. ➢ To use manipulator it is must to include header file <iomanip.h> ❖ endl ❖ setw() ➢ Example: endl manipulator: causes a line feed to be inserted. It has same effect as using new line character “n”. cout<<”Entered the two number”<<a<<b<<endl; The setw( ) manipulator sets the width of the field assign for the output. cout<<setw(6)<<”R” ; Output: _ _ _ _ _ R
  • 63. Formatted Output (Manipulators): ➢ Manipulators are the operators used with the insertion operator “<<“ to format the data display. ➢ Program: To find the sum of two numbers: #include<iostream.h> #include<iomanip.h> void main( ) { int a, b, add; clrscr( ); cout<<”Enter the two numbers”<<endl; cin>>a>>b; add = a + b; cout<<”The sum of two number is”<<setw(6)<<sum<<endl; getch(); } Manipulators Prof. K. Adisesha (Ph. D) 63
  • 65. Discussion Prof. K. Adisesha (Ph. D) 65 Queries ? Prof. K. Adisesha 9449081542