Principles of computer programming Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković E-mail: mtanaskovic@singidunum.ac.rs
Course organization Lectures: Presentation of concepts and their illustration through simple examples. The examples will be done in interaction with students Exercises: Practical application of the concepts through more complex examples
Lecture material Basic literature 1.) Lecture and exercise slides (course webpage http://predmet.singidunum.ac.rs/course/view.php?id=945) 2.) Book: The C Programming Language from Brian W. Kernighan and Dennis M. Ritchie (available on-line at http://cs.indstate.edu/~cbasavaraj/cs559/the_c_programming _language_2.pdf ) Additional literature 1.) Internet (Google as your best friend)
Assesment The progress of the students will be continuously monitored during the semester Students can maximally obtain 100 points for this course. Out of these 100 points, 70 can be won during the semester and 30 on the final exam Students will pass the exam by winning at least 51 points during the course. Points in the range 51-60 result in grade six, points in the range 61-70 result in grade seven
Assesment Final grade will be formed on the basis of obtained points according to the following scheme: 51-60 points grade 6 (six); 61-70 points grade 7 (seven); 71-80 points grade 8 (eight); 81-90 points grade 9 (nine); 91-100 points grade 10 (ten).
Semester progress assessment 1. Presence at lectures and exercizes (0-10 points) Students who are working and can not come to the lectures and exercises may still win these points by doing a project in agreement with the lecturer 2. Midterm I (0-30 points) student has to obtain at least 17 points in order to pass the first midterm 3. Midterm II (0-30 points) student has to obtain at least 17 points in order to pass the second midterm
Midterms The two midterms take place: I midterm in 6 th week of the semester II midterm in 12 th week of the semester During the second midterm, students can also do the first one, while at the final exam students can do both the first and the second midterm The midterms will consist of a written test and a mini project - Test is worth 20 points (10 are needed for a pass) - Mini project is worth 10 points and it is a take home task that students have one week to complete. It is defended orally by practically presenting the results
Final exam Final exam will be in a form of a take home project. Students will have two and a half weeks to complete the project The final project is defended orally by practically presenting the results Final exam is worth 30 points
Why should you invest your time in learning the material of this course??
The future of IT industry Whether you chose to study data science or embedded systems, you will profit from the future trends!
Where does the principles of computer programming fit in this story? Principles of computer programming lies in the fundamentals of both areas Dta Science Embedded Systems Domain specific knowledge Orogramming languages Databa ses Maths, Principles of programming
Why should you study this course? Form a good fundamental so that you can build your knowledge and expertize on top of it You will be able to profit from this knowledge later as you develop into software engineers!
Silabus Course outline Week I II III IV V VI VII VIII Team/Activity Introduction to principles of programming and the C programming language Types, operators and expressions Control flow Functions and program structures Pointers and arrays First Midterm Structures Input and output
Silabus Course outline Nedelja X XI XII XIII XIV XV Tema/Aktivnost The UNIX system interface Standard libraries Second Midterm Recapitulation, introduction to writting large projects in C Example of a complex programming project in C Example of a complex programming project in C, preparation for the final exam project
Principles of computer programming Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković E-mail: mtanaskovic@singidunum.ac.rs
Definition of a computer Computer (noun) An electronic device which is capable of receiving information (data) in a particular form and of performing a sequence of operations in accordance with a predetermined but variable set of procedural instructions (program) to produce a result in the form of information or signals. Computer, Wikipedia definition A computer is a device that can be instructed to carry out arbitrary sequences of arithmetic or logical operations automatically. The ability of computers to follow generalized sets of operations, called programs, enables them to perform an extremely wide range of tasks.
Computer - examples
Definition of a computer program Computer program (noun) A sequence of instructions that a computer can interpret and execute Computer program, Wikipedia definition: A computer program is a collection of instructions that performs a specific task when executed by a computer. A computer requires programs to function and typically executes the program's instructions in a central processing unit
Computer program - examples
Definition of a programming language A programming language is a formal language that specifies a set of instructions that can be used to produce various kinds of output. Programming languages generally consist of instructions for a computer. Programming languages can be used to create programs that implement specific algorithms. Programming language is a language that a computer may understand. By learning different programming languages we become capable of telling the computer to do what we want it to do
What does a computer understand? Computers are binary machines they only work with binary data Binary states in computer are represented by presence and absence of voltage We usually denote these binary states by 1 and 0 A typical binary instruction that a computer would understand
Representation of characters in a computer Numbers and characters are also represented as binary sequences in a computer The ASCII standard defines binary sequences that correspond to the alphabet letters and other characters
Representation of numbers in a computer Same logic is used for binary numbers
Transformation from decimal to binary numbers LSB least significant bit (the most right digit) MSB most significant bit (the most left digit) Binary number: 101001
Representation of negative binary numbers How to represent -41? Use the most significant bit to indicate the sign 0 for positive numbers 1 for negative numbers Decimal number 41 --- Binary representation: 00101001 Decimal number -41 --- Binary representation: 10101001 Alternatively use complement Decimal number 41 --- Binary representation: 00101001 Decimal number -41 --- Binary representation: 11010110
Should we write our programs as binary instructions?
Should we write our programs as binary instructions? Writing programs as binary instructions would be very difficult Programs would be prone to errors and it would be almost impossible for humans to write large and complex computer programs in this way If programming was done through writing binary instructions, the IT industry would newer be in the state it is in now No need to write instructions as binary commands. For each computer architecture there is a finite set of commands that can be used to write instructions assembler
Should we write our programs in assembler?
Should we write our programs in assembler? An assembler is a low-level programming language for a computer, in which there is a very strong correspondence between the language and the architecture of the machine. Each assembly language is specific to a particular computer architecture Writing code in assembler is easier than writing binary instructions, but still making complex projects and discovering possible errors is very hard Programs written in assembler work only for the corresponding computer architecture. Porting assembler code is hard and programs have to be rewritten in order to work on other architectures
High level programming languages A high-level programming language is a programming language with strong abstraction from the details of the computer. Unlike low-level programming languages, it may use natural language elements and be easier to use. This makes the process of developing a program simpler and more understandable relative to a lower-level language. The amount of abstraction provided defines how "high-level" a programming language is A compiler translates a program in a high-level programing language to an assembler code for a given hardware platform. This makes programs written in high level languages easily portable
History of high level programming languages 1957 Fortran, first compiler 1958 Lisp 1959 COBOL 1964 BASIC 1970 Pascal 1972 C 1980 C++ 1991 Python 1993 R 1995 Java, Java script 1995 - PHP
Why start with C? C is not specialized to any particular area of application and is quite general, which makes it suitable for learning the fundamentals of computer programming C can be useful both in Embedded Systems and Data Science It is a high-level programming language, but still remains very close to hardware, which makes it very useful for programming in conditions of limited resources or in situations where the speed of execution is critical Most modern operating systems are written in C
Prepare the environment for your first program in C We will use Code::Blocks for writing our C programs (open source and freely available at http://www.codeblocks.org/) As a compiler we will use GNU GCC Compiler (open source and freely available at https://sourceforge.net/projects/mingw/)
1. Start code blocks Your first program in C 2. Start a new project (Files->New->Project) 3. Select Console Project and press Go
Your first program in C 3. Select C as your language of choice and click next
Your first program in C 4. Specify the name and location directory of your folder and click next
Your first program in C 5. Select GNU GCC Compiler and click finish
Your first program in C 5. Select GNU GCC Compiler and click finish
Your first program in C
Your first program in C Include libraries that allow you to write on the standard output (monitor)
Your first program in C Program in C is a function that is always called main. It takes no arguments and in this case returns zero
Your first program in C Blocks of code are delimited with large brackets { and } in C
Your first program in C Each command in C must end with ; Command printf prints its argument to the standard output (console/monitor). The argument of this function is the sentence Hello world! And at the end there is a special sign \n which brings the cursor to the new line
Compile and run your program Press the compile and run button
Result of the program execution You will further extend this program during the exercise class Have fun, programming is interesting!