Getting started with c++.pptx
-
Upload
akash-baruah -
Category
Education
-
view
178 -
download
0
description
Transcript of Getting started with c++.pptx
![Page 1: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/1.jpg)
Computer Project Work
Getting started with C++
Prepared by:-Ranjan Das & Akash deep
baruah.
![Page 2: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/2.jpg)
INTRODUCTIONIn 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.
![Page 3: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/3.jpg)
C++ CHARACTER SET
Character set is a set of valid characters that a language can recognize. 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.
![Page 4: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/4.jpg)
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
![Page 5: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/5.jpg)
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.
![Page 6: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/6.jpg)
Some of the keywords in c++
asm continue float new signed try auto default for operator sizeof typedefbreak delete friend private static unioncase do goto protected struct unsignedcatch double if public switch virtualchar else inline register template voidclass enum int return this volatileconst extern long short throw while
![Page 7: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/7.jpg)
Identifiers
Identifiers are names of the program given by user.
Rules to write identifiers1. Do not start with digits.2. No special symbols are used except
_(underscore).3. No spaces are used. Examples:- myfile , date9_2_7_6
![Page 8: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/8.jpg)
Literals
Literals (constants) are data items that never change their value during a program run.
Types of Literals:1. Integer constant2. Floating constants3. Character constant4. String literal
![Page 9: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/9.jpg)
Integer constant
Integer constants are whole numbers without any fractional part.
Three types of Integer constants1. Decimal Integer constant2. Octal Integer constant3. Hexadecimal Integer constant
![Page 10: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/10.jpg)
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.,
![Page 11: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/11.jpg)
Octal Integer constant
A sequence of digits starting with0(digit zero) is taken to be an octal integer.
Example:-123, 456, etc.,
![Page 12: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/12.jpg)
Hexadecimal Integer constant
A sequence of digits preceded by 0x or 0X is taken to be an hexadecimal integer.
Example:-4B6, A43,etc.,
![Page 13: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/13.jpg)
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.,
![Page 14: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/14.jpg)
Character constants
A Character constant is one character enclosed in single quotes, as in ‘z’.
Examples:- ‘a’, ‘b’, etc.,
![Page 15: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/15.jpg)
Escape sequences
\a Audible sound\b back space\f Formfeed\n Newline or Linefeed\r Carriage return\t Horizontal tab\v Vertical tab\\ Backslash\’ single quote\” double quote\? Question mark\on Octal number\xHn Hexadecimal number\0 Null
![Page 16: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/16.jpg)
String Literals
Multiple character constants are treated as string literals.
Examples:-”a” , “ade”, etc.,
![Page 17: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/17.jpg)
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.
![Page 18: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/18.jpg)
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.
Colon : it indicates a labeled statement. Asterisk * it is used for pointer
declaration.
![Page 19: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/19.jpg)
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 initialization and an assignment operator in expressions.
Pound sign # this sign is used for preprocessor directive.
![Page 20: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/20.jpg)
Operators
Operators are tokens that trigger some computation when applied to variables and other objects in an expression.
Types of operators1. Unary operators2. Binary operators3. Ternary operators
![Page 21: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/21.jpg)
Unary operators
Unary operators are those operators that require one operator to operate upon.
Examples :- +45, 5, -636,etc.,
![Page 22: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/22.jpg)
Some unary operators
& Addresser operator * Indirection operator + Unary plus - Unary minus ~ Bitwise complement ++ increment operator -- decrement operator ! Logical negation
![Page 23: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/23.jpg)
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)
![Page 24: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/24.jpg)
Relational operators < (Less than)<=(Less than or equal to) >(Greater than)>=(greater than or equal to) == (equal to)!= (not equal to)
![Page 25: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/25.jpg)
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.
![Page 26: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/26.jpg)
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.
![Page 27: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/27.jpg)
Comments in a C++ Program
Comments are pieces of codes that the compiler discards or ignores or simply does not execute.
Types of comments:1. Single line comments2. Multiline or block comments
![Page 28: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/28.jpg)
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.
![Page 29: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/29.jpg)
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*/
![Page 30: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/30.jpg)
Using I/O operators
Output 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.
![Page 31: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/31.jpg)
Variable A variable refers to a storage area
whose contents can vary during processing.
Cascading of I/O operators The multiple use of input or output
operators(“>>”or”<<“) in one statement is called cascading of I/O operators.
![Page 32: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/32.jpg)
Role of compiler
A part of the compiler’s 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 Errors2. Semantic Errors3. Type Errors4. Run-time Errors5. Logical Errors
![Page 33: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/33.jpg)
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;
![Page 34: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/34.jpg)
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; }
![Page 35: Getting started with c++.pptx](https://reader038.fdocuments.us/reader038/viewer/2022103001/55910f181a28ab7e2f8b45a3/html5/thumbnails/35.jpg)
THANK YOU