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

More Related Content

PDF
Introduction to c++ ppt
PDF
Object oriented programming c++
PPT
Basics of c++ Programming Language
PPTX
Presentation on C++ Programming Language
PPTX
C++ presentation
PPTX
Introduction to c++
PPT
C by balaguruswami - e.balagurusamy
Introduction to c++ ppt
Object oriented programming c++
Basics of c++ Programming Language
Presentation on C++ Programming Language
C++ presentation
Introduction to c++
C by balaguruswami - e.balagurusamy

What's hot (20)

PPT
Operator Overloading
PPTX
Operators and expressions in C++
PPTX
Keywords in c language
PPT
Constants in C Programming
PPTX
Data types
PPTX
Inheritance in c++
PPT
Class and object in C++
PPTX
Constructor and Types of Constructors
PPT
Structure of C++ - R.D.Sivakumar
PPT
File handling in c
PPT
08 c++ Operator Overloading.ppt
PPT
Operators in C Programming
PPTX
While , For , Do-While Loop
PPTX
C language ppt
PPTX
Data types in c++
PPTX
class and objects
PPTX
Pointer in C++
PDF
Function overloading ppt
PPT
Input and output in C++
PDF
Managing I/O in c++
Operator Overloading
Operators and expressions in C++
Keywords in c language
Constants in C Programming
Data types
Inheritance in c++
Class and object in C++
Constructor and Types of Constructors
Structure of C++ - R.D.Sivakumar
File handling in c
08 c++ Operator Overloading.ppt
Operators in C Programming
While , For , Do-While Loop
C language ppt
Data types in c++
class and objects
Pointer in C++
Function overloading ppt
Input and output in C++
Managing I/O in c++
Ad

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

PPTX
Introduction to c++ programming language
PDF
Introduction to c++
PPTX
introductiontocprogramming datatypespp.pptx
PDF
1 puc programming using c++
PPTX
INTRODUCTION TO C++.pptx
PPTX
Object Oriented Programming Using C++.pptx
PPTX
Basics Of C++.pptx
PPTX
C++
 
PDF
PDF
Introduction of C++ By Pawan Thakur
PDF
The C++ Programming Language
PDF
3.-Beginnign-with-C.pdf.Basic c++ Learn and Object oriented programming a to z
PDF
Cp week _2.
PPTX
c++ programming Unit 1 introduction to c++
PPTX
Object oriented programming 7 first steps in oop using c++
PDF
Keywords, identifiers ,datatypes in C++
PPTX
Getting started with C++
PPT
Programming of c++
PPTX
C++ AND CATEGORIES OF SOFTWARE
PDF
Object Oriented Programming With C Sharma A K
Introduction to c++ programming language
Introduction to c++
introductiontocprogramming datatypespp.pptx
1 puc programming using c++
INTRODUCTION TO C++.pptx
Object Oriented Programming Using C++.pptx
Basics Of C++.pptx
C++
 
Introduction of C++ By Pawan Thakur
The C++ Programming Language
3.-Beginnign-with-C.pdf.Basic c++ Learn and Object oriented programming a to z
Cp week _2.
c++ programming Unit 1 introduction to c++
Object oriented programming 7 first steps in oop using c++
Keywords, identifiers ,datatypes in C++
Getting started with C++
Programming of c++
C++ AND CATEGORIES OF SOFTWARE
Object Oriented Programming With C Sharma A K
Ad

More from Prof. Dr. K. Adisesha (20)

