SlideShare uma empresa Scribd logo
1 de 25
Getting Started in C++
Parts of C++
Computer
Language
Program
Character
Set
Tokens
Header
Files
C++ Character Set
• A character set of a language consists of any of the letters, digits
or special symbols that can be used to form the commands in that
language. The C++ character set consists of :
Alphabets
A-Z
a-z
Digits
0-9
Special
Symbols
#, ||+ -* ^
 = !=; : &
#
[] {} < > . ‘
‘
Tokens in C++ Token
Keywords
Identifier Literal
Operator
The smallest executable unit in a program is known as token.
A token can be any keyword, Identifier ,Literal, Punctuator or Operator.
Keywords in
C++
Examples
of
keywords
public
void
float class
Signed
private
These are the reserved words used by the compiler. They have a certain meaning for the language
They cannot be used as identifiers.
NOTE: All the keywords are written in small letters.
Identifiers in
C++
Examples
of
identifiers
rollno
Change_no student
Employee
An identifier is a name given to any entity of a program. It is used to identify any variable, function,
class , structure etc in c++. It may consist of a combination of letters & numbers.
NOTE: C++ is case sensitive as it treats upper and lower case letters differently so an identifier Rollno
will be diiferent from rollno.
Literals in
C++ LiteralsInteger
Character
Floating
point
String
Backslash
character
constants
The data items which never change their value throughout the program run.
There are several kind of literals which we shall discuss in detail in the next chapter
We shall discuss Backslash character constants here.
Backslash character constants
• These are also known as escape sequences.
• They are used to represent certain sequences such as newline in
C++ .
• When certain letters are preceded by a backslash they will have
special meaning in the language and they are used to represent
sequences such as newline (n) or tab (t) or backspace(b).
• Let us take a look at each of these.
Newline (n)
cout<<“Goodn
morning”;
Good
morning
cout<<“”Good
morning”;
Good mo
rning
cout<<“Letn”;
cout<<“the
mouse n in”;
Let
the mouse
in
The newline character when encountered by the compiler converts to a carriage return.
Any text or data following it appears on the next line. IT is used to display output on the
Next line.
Tab (t)
cout<<“Goodt morning”;
Good morning
cout<<“”Good mot rning”;
Good mo rning
The t character when encountered by the compiler converts to a tab.
Any text or data following it appears after 8 spaces.
backspace
(b)
cout<<“Hellobworld”;
Hellworld
The b character when encountered by the compiler converts to a backspace.
The cursor moves one space backward in the output when this character is encountered
Here the b makes the cursor move one
space backward to ‘o’
The charcter ‘o’ is overwritten by w
backspace
(b)
cout<<“Good morningb”;
cout<<“Welcome friends”;
Good morninWelcome friends
The b character when encountered by the compiler converts to a backspace.
The cursor moves one space backward in the output when this character is encountered
Here the b makes the cursor move one
space backward to ‘g’. The next cout
statement will display the message
overriding the character ‘g’
An example program to demonstrate (n),
(b) & (t)
#include <iostream.h>
void main()
{
cout<< “Hello n world”;
cout<<“n welcome t to”;
cout<<“the worldn of t
programmingn”;
cout<<“Learbn to bcode”;
}
Hello
world
welcome to the world
of programming
Lean tocode
Operators in
C++
The symbols that are used to form expressions to represent equations or logical sequences
In c++ are known as operators. C++ has a number of operators which shall be discussed in detail
In a separate chapter.
Operators
Arithmetic
Logical Relational
Special
Comments in
C++
Comments are the lines that compiler ignores while compiling or executing
the program.
There are two types of comments in C++: Single line and multiline
// this is a constant
Single
line
/* This program
calculates
the sum of two
numbers*/
Multi
line
An example program to demonstrate the use
of comments
/* Name :Ankit Jain
Roll No: 2
WAP Program to display message on new line
Date: 15/4/2017 */
#include <iostream.h>
void main()
{
cout<< “Hello n world”;// this line displays text with a newline
}
Multi line
Comment
Single line
Comment
Types of
Errors
There are many types of errors that are encountered during the compilation and execution of a program .
Errors
in C++
Syntax
Logical
Run
Time
Linker
Syntax Errors
• Every language has a predefined set of its symbols and characters
which are supposed to be used while forming programs. These sets
are also known as the syntax or grammar of the language.
• These are common error and can be easily corrected.
• These are produced when we translate the source code from high
level language to machine language. Thus they are generated
when a program is compiled.
• e.g cuot<<endl; This line will produce a syntax error as there is a
grammatical mistake in the word cout . It is misspelled as cuot.
Logical Errors
• A logical error is simply an incorrect translation of either the
problem statement or the algorithm.
• For eg. We want to calculate the average of 4 numbers say a,
b,c,d.
• If we write it as a+b+c+d/4, we will get the wrong answer.
• This is because as division has the higher precedence than sum
first d/4 will take place and then the result will be added to
a+b+c.
• Thus we need to put brackets like (a+b+c+d)/4 to get the correct
output.
Linker Errors
• Errors appear during linking process e.g if the word main written
as mian . The program will compile correctly but while linking the
linking window will display errors instead of success.
Run time Errors
• An abnormal program termination during execution is known as
Run time Error.
• e.g. If we are writing a statement X = ( A + B) /C ;
•
• the above statement is grammatically correct and also produces
correct result. But if we gave value 0 to the variable c, this
statement will attempt a division by 0 which will result in illegal
program termination. Error will not be found until the program
will be executed because of that it is termed as run time error.
Output
Manipulators
Manipulators are the operators used with the insertion operator << to modify or manipulate the way data is displayed
There are two types of manipulators endl and setw.
.
Output
manipulators
endl
setw()
endl
manipulator
The endl manipulator outputs new line .
It takes the compiler to the end the line of display.
cout << “ SRDAV School”<<endl;
cout<< “ Teachers Orientation”;
SRDAV School
Teachers Orientation
setw()
manipulator
The setw manipulator causes the value of the variable or a number ( or string) that follows it
in the stream to be printed within a field n characters wide where n is the arguments in setw (n). The function
requires a header file, <iomanip.h>
cout<<“a”<<setw(6)<<“b”<<" are the values to be
printed";
a b are the values to be printed
The statement will display the message with 6 spaces between a and b.
COLUMN A COLUMN B
1.The smallest executable unit in a program a. Keywords
2. They are used to represent certain sequences in C++ b. Literals
3.Name given to any part of a program c. Operators
4.The data items which never change their value throughout
the program run
d. Tokens
5. Words having a special meaning to the language e. Identifiers
6.The symbols that are used to form expressions f. Backslash character constants
TEST YOURSELF
Match contents of column A with column B

