#OOP_D_ITS - 3rd - Migration From C To C++
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

#OOP_D_ITS - 3rd - Migration From C To C++

on

  • 725 views

 

Statistics

Views

Total Views
725
Views on SlideShare
724
Embed Views
1

Actions

Likes
0
Downloads
21
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

#OOP_D_ITS - 3rd - Migration From C To C++ Presentation Transcript

  • 1. Migration: C to C++
    09/09/2009
    1
    Hadziq Fabroyir - Informatics ITS
  • 2. C/C++ Program Structure
    Operating
    System
    void function1()
    {
    //...
    return;
    }
    int main()
    {
    function1();
    function2();
    function3();
    return 0;
    }
    void function2()
    {
    //...
    return;
    }
    void function3()
    {
    //...
    return;
    }
    Operating
    System
  • 3. Naming Variable
    MUST
    Identifier / variable name can include letters(A-z), digits(0-9), and underscore(_)
    Identifier starts with letteror underscore
    Do NOT use keywordsas identifier
    Identifier in C++ is case-sensitive
    CONSIDER
    Usemeaningfullname
    Limit identifier length up to 31 characters, although it can have length up to 2048
    Avoid using identifiers that start with an underscore
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    3
  • 4. Keywords
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    4
  • 5. Declaring Variable
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    5
    int value;
    char[] firstName;
    Char[] address;
    int 9ball;
    long bigInt;
    System::String full_name;
    int count!;
    long class;
    float a234_djJ_685_abc___;
  • 6. Initializing Variable
    int value = 0;
    char[] firstName = “Budi”;
    long bigInt(100L);
    System::String^ full_name = “Budi Lagi”;
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    6
  • 7. Fundamental Data Types
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    7
  • 8. Literals
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    8
  • 9. Example of Data Types
    int main()
    {
    char c = 'A';
    wchar_t wideChar = L'9';
    int i = 123;
    long l = 10240L;
    float f = 3.14f;
    double d = 3.14;
    bool b = true;
    return 0;
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    9
  • 10. Enumerations
    Variable with specific sets of values
    Enum Day {Mon, Tues, Wed, Thurs, Fri, Sat, Sun};
    Day today = Mon;
    Enum Day {Mon = 1, Tues, Wed, Thurs, Fri, Sat, Sun};
    Day nextDay = Tues;
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    10
  • 11. Basic Input/Output Operations
    int main()
    {
    //declare and initialize variables
    int num1 = 0;
    int num2 = 0;
    //getting input from keyboard
    cin >> num1 >> num2;
    //output the variables value to command line
    cout << endl;
    cout << "Num1 : " << num1 << endl;
    cout << "Num2 : " << num2;
    return 0;
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    11
  • 12. Escape Sequence
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    12
  • 13. Basic Operators
    int main()
    {
    int a = 0;
    int b = 0;
    int c = 0;
    c = a + b;
    c = a - b;
    c = a * b;
    c = a / b;
    c = a % b;
    a = -b;
    return 0;
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    13
  • 14. Bitwise Operators
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    14
    & bitwise AND
    ~ bitwise NOT
    | bitwise OR
    ^ bitwise XOR
    >>shift right
    <<shift left
  • 15. Increment and Decrement Operators
    int main()
    {
    int a = 0;
    int b = 0;
    a++;
    b--;
    ++a;
    ++b;
    return 0;
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    15
  • 16. Shorthand Operators
    int main()
    {
    int a = 0;
    int b = 0;
    a += 3;
    b -= a;
    a *= 2;
    b /= 32;
    a %= b;
    return 0;
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    16
  • 17. Explicit Casting
    static_cast<the_type_to_convert_to>(expression)
    (the_type_to_convert_to)expression
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    17
  • 18. Constant Declaration
    int main()
    {
    const double rollwidth = 21.0;
    const double rolllength = 12.0*33.0;
    const double rollarea = rollwidth*rolllength;
    return 0;
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    18
  • 19. Declaring Namespace
    namespace MyNamespace
    {
    // code belongs to myNamespace
    }
    namespace OtherNamespace
    {
    // code belongs to otherNamespace
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    19
  • 20. Using Namespace
    #include <iostream>
    namespace myStuff
    {
    int value = 0;
    }
    int main()
    {
    std::cout << “enter an integer: “;
    std::cin >> myStuff::value;
    std::cout << “ You entered “ << myStuff::value << std:: endl;
    return 0;
    }
    #include <iostream>
    namespace myStuff
    {
    int value = 0;
    }
    using namespace myStuff;
    int main()
    {
    std::cout << “enter an integer: “;
    std::cin >> value;
    std::cout << “ You entered “ << value<< std:: endl;
    return 0;
    }
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    20
  • 21. Visual C++ Programming Environment
    Hadziq Fabroyir - Informatics ITS
    ISO/ANSI C++ (unmanaged)
    C++/CLI
    .NET Framework
    Managed C++
    Native C++
    Framework Classes
    Native C++
    MFC
    Common Language Runtime (CLR)
    Operating System
    HHardware
    09/09/2009
    21
  • 22. C++/CLI Data Types
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    22
  • 23. ITC1398 Introduction to Programming
    Chapter 3
    23
    Control Structures
    Three control structures
    Sequence structure
    Programs executed sequentially by default
    Selection structures
    if, if…else, switch
    Repetition structures
    while, do…while, for
  • 24. ITC1398 Introduction to Programming
    Chapter 3
    24
    if Selection Statement
    Choose among alternative courses of action
    Pseudocode example
    If student’s grade is greater than or equal to 60
    print “Passed”
    If the condition is true
    Print statement executes, program continues to next statement
    If the condition is false
    Print statement ignored, program continues
  • 25. Activity Diagram
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    25
  • 26. ITC1398 Introduction to Programming
    Chapter 3
    26
    if Selection Statement
    Translation into C++
    if ( grade >= 60 ) cout << "Passed";
    Any expression can be used as the condition
    If it evaluates to zero, it is treated as false
    If it evaluates to non-zero, it is treated as true
  • 27. ITC1398 Introduction to Programming
    Chapter 3
    27
    if…else Double-Selection Statement
    if
    Performs action if condition true
    if…else
    Performs one action if condition is true, a different action if it is false
    Pseudocode
    If student’s grade is greater than or equal to 60 print “Passed”Else print “Failed”
    C++ code
    if ( grade >= 60 ) cout << "Passed";else cout << "Failed";
  • 28. Activity Diagram
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    28
  • 29. ITC1398 Introduction to Programming
    Chapter 3
    29
    if…else Double-Selection Statement
    Ternary conditional operator (?:)
    Three arguments (condition, value if true, value if false)
    Code could be written:
    cout << ( grade >= 60 ? “Passed” : “Failed” );
    Condition
    Value if true
    Value if false
  • 30. ITC1398 Introduction to Programming
    Chapter 3
    30
    if…else Double-Selection Statement
    Nested if…else statements
    One inside another, test for multiple cases
    Once a condition met, other statements are skipped
    Example
    If student’s grade is greater than or equal to 90
    Print “A”
    Else If student’s grade is greater than or equal to 80 Print “B” Else If student’s grade is greater than or equal to 70 Print “C” Else If student’s grade is greater than or equal to 60 Print “D” Else
    Print “F”
  • 31. ITC1398 Introduction to Programming
    Chapter 3
    31
    if…else Double-Selection Statement
    Nested if…else statements (Cont.)
    Written In C++
    if ( studentGrade >= 90 ) cout << "A";elseif (studentGrade >= 80 ) cout << "B";elseif (studentGrade >= 70 ) cout << "C"; elseif ( studentGrade >= 60 ) cout << "D";else cout << "F";
  • 32. while Repetition Statement
    A repetition statement (also called a looping statement or a loop) allows the programmer to specify that a program should repeat an action while some condition remains true. The pseudocode statement
    While there are more items on my shopping list Purchase next item and cross it off my list
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    32
  • 33. for Repetition Statement
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    33
  • 34. do …while Repetition Statement
    do {
    statement
    } while ( condition );
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    34
  • 35. switch Multiple-Selection Statement
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    35
  • 36. For your practice …
    Lab Session I (Ahad, 19.00-21.00)
    4.14
    5.20
    6.27
    Lab Session II (Senin, 19.00-21.00)
    4.35
    5.12
    6.30
    09/09/2009
    Hadziq Fabroyir - Informatics ITS
    36
  • 37. ☺~ Next: OOP using C++ ~☺
    [ 37 ]
    Hadziq Fabroyir - Informatics ITS
    09/09/2009