Secure your environment with UiPath and CyberArk technologies - Session 1
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