Mais conteúdo relacionado

Mais procurados

Mais procurados (19)

Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
Expressions in c++
 Expressions in c++ Expressions in c++
Expressions in c++
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Basics of c++
Basics of c++ Basics of c++
Basics of c++
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 

Semelhante a Getting started in c++

Semelhante a Getting started in c++ (20)

C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptx
 
Chapter3
Chapter3Chapter3
Chapter3
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Chapter2
Chapter2Chapter2
Chapter2
 
C programming
C programmingC programming
C programming
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
Intro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample ProgramIntro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample Program
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C programming
C programmingC programming
C programming
 
C programming
C programmingC programming
C programming
 
Msc prev completed
Msc prev completedMsc prev completed
Msc prev completed
 
Msc prev updated
Msc prev updatedMsc prev updated
Msc prev updated
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 

Mais de Neeru Mittal

Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptxNeeru Mittal
 
Brain Storming techniques in Python
Brain Storming techniques in PythonBrain Storming techniques in Python
Brain Storming techniques in PythonNeeru Mittal
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python PandasNeeru Mittal
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and TricksNeeru Mittal
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV ConnectivityNeeru Mittal
 
Working of while loop
Working of while loopWorking of while loop
Working of while loopNeeru Mittal
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++Neeru Mittal
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arraysNeeru Mittal
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
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++Neeru Mittal
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 

Mais de Neeru Mittal (16)

Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptx
 
Brain Storming techniques in Python
Brain Storming techniques in PythonBrain Storming techniques in Python
Brain Storming techniques in Python
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and Tricks
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV Connectivity
 
Working of while loop
Working of while loopWorking of while loop
Working of while loop
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Arrays
ArraysArrays
Arrays
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
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++
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 

