SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Basic Elements of C++
09/04/131 VIT - SCSE
By
G.SasiKumar., M.E., (Ph.D).,
Assistant Professor
School of Computing Science and Engineering
VIT University
Characters are used to form the words, numbers and
expressions.
 alphabets from A.....Z, a....z
all decimal digits from 0....9
characters , . ; : ?
‘ “ ! | /  ~ _ $ % # & ^
* - + < > ( ) [ ] { } Spaces
blank
New Line endl
09/04/132 VIT - SCSE
Character Set
Keywords and Identifiers
All keywords must be written in lowercase.
auto double int struct break
else long switch case enum register
Typedef char extern return union
const float short unsigned continue
for signed void default goto
sizeof volatile do if static while
Identifiers refer to the names of variables, functions and arrays.
These are user -defined names and consist of a sequence of letters
and digits.
09/04/133 VIT - SCSE
Data Types
09/04/134 VIT - SCSE
C++ Data Types
User Defined type
Structure
Union
Class
Enumeration
Built-in type Derived type
Array
Function
Pointer
Integral Floating
Character
Void
byte short int long
float double
Constants
Constants in C++ refer to fixed values that do not change
during the execution of a program.
C++ supports several types of constants as shown below: -
1. Numeric Constants
Integer Constants
Floating point (real) Constants
2. Character Constants
Single Character Constants
String Constants
09/04/135 VIT - SCSE
Integer Constants
Decimal integers consist of a set of digits from 0
through 9. The decimal integers can be positive or
negative.(base 10)
Octal integers consist of any combination of digits
from 0 through 7, with a leading zero.(base 8)
Hexadecimal integers consist of a sequence of digits 0
through 9 and alphabets from A (a) through F (f). The
letters 'A' (a) through 'F ' (f) represent the integers 10
through 15.(16)
09/04/136 VIT - SCSE
Floating-Point Constants
Floating-point constants are represented by numbers
containing fractional parts like in 549.4545.
Floating-point constants are also sometimes called as real
number constants.
09/04/137 VIT - SCSE
Single Character Constants
A character constant is a single character enclosed within a pair of single
quotes.
Example:
'A'
'3'
'?'
';'
' '
Constant ASCII value
'a' 97
'A' 65
'&' 38
';' 59
09/04/138 VIT - SCSE
String Constants
 A string constant is a sequence of characters enclosed
within a pair of double quotes.
The string constant may also include special characters,
numbers and blank spaces.
Example:
" Hello!"
" I'm going for shopping today. Will you come?"
" 549, The Mall, Shimla."
09/04/139 VIT - SCSE
Escape Sequences
Character Escape sequence
bell a
backspace b
horizontal tab t
vertical tab v
newline n
carriage return r
quotation mark "
apostrophe '
backslash 
null 0
09/04/1310 VIT - SCSE
Variables
A variable is an identifier that is used to represent a single data
item
Declaration
Definition
09/04/1311 VIT - SCSE
Operators
An operator is a symbol that tells the compiler to perform
specific mathematical or logical manipulations.
Arithmetic Operators
o Increment and Decrement Operators
Relational and Logical Operators
Assignment Operators
Ternary(Conditional) Operator
Sizeof Operator
Comma Operator
& Operator
 -> Operators(a->b -Member b of object pointed to by a )
