Rabu, 31 Oktober 2018

Review 31-10-2018

Algorithm and Programming 31-10-2018

Review:

            There are 6 main topics:
                 > Algorithm & Programming 
                 > Introduction to C Programming 
                 > Operator, Operand, and Arithmetic
                 > Program Control: Selection
                 > Program Control: Repetition
                 > Pointers and Arrays

     ALGORITHM:

                 Procedure for solving a problem
                 To write an algorithm:
                      -writing : Pseudocode
                           Pseudocode can use artificial and informal language
                           Keywords are allowed in writing Pseudocode
                      -drawing : flowchart
                 Basic Computer Operation:
                      1. Input
                      2. Output
                      3. Compute
                      4. Storing Value
                      5. Compare
                      6. Repetition
                 Structure Theorem
                      1. Sequence
                      2. Selection
                      3. Repetition

     INTRODUCTION TO C PROGRAMMING:

                 C Structure consist of function
                                  have many library (standard, by yourself, form others)
                                  every statement closed with ;
                                  has one function called main
                                  case sensitive
                 Comments // <- for 1 line /* */ <- more than 1
                 Escape Sequence \a, \n, \', \", \\, \t
                 Character A - Z, a - z, 0 - 9, '!', '&', '+' etc.
                 Identifier naming mechanism for various element
                                Case Sensitive (Leo not equal to leo)
                                Never use keyword
                                cannot started with numbers 
                  Keywords is words that have special meaning to C compiler
                  Data types character, integer, float  <- basic
                                char, int, float, double, long, unsigned
                  Casting (int), (float) to change data type
                  Constant #define Pi 3.14 
                                const float Pi = 3.14;
                  Sizeof to find out size of data
                  Output Operation
                                printf();
                                putchar();
                                puts();
                  Input Operation
                                scanf();
                                getchar;
                                getch();
                                gets();

     OPERATOR, OPERAND, and ARITHMETIC:

                 C = A + B
                 
                 C, A, B are Operands -> part which data is to be manipulated
                 =, + are Operator -> symbol to process values in result for new value
                      Based in its operand, operator divided into three:
                           - Unary    Operator (1 Operand) Ex. ++A ,A++, --A , A--
                           - Binary   Operator (2 Operand) Ex. A + B, A - B, A = B
                           - Ternary Operator (3 Operand) Ex. Condition ? argument : argument
                      Based on its operation type, operator can be grouped as:
                           1. Assignment =
                           2. Logical && || !
                           3. Arithmetic + - * / % ++ -- ()
                           4. Relational >=, <= , == (to differentiate between =) > , , ?:
                           5. Bitwise >> << ^~ | &
                           6. Pointer  *(value of) & (address of) 
                 Operator will have precedence and associative:
 

     PROGRAM CONTROL 

         SELECTION:
Selection Definition

If

If-Else

Nested If

Program Examples Using If

Switch-Case

?: Operator 
- Go To Label: syntax: goto label; label:

Error Type: Compile-Time Error: syntax error
                    Link-Time Error : Successfully compiled but no object code at link time
                    Run-Time Error: successfully compiled but Run result causing  
                         overflow, floating point underflow, Divison by zero etc
                    Logical Error: YOUR FAULT :v <- I mean incorrect logical flow/ 
                         Algorithm

REPETITION: For(know the limit)
While (don't know the limit)
Do-While (at least 1 time must be executed)
Repetition OperationBreak vs Continue



     POINTERS and ARRAY:

           pointer: datatype* ptrname;
                pointer must be assigned with address
                pointer has its own address it means pointer can point another pointer
                datatype** ptr2;
                ptr2 = ptr1
                ptrname = &address;
                to access address value through ptrname, *ptr <- dereference
                Careful when using scanf array, and string because scanf read a 
                     value and store it in address of some variable
                Creating array: datatype name[length] = {// if you want to set a value first};
                Accessing array[index] // 0 based index
                String is array of char. Remember STRING ALWAYS ENDS with '\0'
                Array consist of single array, 2D array
               
               
    - Stay curious -
       NIM: 2201762723
       binus.ac.id
       skyconnectiva.com
       Hubert Michael Sanyoto