Getting started with c++


Published on

This ppt obout getting started with C++ in 11 class in cbse schools.S

Published in: Education, Technology
  • Be the first to comment

Getting started with c++

  1. 1. Computer Project Work <ul><li>Getting started with C++ </li></ul><ul><li>Guided by:- Prepared by:- </li></ul><ul><li>M. Ravi Kiran (sir) K. Durga Prasad </li></ul><ul><li>T.G.T computer. X1 class </li></ul><ul><li>M.P.C.Computers </li></ul>
  2. 2. 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. INTRODUCTION
  3. 3. C++ CHARACTER SET <ul><li>Character set is a set of valid characters that a language can recognise. A character represents any letter, digit, or any other sign. </li></ul><ul><li>Letters A-Z, a-z </li></ul><ul><li>Digits 0-9 </li></ul><ul><li>Special Symbols Space + - * / ^ ( ) [ ] { } = != < > . ‘ “ $ , ; : % ! & ? _(underscore) # <= >= @ </li></ul><ul><li>White Spaces Blank spaces, Horizontal tab, Carriage return, New line, Form feed. </li></ul><ul><li>Other Characters C++ can process any of the 256 ASCII characters as data or as literals. </li></ul>
  4. 4. TOKENS(LEXICAL UNITS) <ul><li>The smallest individual unit in a program is known as a Token or lexical unit. </li></ul><ul><li>Types of Tokens </li></ul><ul><li>Keywords </li></ul><ul><li>Identifiers </li></ul><ul><li>Literals </li></ul><ul><li>Punctuators </li></ul><ul><li>Operators </li></ul>
  5. 5. KEYWORDS <ul><li>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. </li></ul>
  6. 6. Some of the keywords in c++ <ul><li>asm continue float new signed try </li></ul><ul><li>auto default for operator sizeof typedef </li></ul><ul><li>break delete friend private static union </li></ul><ul><li>case do goto protected struct unsigned </li></ul><ul><li>catch double if public switch virtual </li></ul><ul><li>char else inline register template void </li></ul><ul><li>class enum int return this volatile </li></ul><ul><li>const extern long short throw while </li></ul>
  7. 7. Identifiers <ul><li>Identifiers are names of the program given by user. </li></ul><ul><li>Rules to write identifiers </li></ul><ul><li>Do not start with digits. </li></ul><ul><li>No special symbols are used except _(underscore). </li></ul><ul><li>No spaces are used. </li></ul><ul><li>Examples:- myfile , date9_2_7_6 </li></ul>
  8. 8. Literals <ul><li>Literals (constants) are data items that never change their value during a program run. </li></ul><ul><li>Types of Literals: </li></ul><ul><li>Integer constant </li></ul><ul><li>Floating constants </li></ul><ul><li>Character constant </li></ul><ul><li>String literal </li></ul>
  9. 9. Integer constant <ul><li>Integer constants are whole numbers without any fractional part. </li></ul><ul><li>Three types of Integer constants </li></ul><ul><li>Decimal Integer constant </li></ul><ul><li>Octal Integer constant </li></ul><ul><li>Hexadecimal Integer constant </li></ul>
  10. 10. Decimal Integer constant <ul><li>An integer constant consisting of a sequence of digits is taken to be decimal integer constant unless it begins with 0 (digit zero). </li></ul><ul><li>Example:- 1296, 5642, 12, +69,- 23,etc., </li></ul>
  11. 11. Octal Integer constant <ul><li>A sequence of digits starting with0(digit zero) is taken to be an octal integer. </li></ul><ul><li>Example:-123, 456, etc., </li></ul>
  12. 12. Hexadecimal Integer constant <ul><li>A sequence of digits preceded by 0x or 0X is taken to be an hexadecimal integer. </li></ul><ul><li>Example:-4B6, A43,etc., </li></ul>
  13. 13. Floating Constants <ul><li>Floating constants are also called as Real constants </li></ul><ul><li>Real constants are numbers having fractional parts. These may be written in one of the two forms called fractional form or the exponent form. </li></ul><ul><li>Examples:-2.0, 3.5, 8.6, etc., </li></ul>
  14. 14. Character constants <ul><li>A Character constant is one character enclosed in single quotes, as in ‘z’. </li></ul><ul><li>Examples:- ‘a’, ‘b’, etc., </li></ul>
  15. 15. Escape sequences <ul><li>a Audible sound </li></ul><ul><li>b back space </li></ul><ul><li>f Formfeed </li></ul><ul><li>n Newline or Linefeed </li></ul><ul><li>r Carriage return </li></ul><ul><li>t Horizontal tab </li></ul><ul><li>v Vertical tab </li></ul><ul><li> Backslash </li></ul><ul><li>’ single quote </li></ul><ul><li>” double quote </li></ul><ul><li>? Question mark </li></ul><ul><li>on Octal number </li></ul><ul><li>xHn Hexadecimal number </li></ul><ul><li>0 Null </li></ul>
  16. 16. String Literals <ul><li>Multiple character constants are treated as string literals. </li></ul><ul><li>Examples:-”a” , “ade”, etc., </li></ul>
  17. 17. Punctuators <ul><li>The following characters are used as punctuators. </li></ul><ul><li>[ ] ( ) { } , ; : * … = # </li></ul><ul><li>Brackets [ ] opening and closing brackets indicate single and multidimensional array subscripts. </li></ul><ul><li>Parenthesis ( ) these indicate function calls and function parameters. </li></ul>
  18. 18. <ul><li>Braces { } these indicates the start and end of a compound statement. </li></ul><ul><li>Comma , it is used as separator in a function argument list. </li></ul><ul><li>Semicolon ; it is used as statement terminator. </li></ul><ul><li>Collon : it indicates a labeled statement. </li></ul><ul><li>Asterisk * it is used for pointer declaration. </li></ul>
  19. 19. <ul><li>Ellipsis … Ellipsis (...) are used in the formal argument lists of the function prototype to indicate a variable number of argument. </li></ul><ul><li>Equal to sign = It is used for variable initialisation and an assignment operator in expressions. </li></ul><ul><li>Pound sign # this sign is used for preprocessor directive. </li></ul>
  20. 20. Operators <ul><li>Operators are tokens that trigger some computation when applied to variables and other objects in an expression. </li></ul><ul><li>Types of operators </li></ul><ul><li>Unary operators </li></ul><ul><li>Binary operators </li></ul><ul><li>Ternary operators </li></ul>
  21. 21. Unary operators <ul><li>Unary operators are those operators that require one operator to operate upon. </li></ul><ul><li>Examples :- +45, 5, -636,etc., </li></ul>
  22. 22. Some unary operators <ul><li>& Addresser operator </li></ul><ul><li>* Indirection operator </li></ul><ul><li>+ Unary plus </li></ul><ul><li>- Unary minus </li></ul><ul><li>~ Bitwise complement </li></ul><ul><li>++ increment operator </li></ul><ul><li>-- decrement operator </li></ul><ul><li>! Logical negation </li></ul>
  23. 23. Binary operators <ul><li>Binary operators are those operators that require two operands to operate upon. </li></ul><ul><li>Types of Binary operators </li></ul><ul><li>Arithmetic operators </li></ul><ul><li>+( addition) –(subtraction) *(multiplication) /(division) %(reminder/modulus) </li></ul><ul><li>Logical operators </li></ul><ul><li>&& (Logical AND) || (Logical OR) </li></ul>
  24. 24. <ul><li>Relational operators </li></ul><ul><li>< (Less than) </li></ul><ul><li><=(Less than or equal to) </li></ul><ul><li>>(Greater than) </li></ul><ul><li>>=(greater than or equal to) </li></ul><ul><li>== (equal to) </li></ul><ul><li>!= (not equal to) </li></ul>
  25. 25. A First look at C++ Program <ul><li>Why include iostream.h ? </li></ul><ul><li>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. </li></ul>
  26. 26. Predefined streams in I/O Library <ul><li>A stream is simply a sequence of bytes. </li></ul><ul><li>The predefined stream objects for input, output, error as follows: </li></ul><ul><li>Cin cin stands for console input. </li></ul><ul><li>Cout cout stands for console output. </li></ul><ul><li>Cerr cerr stands for console error. </li></ul>
  27. 27. Comments in a C++ Program <ul><li>Comments are pieces of codes that the compiler discards or ignores or simply does not execute. </li></ul><ul><li>Types of comments: </li></ul><ul><li>Single line comments </li></ul><ul><li>Multiline or block comments </li></ul>
  28. 28. <ul><li>These comments begins with // are single line comments. The compiler simply ignores everything following // in that same line </li></ul><ul><li>Example:- </li></ul><ul><li>#include<iostream.h> </li></ul><ul><li>Void main() // the program about addition. </li></ul>Single line comment
  29. 29. Multi line comments <ul><li>The block comments, mark the beginning of comment with /* and end with */. That means, everything that falls between/* and*/ is considered as comment. </li></ul><ul><li>Example:- </li></ul><ul><li>#include<iostream.h> </li></ul><ul><li>Void main() /*the program is about addition*/ </li></ul>
  30. 30. Using I/O operators <ul><li>Output operator “ << “ </li></ul><ul><li>The output operator (“<<“), also called stream insertion operator is used to direct a value top standard output. </li></ul><ul><li>Input operator “ >> ” </li></ul><ul><li>The input operator(“>>“), also known as stream extraction operator is used to read a value from standard input. </li></ul>
  31. 31. <ul><li>Variable </li></ul><ul><li>A variable refers to a storage area whose contents can vary during processing. </li></ul><ul><li>Cascading of I/O operators </li></ul><ul><li>The multiple use of input or output operators(“>>”or”<<“) in one statement is called cascading of I/O operators. </li></ul>
  32. 32. Role of compiler <ul><li>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. </li></ul><ul><li>Types of errors: </li></ul><ul><li>Syntax Errors </li></ul><ul><li>Semantic Errors </li></ul><ul><li>Type Errors </li></ul><ul><li>Run-time Errors </li></ul><ul><li>Logical Errors </li></ul>
  33. 33. <ul><li>Syntax Errors are occurred when rules of the program is misused i.e., when grammatical rule of C++ is violated. </li></ul><ul><li>Ex:- int a, b (semicolon missing) </li></ul><ul><li>Semantic Errors are occur when statements not meaningful. </li></ul><ul><li>Ex:- x*y=z; </li></ul><ul><li>Type Errors are occurred when the data types are misused. </li></ul><ul><li>Ex:-int a; a=123.56; </li></ul>
  34. 34. <ul><li>Run-time Errors are occurred at the time of execution. </li></ul><ul><li>Logical Errors are occurred when the logic of program is not proper. </li></ul><ul><li>Ex:- ctr=1; </li></ul><ul><li>While (ctr>10) </li></ul><ul><li>{ </li></ul><ul><li>cout<<n*ctr; </li></ul><ul><li>ctr=ctr+1; </li></ul><ul><li>} </li></ul>
  35. 35. <ul><li>Thank You </li></ul><ul><li>Thank You </li></ul><ul><li>Thank You </li></ul><ul><li>Thank You </li></ul><ul><li>Thank You </li></ul><ul><li>Thank You </li></ul><ul><li>Thank You </li></ul><ul><li>Thank You </li></ul>