09/04/1312 VIT - SCSE
Control Statements
Conditional Statements
If statement
If-else statement
Switch-case statement
Loop Statements
For loop
While loop
Do-while loop
Breaking control statements
Break
Continue
goto
09/04/1313 VIT - SCSE
Switch statement
switch(expression)
{ case constant_1:
statement;
break;
case constant_2:
statement;
break;
-----------------
case constant_n:
statement,
break;
default:
statement;
break;
}
09/04/1314 VIT - SCSE
//A program to display the name of the day in a week, depending upon the
number entered through the keyboard using the switch-case statement.
09/04/1315 VIT - SCSE
#include<iostream.h>
void main()
{
int day;
cout<<”Enter a number between 1 to
7”<<endl;
cin>>day;
switch(day)
{
case 1:
cout<<”Monday”<<endl;
break;
case 2:
cout<<”Tuesday”<<endl;
break;
case 3:
cout<<”Wednesday”<<endl;
break;
case 4:
cout<<”Thursday”<<endl;
break;
case 5:
cout<<”Friday”<<endl;
break;
case 6:
cout<<”Saturday”<<endl;
break;
case 7:
cout<<”Sunday”<<endl;
break;
}
}
For statement
//A program to find the sum and average of given numbers.
09/04/1316 VIT - SCSE
#include<iostream.h>
void main()
{
int n;
cout<<”How many
numbers?”<<endl;
cin>>n;
float sum=0;
float a=0;
float a;
for(int i=0; i<=n-1;i++)
{
cout<<”Enter a
number”<<endl;
cin>>a;
sum=sum+a;
}
float av;
av=sum/n;
cout<<”sum=”<<sum<<endl;
cout<<”Average=”<<av<<endl;
}
Nested For Statement
A program to display a name 15 times using the nested for loops.
#include<iostream.h>
void main()
{
cout<<”Nested for loop”;
for(int i=0; i<=2; i++)
{
cout<<i;
for(int j=0;j<=2;j++)
{
cout<<j;
for(int k=0;k<=2;k++)
{
cout<<k;
}}}}
09/04/1317 VIT - SCSE
While statement
{
sum+=digit;
digit++;
}
cout<<“1+2+3+.....
+100=“<<sum<<endl;
}
09/04/1318 VIT - SCSE
//program to find the sum
of the first 100 natural
numbers
#include<iostream.h>
void main()
{
int sum,digit;
sum=0;
digit=1;
while(digit<=100)
Do while loop
do
{
sum=sum+digit;
digit=digit+2;
}
while(digit<=max);
cout<<“2+4+...=“<<max<<“su
m=“;
}
09/04/1319 VIT - SCSE
//program to find the sum of
the even numbers using do-
while loop.
#include<iostream.h>
void main()
{
int max,sum,digit;
digit=2;
cout<<“enter a number“;
cin>>max;
sum=0;
Break statement
if(a<=0)
{
cout<<”Zero or negative
value found”;
break;
}
i++;
}
}
09/04/1320 VIT - SCSE
#include<iostream.h>
void main()
{
int a,i;
i=0;
while(i<=10)
{
cout<<”Enter a
number”<<endl;
cin>>a;
Continue statement
if(a<=0)
{
cout<<”Zero or negative
value found”;
continue;
}
i++;
}
}
09/04/1321 VIT - SCSE
#include<iostream.h>
void main()
{
int a,i;
i=0;
while(i<=10)
{
cout<<”Enter a
number”<<endl;
cin>>a;
Goto statement
output1:
cout<<”largest value=”<<a<<endl;
goto stop;
output2:
cout<<”largest value=”<<b<<endl;
stop:
getch();
}
09/04/1322 VIT - SCSE
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
cout<<”Enter two
numbers;
cin>>a>>b;
if(a>b)
goto output1;
else
goto output2;
goto label;

Weitere ähnliche Inhalte

Was ist angesagt?

Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programmingChitrank Dixit
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageRai University
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in Crgnikate
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageRai University
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data typesPratik Devmurari
 

Was ist angesagt? (20)

Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
Variable declaration
Variable declarationVariable declaration
Variable declaration
 
Variable declaration
Variable declarationVariable declaration
Variable declaration
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c language
 
Character set of c
Character set of cCharacter set of c
Character set of c
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
Pengaturcaraan asas
Pengaturcaraan asasPengaturcaraan asas
Pengaturcaraan asas
 
C tokens
C tokensC tokens
C tokens
 
2 1 data
2 1  data2 1  data
2 1 data
 
Basics of c
Basics of cBasics of c
Basics of c
 
C language basics
C language basicsC language basics
C language basics
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
Data type in c
Data type in cData type in c
Data type in c
 

Ähnlich wie 3 intro basic_elements

Ähnlich wie 3 intro basic_elements (20)

1.getting started with c
1.getting started with c1.getting started with c
1.getting started with c
 
PROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptxPROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptx
 
Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Module 1 PCD.docx
Module 1 PCD.docxModule 1 PCD.docx
Module 1 PCD.docx
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
C++
C++C++
C++
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
 
U2.ppt
U2.pptU2.ppt
U2.ppt
 
U2.ppt
U2.pptU2.ppt
U2.ppt
 
Cnotes
CnotesCnotes
Cnotes
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
 
fds unit1.docx
fds unit1.docxfds unit1.docx
fds unit1.docx
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 

Mehr von Docent Education

Mehr von Docent Education (15)

17 files and streams
17 files and streams17 files and streams
17 files and streams
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
13 exception handling
13 exception handling13 exception handling
13 exception handling
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
12 constructors invocation and data members initialization
12 constructors invocation and data members initialization12 constructors invocation and data members initialization
12 constructors invocation and data members initialization
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
 
10 inheritance
10 inheritance10 inheritance
10 inheritance
 
7 class objects
7 class objects7 class objects
7 class objects
 
6 pointers functions
6 pointers functions6 pointers functions
6 pointers functions
 
5 array
5 array5 array
5 array
 
4 Type conversion functions
4 Type conversion functions4 Type conversion functions
4 Type conversion functions
 
1 Intro Object Oriented Programming
1  Intro Object Oriented Programming1  Intro Object Oriented Programming
1 Intro Object Oriented Programming
 
2 Intro c++
2 Intro c++2 Intro c++
2 Intro c++
 
unit-1-intro
 unit-1-intro unit-1-intro
unit-1-intro
 

Kürzlich hochgeladen

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

3 intro basic_elements

  • 1. Basic Elements of C++ 09/04/131 VIT - SCSE By G.SasiKumar., M.E., (Ph.D)., Assistant Professor School of Computing Science and Engineering VIT University
  • 2. Characters are used to form the words, numbers and expressions.  alphabets from A.....Z, a....z all decimal digits from 0....9 characters , . ; : ? ‘ “ ! | / ~ _ $ % # & ^ * - + < > ( ) [ ] { } Spaces blank New Line endl 09/04/132 VIT - SCSE Character Set
  • 3. Keywords and Identifiers All keywords must be written in lowercase. auto double int struct break else long switch case enum register Typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while Identifiers refer to the names of variables, functions and arrays. These are user -defined names and consist of a sequence of letters and digits. 09/04/133 VIT - SCSE
  • 4. Data Types 09/04/134 VIT - SCSE C++ Data Types User Defined type Structure Union Class Enumeration Built-in type Derived type Array Function Pointer Integral Floating Character Void byte short int long float double
  • 5. Constants Constants in C++ refer to fixed values that do not change during the execution of a program. C++ supports several types of constants as shown below: - 1. Numeric Constants Integer Constants Floating point (real) Constants 2. Character Constants Single Character Constants String Constants 09/04/135 VIT - SCSE
  • 6. Integer Constants Decimal integers consist of a set of digits from 0 through 9. The decimal integers can be positive or negative.(base 10) Octal integers consist of any combination of digits from 0 through 7, with a leading zero.(base 8) Hexadecimal integers consist of a sequence of digits 0 through 9 and alphabets from A (a) through F (f). The letters 'A' (a) through 'F ' (f) represent the integers 10 through 15.(16) 09/04/136 VIT - SCSE
  • 7. Floating-Point Constants Floating-point constants are represented by numbers containing fractional parts like in 549.4545. Floating-point constants are also sometimes called as real number constants. 09/04/137 VIT - SCSE
  • 8. Single Character Constants A character constant is a single character enclosed within a pair of single quotes. Example: 'A' '3' '?' ';' ' ' Constant ASCII value 'a' 97 'A' 65 '&' 38 ';' 59 09/04/138 VIT - SCSE
  • 9. String Constants  A string constant is a sequence of characters enclosed within a pair of double quotes. The string constant may also include special characters, numbers and blank spaces. Example: " Hello!" " I'm going for shopping today. Will you come?" " 549, The Mall, Shimla." 09/04/139 VIT - SCSE
  • 10. Escape Sequences Character Escape sequence bell a backspace b horizontal tab t vertical tab v newline n carriage return r quotation mark " apostrophe ' backslash null 0 09/04/1310 VIT - SCSE
  • 11. Variables A variable is an identifier that is used to represent a single data item Declaration Definition 09/04/1311 VIT - SCSE
  • 12. Operators An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Arithmetic Operators o Increment and Decrement Operators Relational and Logical Operators Assignment Operators Ternary(Conditional) Operator Sizeof Operator Comma Operator & Operator  -> Operators(a->b -Member b of object pointed to by a ) 09/04/1312 VIT - SCSE
  • 13. Control Statements Conditional Statements If statement If-else statement Switch-case statement Loop Statements For loop While loop Do-while loop Breaking control statements Break Continue goto 09/04/1313 VIT - SCSE
  • 14. Switch statement switch(expression) { case constant_1: statement; break; case constant_2: statement; break; ----------------- case constant_n: statement, break; default: statement; break; } 09/04/1314 VIT - SCSE
  • 15. //A program to display the name of the day in a week, depending upon the number entered through the keyboard using the switch-case statement. 09/04/1315 VIT - SCSE #include<iostream.h> void main() { int day; cout<<”Enter a number between 1 to 7”<<endl; cin>>day; switch(day) { case 1: cout<<”Monday”<<endl; break; case 2: cout<<”Tuesday”<<endl; break; case 3: cout<<”Wednesday”<<endl; break; case 4: cout<<”Thursday”<<endl; break; case 5: cout<<”Friday”<<endl; break; case 6: cout<<”Saturday”<<endl; break; case 7: cout<<”Sunday”<<endl; break; } }
  • 16. For statement //A program to find the sum and average of given numbers. 09/04/1316 VIT - SCSE #include<iostream.h> void main() { int n; cout<<”How many numbers?”<<endl; cin>>n; float sum=0; float a=0; float a; for(int i=0; i<=n-1;i++) { cout<<”Enter a number”<<endl; cin>>a; sum=sum+a; } float av; av=sum/n; cout<<”sum=”<<sum<<endl; cout<<”Average=”<<av<<endl; }
  • 17. Nested For Statement A program to display a name 15 times using the nested for loops. #include<iostream.h> void main() { cout<<”Nested for loop”; for(int i=0; i<=2; i++) { cout<<i; for(int j=0;j<=2;j++) { cout<<j; for(int k=0;k<=2;k++) { cout<<k; }}}} 09/04/1317 VIT - SCSE
  • 18. While statement { sum+=digit; digit++; } cout<<“1+2+3+..... +100=“<<sum<<endl; } 09/04/1318 VIT - SCSE //program to find the sum of the first 100 natural numbers #include<iostream.h> void main() { int sum,digit; sum=0; digit=1; while(digit<=100)
  • 19. Do while loop do { sum=sum+digit; digit=digit+2; } while(digit<=max); cout<<“2+4+...=“<<max<<“su m=“; } 09/04/1319 VIT - SCSE //program to find the sum of the even numbers using do- while loop. #include<iostream.h> void main() { int max,sum,digit; digit=2; cout<<“enter a number“; cin>>max; sum=0;
  • 20. Break statement if(a<=0) { cout<<”Zero or negative value found”; break; } i++; } } 09/04/1320 VIT - SCSE #include<iostream.h> void main() { int a,i; i=0; while(i<=10) { cout<<”Enter a number”<<endl; cin>>a;
  • 21. Continue statement if(a<=0) { cout<<”Zero or negative value found”; continue; } i++; } } 09/04/1321 VIT - SCSE #include<iostream.h> void main() { int a,i; i=0; while(i<=10) { cout<<”Enter a number”<<endl; cin>>a;
  • 22. Goto statement output1: cout<<”largest value=”<<a<<endl; goto stop; output2: cout<<”largest value=”<<b<<endl; stop: getch(); } 09/04/1322 VIT - SCSE #include<iostream.h> #include<conio.h> void main() { int a,b; cout<<”Enter two numbers; cin>>a>>b; if(a>b) goto output1; else goto output2; goto label;