Introduction

Created by Emília Pietriková / ema

Course Overview

http://kurzy.kpi.fei.tuke.sk/zap

CS50 - Introduction
to Computer Science

https://www.edx.org/course/introduction-computer-science-harvardx-cs50x

Total max. 100 pts

semester (max. 20 pts, min. 11 pts)

3 rounds (week 5, 9 & 12), max. 9 pts
7 problemsets, max. 11 pts

exam (max. 80 pts, min. 41 pts)

3 rounds (week 5, 9 & 12), max. 24 pts
7 problemsets, max. 56 pts
52-70 pts: can be exam B
71-100 pts: can be exam A
otherwise: go to exam B or A

Total max. 100 pts

semester (max. 20 pts, min. 11 pts)

3 rounds (week 5, 9 & 12), max. 9 pts
7 problemsets, max. 11 pts

exam (max. 80 pts, min. 41 pts)

exam B: test, simple tasks
52-75 pts
exam A: practical programming
52-100 pts
otherwise: fx

Algorithm

a set of steps to accomplish a task
more coming soon...

Karel the Robot

gentle introduction to programming

world, Karel, walls,
beepers (corner, bag)

              CORNER  FACING  BEEP-BAG  BEEP-CORNER
              (3, 2)   NORTH      1         0
             ST.+-----------------------------------+
              9 | .   .   .   .   .   .   .   .   . |
                |                                   |
              8 | .   .   .   .   .   .   .   .   . |
                |                                   |
              7 | .   .   .   .   .   .   .   .   . |
                |                                   |
              6 | .   .   .   .   .   .   .   .   . |
                |                       +---+       |
              5 | .   .   .   .   .   . | . | .   . |
                |                   +---+   |       |
              4 | .   .   .   .   2 | .   . | .   . |
                |               +---+       |       |
              3 | .   .   .   . | .   .   . | .   . |
                |           +---+           |       |
              2 | .   .   ^ | .   .   .   . | .   . |
                |       +---+               |       |
              1 | .   . | .   .   .   .   . | .   . |
                +-----------------------------------+
                  1   2   3   4   5   6   7   8   9   AVE.

Karel Primitives

turn_on("world.kw")
step()
turn_left()
pick_beeper()
put_beeper()
turn_off()

 
 
 
 
 
    turn_left
    pick_beeper
 
 
 
 
 
 
 
 
    turn_left();
    pick_beeper();
 
 
 
 
 
 
    turn_on();

    turn_left();
    pick_beeper();

    turn_off();
 
 
 
 
    turn_on("world.kw");

    turn_left();
    pick_beeper();

    turn_off();
 
 
 
int main(){
    turn_on("world.kw");

    turn_left();
    pick_beeper();

    turn_off();
}
#include <karel.h>

int main(){
    turn_on("world.kw");

    turn_left();
    pick_beeper();

    turn_off();
}

source code

source code

compiler

object code

00000000 01001001 11101101 01110111 11111111 00110011 00110011 01010101 11111110 11110000
10010011 11110111 10001000 10001011 00000110 11100001 10010001 10001001 10001001 11010101
11101001 01000101 10101010 11001010 01111101 10001111 00111111 10011111 10011110 11010110
01001010 00101000 11001000 10010111 01000111 10110100 10001010 01110001 11111000 01101010
00010000 11101010 11100100 11100101 10100000 00101011 00001011 01001010 01000001 11101110
10101110 11011000 10011001 01010010 10110111 00011010 10111100 01010110 01001010 01101100
10101011 00100100 01010010 00010110 01110001 10110101 10101001 11111010 00111100 10101100
10101101 00100011 00110001 10111011 00110110 10001000 01001100 10111100 01000111 00101101
00101101 10011010 11110011 01110011 11000100 10111100 11100100 11111011 11100101 10011111
01101001 00111111 01111000 00000111 01100110 00110100 01110000 11011110 00110001 01010011
00001100 01000010 11110001 00111101 11111001 11011110 01110011 10001011 00011101 10001101
11100001 00110111 01010001 01101011 11011101 01110100 10101000 11000110 01110000 00111100
00111011 00100101 01011100 01011110 01100000 00000100 11100101 11001001 11011000 00101100
10111011 00110010 10101111 00110111 00010001 01101001 00010110 01101011 00010110 00000101
10010000 11110110 01110001 11001001 11100010 10010011 10000010 11011011 00110101 11110011
11101001 10010001 11001111 10001010 10100000 10011110 10001110 00110100 01110000 10110000
00000110 11010110 10011010 10101011 10011010 10000111 00110110 10000011 10011101 10101010
11000110 01000010 00100010 10001110 10101010 11010000 01011101 11101001 01100111 00010110
11100110 01111111 10001110 11011010 00001010 01101110 10101010 01000011 01000100 11000110
11110010 01000000 01110011 00010101 00011011 11100101 01010000 10100010 01010110 11000010
01011000 10110010 10100001 11111010 01111100 11011011 01010110 00011111 11001110 10001011
10000110 01011010 00001011 11001010 10101100 10000100 10010011 01010001 11000110 00110111
10110110 01001101 01110111 00111101 01011011 11100010 00100110 10100111 10110000 01110010
00010101 11100100 11011000 11110100 01100000 10011010 01010001 00001111 11001010 10111110
01000011 00101100 11101011 11001000 11100001 00110001 11001101 10001011 11101001 00011000
01111100 00100001 01010010 00110101 00000011 10100101 00101111 01100100 11010000 01000000
11001111 11001101 00010101 00001000 01000110 11110101 00010111 00110111 00000101 00111100
01010110 01000111 00001111 10000011 10101111 00011110 01110011 10010101 10010011 01100110
10000010 00010000 01010110 00110000 10101100 00110100 10001101 01010100 10001011 00111100
11010101 10100011 11110111 00101010 10101010 11001010 11000001 11111100 11111101 00100100
01011111 11010100 01100001 11010111 00110110 00111110 10100110 11011100 01100101 01110101
                                           ...

How to compile a program?

gcc -std=c11 -Wall -Werror karel.c -lkarel -lcurses -o karel

or

make karel

How to run a program?

./karel

Houston, we have a BUG!

Ďuri, maš tam ryžu!

DRY

Don't Repeat Yourself
Watch Disney instead

Function

sequence of program instructions that perform a specific task, packaged as a unit

ret_type name(params);

void

Definition
vs
Declaration

Function Call

Sequence

What if?

Karel Sensors

front_is_clear()
beepers_present()
beepers_in_bag()
facing_north()

IF

if( front_is_clear() )
    step();
    
 

IF

if( front_is_clear() )
    step();
    turn_left();
 

IF

if( front_is_clear() ){
    step();
    turn_left();
}

IF

if( front_is_clear() ){
    step();

}

ELSE

if( front_is_clear() ){
    step();
}
else
    turn_left();
    turn_left();
    turn_left();
 

ELSE

if( front_is_clear() ){
    step();
}
else{
    turn_left();
    turn_left();
    turn_left();
}

Iteration

repetition of a process or procedure

WHILE

while(beepers_present()){
    pick_beeper();
 
 
 
}

WHILE

while( front_is_clear() ){
    step();
 
 
 
}

WHILE

while( front_is_clear() ){
    step();
    if( beepers_in_bag() ){
        put_beeper();
    }
}

DO-WHILE

do{
    step();
    if( beepers_in_bag() ){
        put_beeper();
    }
} while( front_is_clear() );

Video

Questions?

MS Teams