PDF
MACHINE LEARNING Notes by Dr. K. Adisesha
PDF
Probabilistic and Stochastic Models Unit-3-Adi.pdf
PDF
Genetic Algorithm in Machine Learning PPT by-Adi
PDF
Unsupervised Machine Learning PPT Adi.pdf
PDF
Supervised Machine Learning PPT by K. Adisesha
PDF
Introduction to Machine Learning PPT by K. Adisesha
PPSX
Design and Analysis of Algorithms ppt by K. Adi
PPSX
Data Structure using C by Dr. K Adisesha .ppsx
PDF
Operating System-4 "File Management" by Adi.pdf
PDF
Operating System-3 "Memory Management" by Adi.pdf
PDF
Operating System Concepts Part-1 by_Adi.pdf
PDF
Operating System-2_Process Managementby_Adi.pdf
PDF
Software Engineering notes by K. Adisesha.pdf
PDF
Software Engineering-Unit 1 by Adisesha.pdf
PDF
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
PDF
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
PDF
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
PDF
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
PDF
Computer Networks Notes by -Dr. K. Adisesha
PDF
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
MACHINE LEARNING Notes by Dr. K. Adisesha
Probabilistic and Stochastic Models Unit-3-Adi.pdf
Genetic Algorithm in Machine Learning PPT by-Adi
Unsupervised Machine Learning PPT Adi.pdf
Supervised Machine Learning PPT by K. Adisesha
Introduction to Machine Learning PPT by K. Adisesha
Design and Analysis of Algorithms ppt by K. Adi
Data Structure using C by Dr. K Adisesha .ppsx
Operating System-4 "File Management" by Adi.pdf
Operating System-3 "Memory Management" by Adi.pdf
Operating System Concepts Part-1 by_Adi.pdf
Operating System-2_Process Managementby_Adi.pdf
Software Engineering notes by K. Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Computer Networks Notes by -Dr. K. Adisesha
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha

Recently uploaded (20)

PPTX
Diploma pharmaceutics notes..helps diploma students
PPTX
Ppt obs emergecy.pptxydirnbduejguxjjdjidjdbuc
PDF
BSc-Zoology-02Sem-DrVijay-Comparative anatomy of vertebrates.pdf
PPTX
Neurology of Systemic disease all systems
PPTX
Copy of ARAL Program Primer_071725(1).pptx
PDF
GSA-Past-Papers-2010-2024-2.pdf CSS examination
PDF
Review of Related Literature & Studies.pdf
PPTX
CHROMIUM & Glucose Tolerance Factor.pptx
PDF
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
PDF
Physical pharmaceutics two in b pharmacy
PPTX
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
PDF
anganwadi services for the b.sc nursing and GNM
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
DOCX
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
PPTX
PAIN PATHWAY & MANAGEMENT OF ACUTE AND CHRONIC PAIN SPEAKER: Dr. Rajasekhar ...
PDF
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
PDF
Chevening Scholarship Application and Interview Preparation Guide
PPTX
Theoretical for class.pptxgshdhddhdhdhgd
PDF
V02-Session-4-Leadership-Through-Assessment-MLB.pdf
PDF
FAMILY PLANNING (preventative and social medicine pdf)
Diploma pharmaceutics notes..helps diploma students
Ppt obs emergecy.pptxydirnbduejguxjjdjidjdbuc
BSc-Zoology-02Sem-DrVijay-Comparative anatomy of vertebrates.pdf
Neurology of Systemic disease all systems
Copy of ARAL Program Primer_071725(1).pptx
GSA-Past-Papers-2010-2024-2.pdf CSS examination
Review of Related Literature & Studies.pdf
CHROMIUM & Glucose Tolerance Factor.pptx
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
Physical pharmaceutics two in b pharmacy
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
anganwadi services for the b.sc nursing and GNM
MMW-CHAPTER-1-final.pptx major Elementary Education
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
PAIN PATHWAY & MANAGEMENT OF ACUTE AND CHRONIC PAIN SPEAKER: Dr. Rajasekhar ...
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
Chevening Scholarship Application and Interview Preparation Guide
Theoretical for class.pptxgshdhddhdhdhgd
V02-Session-4-Leadership-Through-Assessment-MLB.pdf
FAMILY PLANNING (preventative and social medicine pdf)

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