C++
Review of C++:-
C++ is an object oriented programming language.
Initially C++ was named as “C with classes”.
C++ was developed by Bjarne Stroustrup at AT and T Bell LAB, USA in early eighties.
Advantages/Features of C++ :
The C++ provides following advantages over any procedure oriented language such as C
language:
1) C++ is an incremented version of C language. So it is called as superset of C language.
Because all programs of C language can also in C++ language so it called superset/
incremented version of C language.
2) The important facilities added in C++ are classes, function overloading, operator
overloading etc.
3) C++ allows user to creates an abstract data types which inherits properties from
existing data types called as inheritance. So it supports reusability.
4) C++ supports polymorphism.
5) Any real life application such as editors, compiles, databases, communication
systems etc can be built by C++. 6) Object oriented libraries can be built by C++.
7) C++ programs can be easily implemented, maintained and expanded.
Differentiate between traditional procedure oriented programming approach
and object oriented programming approach.
POP (procedure oriented programming approach)
1) In this approach the problem are viewed as a sequence of things to be done.
2) Emphasis is doing things.
3) Large programs are divided into smaller programs known as functions.
4) Data are moves openly around the system from function to function.
5) Follows top-down approach in program design.
6) Examples : C language, VB, COBOL, PASCAL
OOP (object oriented programming approach)
1) In this the problems are decomposed into number of entities called as objects and
then build data and functions around these entities.
2) Emphasis is on the data rather than procedure.
,3) Programs are divided into number of runtime entities are called as objects.
4) Data are hidden and cannot be accessed by an external functions.
5) Follows bottom-up approach in program design.
6) Examples : C++, Smalltalk, Ada
C++ Character Sets:
Letters A-Z , a-z
Digits 0-9
Special Symbols Space + - * / ^ \ ( ) [ ] { } = != <>
.„“$,
; : % ! & ? _ # <= >= @
White Spaces Blank spaces, horizontal tab,
carriage
Return
Other Characters Any of the 256 ASCII character
Token:-The smallest individual unit in a program is known as token. Tokens used in
C++ are:
KEYWORDS :
Keywords are the certain reserved words that convey a special meaning to
the compiler. These are reserve for special purpose and must not be used as
identifier name.eg for , if, else , this , do, etc.
IDENTIFIERS:
Identifiers are programmer defined names given to the various program
elements such as variables, functions, arrays, objects, classes, etc.. It may
contain digits, letters and underscore, and must begin with a letter or
underscore. C++ is case sensitive as it treats upper and lower case letters
differently. The following are some valid identifiers:
Pen time580 s2e2r3 _dos _HJI3_JK
Constant:- A named memory location, whose contains cannot be changed
with in program execution is known as constant. OR
A constant is an identifier that denotes a storage location, which contains
cannot be varied during program execution.
Syntax for constant declaration is:
const datatypes constant_name = value ;
e.g.,
const float pi = 3,14f ;
LITERALS:
The data items which never change their value throughout the program run.
There are several kinds of literals:
Integer literals
Character literals
Floating literals
String literals
, Integer literals :
Integer literals are whole numbers without any fractional part. An integer
literal must have at least one digit and must not contain any decimal point. It
may contain either + or - sign. A number with no sign is assumed as positive.
C++ allows three types of integer literals:
(i) Decimal Integer Literals:- An integer literal without leading 0
(zero) is called decimal integer literals e.g., 123, 786 , +97 , etc.
(ii) Octal Integer Literals:- A sequence of octal digit starting with 0
(zero) is taken to be an octal integer literal ( zero followed by octal digits).
e.g., 0345, 0123 , etc.
(iii) Hexadecimal Integer Literals :- Hexadecimal Integer Literals
starts with 0x or 0X followed by any hexa digits. e.g., 0x9A45, 0X1234, etc.
Character literals:
Any single character enclosed within single quotes is a character literal.
e.g ‘ A’ , ‘3’
Floating literals:
Numbers which are having the fractional part are referred as floating literals
or real literals. It may be a positive or negative number. A number with no
sign is assumed to be a positive number.
e.g 2.0, 17.5, -0.00256
String Literals:
It is a sequence of character surrounded by double quotes. e.g., “abc” , “23”.
PUNCTUATORS:
The following characters are used as punctuators which are also known as separators
in C++
[ ]{ } ( ) , ; : * ……….. = #
Punctuator Name Function
[] Brackets These indicates single and
multidimensional array
subscripts
() Parenthesis These indicate function calls
and function parameters.
{} Braces Indicate the start and end of
compound statements.
; Semicolon This is a statement terminator.
, Comma It is used as a separator.
: Colon It indicates a labeled statement
* Asterisk It is used as a pointer
declaration
… Ellipsis These are used in the formal
argument lists of function
prototype to
indicate a variable number of
arguments.
= Equal to It is used as an assigning
operator.
# Pound sign This is used as preprocessor
directives.