Último

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Getting started in c++

  • 3. C++ Character Set • A character set of a language consists of any of the letters, digits or special symbols that can be used to form the commands in that language. The C++ character set consists of : Alphabets A-Z a-z Digits 0-9 Special Symbols #, ||+ -* ^ = !=; : & # [] {} < > . ‘ ‘
  • 4. Tokens in C++ Token Keywords Identifier Literal Operator The smallest executable unit in a program is known as token. A token can be any keyword, Identifier ,Literal, Punctuator or Operator.
  • 5. Keywords in C++ Examples of keywords public void float class Signed private These are the reserved words used by the compiler. They have a certain meaning for the language They cannot be used as identifiers. NOTE: All the keywords are written in small letters.
  • 6. Identifiers in C++ Examples of identifiers rollno Change_no student Employee An identifier is a name given to any entity of a program. It is used to identify any variable, function, class , structure etc in c++. It may consist of a combination of letters & numbers. NOTE: C++ is case sensitive as it treats upper and lower case letters differently so an identifier Rollno will be diiferent from rollno.
  • 7. Literals in C++ LiteralsInteger Character Floating point String Backslash character constants The data items which never change their value throughout the program run. There are several kind of literals which we shall discuss in detail in the next chapter We shall discuss Backslash character constants here.
  • 8. Backslash character constants • These are also known as escape sequences. • They are used to represent certain sequences such as newline in C++ . • When certain letters are preceded by a backslash they will have special meaning in the language and they are used to represent sequences such as newline (n) or tab (t) or backspace(b). • Let us take a look at each of these.
  • 9. Newline (n) cout<<“Goodn morning”; Good morning cout<<“”Good morning”; Good mo rning cout<<“Letn”; cout<<“the mouse n in”; Let the mouse in The newline character when encountered by the compiler converts to a carriage return. Any text or data following it appears on the next line. IT is used to display output on the Next line.
  • 10. Tab (t) cout<<“Goodt morning”; Good morning cout<<“”Good mot rning”; Good mo rning The t character when encountered by the compiler converts to a tab. Any text or data following it appears after 8 spaces.
  • 11. backspace (b) cout<<“Hellobworld”; Hellworld The b character when encountered by the compiler converts to a backspace. The cursor moves one space backward in the output when this character is encountered Here the b makes the cursor move one space backward to ‘o’ The charcter ‘o’ is overwritten by w
  • 12. backspace (b) cout<<“Good morningb”; cout<<“Welcome friends”; Good morninWelcome friends The b character when encountered by the compiler converts to a backspace. The cursor moves one space backward in the output when this character is encountered Here the b makes the cursor move one space backward to ‘g’. The next cout statement will display the message overriding the character ‘g’
  • 13. An example program to demonstrate (n), (b) & (t) #include <iostream.h> void main() { cout<< “Hello n world”; cout<<“n welcome t to”; cout<<“the worldn of t programmingn”; cout<<“Learbn to bcode”; } Hello world welcome to the world of programming Lean tocode
  • 14. Operators in C++ The symbols that are used to form expressions to represent equations or logical sequences In c++ are known as operators. C++ has a number of operators which shall be discussed in detail In a separate chapter. Operators Arithmetic Logical Relational Special
  • 15. Comments in C++ Comments are the lines that compiler ignores while compiling or executing the program. There are two types of comments in C++: Single line and multiline // this is a constant Single line /* This program calculates the sum of two numbers*/ Multi line
  • 16. An example program to demonstrate the use of comments /* Name :Ankit Jain Roll No: 2 WAP Program to display message on new line Date: 15/4/2017 */ #include <iostream.h> void main() { cout<< “Hello n world”;// this line displays text with a newline } Multi line Comment Single line Comment
  • 17. Types of Errors There are many types of errors that are encountered during the compilation and execution of a program . Errors in C++ Syntax Logical Run Time Linker
  • 18. Syntax Errors • Every language has a predefined set of its symbols and characters which are supposed to be used while forming programs. These sets are also known as the syntax or grammar of the language. • These are common error and can be easily corrected. • These are produced when we translate the source code from high level language to machine language. Thus they are generated when a program is compiled. • e.g cuot<<endl; This line will produce a syntax error as there is a grammatical mistake in the word cout . It is misspelled as cuot.
  • 19. Logical Errors • A logical error is simply an incorrect translation of either the problem statement or the algorithm. • For eg. We want to calculate the average of 4 numbers say a, b,c,d. • If we write it as a+b+c+d/4, we will get the wrong answer. • This is because as division has the higher precedence than sum first d/4 will take place and then the result will be added to a+b+c. • Thus we need to put brackets like (a+b+c+d)/4 to get the correct output.
  • 20. Linker Errors • Errors appear during linking process e.g if the word main written as mian . The program will compile correctly but while linking the linking window will display errors instead of success.
  • 21. Run time Errors • An abnormal program termination during execution is known as Run time Error. • e.g. If we are writing a statement X = ( A + B) /C ; • • the above statement is grammatically correct and also produces correct result. But if we gave value 0 to the variable c, this statement will attempt a division by 0 which will result in illegal program termination. Error will not be found until the program will be executed because of that it is termed as run time error.
  • 22. Output Manipulators Manipulators are the operators used with the insertion operator << to modify or manipulate the way data is displayed There are two types of manipulators endl and setw. . Output manipulators endl setw()
  • 23. endl manipulator The endl manipulator outputs new line . It takes the compiler to the end the line of display. cout << “ SRDAV School”<<endl; cout<< “ Teachers Orientation”; SRDAV School Teachers Orientation
  • 24. setw() manipulator The setw manipulator causes the value of the variable or a number ( or string) that follows it in the stream to be printed within a field n characters wide where n is the arguments in setw (n). The function requires a header file, <iomanip.h> cout<<“a”<<setw(6)<<“b”<<" are the values to be printed"; a b are the values to be printed The statement will display the message with 6 spaces between a and b.
  • 25. COLUMN A COLUMN B 1.The smallest executable unit in a program a. Keywords 2. They are used to represent certain sequences in C++ b. Literals 3.Name given to any part of a program c. Operators 4.The data items which never change their value throughout the program run d. Tokens 5. Words having a special meaning to the language e. Identifiers 6.The symbols that are used to form expressions f. Backslash character constants TEST YOURSELF Match contents of column A with column B