Você está na página 1de 35

Computer Project Work

Getting

started with C++ Prepared by:K. Durga Prasad

Guided by:M. Ravi Kiran (sir)

T.G.T computer.

X1 class M.P.C.Computers

INTRODUCTION
In 1980s bjarne Stroustrup decided to extend the C language by adding some features from his favourite language Simula 67. Simula 67 was one of the earliest object oriented language. Bjarne Stroustrup called it C with classes. Later Rick Mascitti renamed as C++. Ever since its birth, C++ evolved to cope with problems encountered by users, and though discussions.

C++ CHARACTER SET

Character set is a set of valid characters that a language can recognise. A character represents any letter, digit, or any other sign. Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] { } = != < > . $ , ; : % ! & ? _(underscore) # <= >= @ White Spaces Blank spaces, Horizontal tab, Carriage return, New line, Form feed. Other Characters C++ can process any of the 256 ASCII characters as data or as literals.

TOKENS(LEXICAL UNITS)
The smallest individual unit in a program is known as a Token or lexical unit. Types of Tokens Keywords Identifiers Literals Punctuators Operators

KEYWORDS
Keywords

are the words that convey a special meaning to the language compiler. These are reserved for special purpose and must not be used as normal identifier names.

Some of the keywords in c++


asm continue float new signed try auto default for operator sizeof typedef break delete friend private static union case do goto protected struct unsigned catch double if public switch virtual char else inline register template void class enum int return this volatile const extern long short throw while

Identifiers
Identifiers are names of the program given by user. Rules to write identifiers 1. Do not start with digits. 2. No special symbols are used except _(underscore). 3. No spaces are used. Examples:- myfile , date9_2_7_6

Literals
Literals (constants) are data items that never change their value during a program run. Types of Literals: 1. Integer constant 2. Floating constants 3. Character constant 4. String literal

Integer constant

Integer constants are whole numbers without any fractional part.

Three types of Integer constants 1. Decimal Integer constant 2. Octal Integer constant 3. Hexadecimal Integer constant

Decimal Integer constant

An integer constant consisting of a sequence of digits is taken to be decimal integer constant unless it begins with 0 (digit zero). Example:- 1296, 5642, 12, +69,23,etc.,

Octal Integer constant

A sequence of digits starting with0(digit zero) is taken to be an octal integer. Example:-123, 456, etc.,

Hexadecimal Integer constant

A sequence of digits preceded by 0x or 0X is taken to be an hexadecimal integer. Example:-4B6, A43,etc.,

Floating Constants
Floating

constants are also called as Real constants Real constants are numbers having fractional parts. These may be written in one of the two forms called fractional form or the exponent form. Examples:-2.0, 3.5, 8.6, etc.,

Character constants
A

Character constant is one character enclosed in single quotes, as in z. b, etc.,

Examples:- a,

Escape sequences
\a \b \f \n \r \t \v \\ \ \ \? \on \xHn \0 Audible sound back space Formfeed Newline or Linefeed Carriage return Horizontal tab Vertical tab Backslash single quote double quote Question mark Octal number Hexadecimal number Null

String Literals
Multiple

character constants are treated as string literals. Examples:-a , ade, etc.,

Punctuators
The

following characters are used as punctuators. [ ] () { } , ; : * = # Brackets [ ] opening and closing brackets indicate single and multidimensional array subscripts. Parenthesis ( ) these indicate function calls and function parameters.

Braces { } these indicates the start and end of a compound statement. Comma , it is used as separator in a function argument list. Semicolon ; it is used as statement terminator. Collon : it indicates a labeled statement. Asterisk * it is used for pointer declaration.

Ellipsis Ellipsis (...) are used in the formal argument lists of the function prototype to indicate a variable number of argument. Equal to sign = It is used for variable initialisation and an assignment operator in expressions. Pound sign # this sign is used for preprocessor directive.

Operators

Operators are tokens that trigger some computation when applied to variables and other objects in an expression. Types of operators 1. Unary operators 2. Binary operators 3. Ternary operators

Unary operators
Unary operators are those operators that require one operator to operate upon. Examples :- +45, 5, -636,etc.,

Some unary operators


& * + ~ ++ -! Addresser operator Indirection operator Unary plus Unary minus Bitwise complement increment operator decrement operator Logical negation

Binary operators
Binary

operators are those operators that require two operands to operate upon. Types of Binary operators Arithmetic operators +(addition) (subtraction) *(multiplication) /(division) %(reminder/modulus) Logical operators && (Logical AND) || (Logical OR)

Relational

operators < (Less than) <=(Less than or equal to) >(Greater than) >=(greater than or equal to) == (equal to) != (not equal to)

A First look at C++ Program


Why

include iostream.h ? The header file iostream.h is included in every C++ program to implement input/output facilities. Input/output facilities are not defined within C++ language, but rather are implemented in a component of C++ standard library, iostream.h which is I/O library.

Predefined streams in I/O Library

A stream is simply a sequence of bytes.

The predefined stream objects for input, output, error as follows: 1. Cin cin stands for console input. 2. Cout cout stands for console output. 3. Cerr cerr stands for console error.

Comments in a C++ Program

1. 2.

Comments are pieces of codes that the compiler discards or ignores or simply does not execute. Types of comments: Single line comments Multiline or block comments

Single line comment


These

comments begins with // are single line comments. The compiler simply ignores everything following // in that same line Example:#include<iostream.h> Void main() // the program about addition.

Multi line comments


The

block comments, mark the beginning of comment with /* and end with */. That means, everything that falls between/* and*/ is considered as comment. Example:#include<iostream.h> Void main() /*the program is about addition*/

Using I/O operators


operator << The output operator (<<), also called stream insertion operator is used to direct a value top standard output. Input operator >> The input operator(>>), also known as stream extraction operator is used to read a value from standard input.
Output

Variable

A variable refers to a storage area whose contents can vary during processing. The multiple use of input or output operators(>>or<<) in one statement is called cascading of I/O operators.

Cascading of I/O operators

Role of compiler
A part of the compilers job is to analyze the program code for correctness. If the meaning of the program is correct, then a compiler can not detect errors. Types of errors: 1. Syntax Errors 2. Semantic Errors 3. Type Errors 4. Run-time Errors 5. Logical Errors

Syntax

Errors are occurred when rules of the program is misused i.e., when grammatical rule of C++ is violated. Ex:- int a, b (semicolon missing) Semantic Errors are occur when statements not meaningful. Ex:- x*y=z; Type Errors are occurred when the data types are misused. Ex:-int a; a=123.56;

Run-time

Errors are occurred at the time of execution. Logical Errors are occurred when the logic of program is not proper. Ex:- ctr=1; While (ctr>10) { cout<<n*ctr; ctr=ctr+1; }

Thank You

Thank You

Thank You

Thank You

Thank You

Thank You Thank You Thank You

Você também pode gostar