Mathematics used to be the lingua franca of the natural sciences on all universities. Today this is computer science. Lino Guzzella, president of ETH Zurich 2015-2018, NZZ Online, 1.9.2017 Malte Schwerhoff Preparatory Course in Computer Science Course at D-ITET at ETH Zurich Autumn 2019 ((BTW: Lino Guzzella is not a computer scientist, he is a mechanical engineer and prof. for thermotronics ) 1 Why Program? 1. Organisation Any understanding of modern technology requires knowledge about the fundamental operating principles of a computer. Programming (with the computer as a tool) is evolving a cultural technique like reading and writing (using the tools paper and pencil) Most qualified jobs require at least elementary programming skills Programming is fun (and is useful)! 2 3
Course goals Context of this Lecture Computer Science 0 (Preparatory Course): Gain first programming experience Provide first programming experience Computer Science 1 : Theoretical and practical foundations of computer Scratch the “computer science surface” science This course cannot, unfortunately, make up for years of programming Computer Science 2 : Algorithms and Data structures experience (school, hobby) ... Computer Engineering 1 : Logical and physical structures of digital ... but it should ease the learning curve for Computer Science 1 systems Computer Engineering 2 : Important components of operating systems ... and further courses (more or less directly) related to computer science 4 5 Course Structure: Performance assessment Course Structure: Schedule Weeks Day Programme 1 Mon 16.09. C++ tutorial for self-study Fri 20.09. 13-17, HG F 5 No exam Lecture + presentation 1. project Two programming projects need to be passed instead Exercise: project work 2 Wed 25.09. 13-17, HG E 3 Programs are graded automatically Lecture + presentation 2. project Program works as expected (does, what it is supposed to do) → pass Exercise: project work You can continously check your own status/progress Sun 29.09. Submission 1. project More about that later 3 Wed 02.10. 15-17, ML E 12 Exercise: project work; if necessary: “defence” 1. project Sun 06.10. Submission 2. project 4 Fri 11.10. 15-17, ??? If necessary: “defence” 2. project 6 7
What is Computer Science? 2. Introduction The science of systematic processing of informations ,... Computer Science: Definition and History, Algorithms, Turing Machine, ...particularly the automatic processing using digital computers. Higher Level Programming Languages, Tools, The first C++ Program and its Syntactic and Semantic Ingredients (Wikipedia, according to “Duden Informatik”) 8 9 Computer Science vs. Computers Computer Science vs. Computers http://larc.unt.edu/ian/research/cseducation/fellows1991.pdf Computer science is also concerned with the development of fast Computer science is not about machines, in the same way that as- computers and networks... tronomy is not about telescopes. ...but not as an end in itself but for the systematic processing of Mike Fellows, US Computer Scientist (1991) informations . 10 11
Algorithm: Fundamental Notion of Computer Sci- Computer Science � = Computer Literacy ence Algorithm: Instructions to solve a problem step by step Computer literacy: user knowledge Execution does not require any intelligence, but precision (even Handling a computer computers can do it) Working with computer programs for text processing, email, Oldest nontrivial algorithm: presentations ... http://de.wikipedia.org/wiki/Algorithmus Euclidean algorithm, 3. century B.C. Computer Science Fundamental knowledge according to Muhammed al-Chwarizmi , How does a computer work? author of an arabic How do you write a computer program? computation textbook (about 825) “Dixit algorizmi...” (Latin translation) 12 13 Binary Search: Problem & Idea Binary Search: Example find 7 in the list [1 , 3 , 4 , 7 , 9 , 11 , 12 , 17] 1 3 4 7 9 11 12 17 Problem: find an element in an ordered list 1 3 4 7 9 11 12 17 Idee: search in a dictionary — open in the middle, continue left/right if 1 3 4 7 9 11 12 17 necessary 1 3 4 7 9 11 12 17 1 3 4 7 9 11 12 17 1 3 4 7 9 11 12 17 14 15
Binary Search: Pseudo Code Binary Search: C++ Implementation std::string binary_search(const int* begin, const int* end, Input: sorted list of numbers L , number to find n const int n) { while (true) { Output: “yes” (“no”) if n (not) in L if (begin >= end) return "no"; While output O is yet unknown: const int* mid = begin + (end - begin) / 2; If L empty then: O ← “no” if (*mid == n) return "yes"; Otherwise: else if (n < *mid) end = mid; Select central number L m : else begin = mid + 1; If L m = n then: O ← “yes” } If n < L m then: L ← left half of L } Otherwise: L ← right half of L Don’t panic: the C++ code is only shown to illustrate the differences between an algo- rithm description in pseudo code and a concrete implementation. The used language constructs are only introduced in Computer Science 1. 16 17 Algorithms: 3 Levels of Abstractions Programming With a programming language we issue commands to a computer such that it does exactly what we want. 1. Core idea (abstract) : The sequence of instructions is the the essence of any algorithm (“Eureka moment”) (computer) program 2. Pseudo code (semi-detailed) : http://en.wikipedia.org/wiki/Harvard_Computers made for humans (education, correctness and efficiency discussions, proofs 3. Implementation (very detailed) : made for humans & computers (read- & executable, specific programming language, various implementations possible) The Harvard Computers , human computers, ca.1890 18 19
Programming Languages Computing speed “Dictionary Core idea search” In the time, on average, that the sound takes to travel from me to you ... The language that the computer can understand (machine language) is very Pseudo 245 chars/ code 46 words primitive. 30 m � = more than 100 . 000 . 000 instructions Simple operations have to be subdivided into (extremely) Impl. many single steps 282/55 (C++) a contemporary computer can process more than 100 millions instructions The machine language varies 1 between computers. Machine 1536/— code 1 Uniprocessor computer at 1 GHz. 20 21 Higher Programming Languages Why C++ ? Other popular programming languages: Java, C#, Python, Javascript, Swift, We write programs (implementations) in a high-level programming Kotlin, Go, ... ... language : C++ is practically relevant, widespread and “runs everywhere” Can be understood by humans C++ is standardized i.e. there is an official C++ is hardware-independent C++ is one of the “fastest” programming languages Includes reusable function libraries C++ well-suited for systems programming since it enables/requires careful resource management (memory, ...) 22 23
Syntax and Semantics Deutsch vs. C++ Deutsch Like our language, programs have to be formed according to certain Alleen sind nicht gefährlich, Rasen ist gefährlich! rules. (Wikipedia: Mehrdeutigkeit) Syntax : Connection rules for elementary symbols (characters) Semantics : interpretation rules for connected symbols. C++ Corresponding rules for a computer program are simpler but also more strict because computers are relatively stupid. // computation int b = a * a; // b = a 2 // b = a 4 b = b * b; 24 25 Syntax and Semantics of C++ C++ : Kinds of errors illustrated with German sentences Syntax: Das Auto fuhr zu schnell. Syntaktisch und semantisch korrekt. When is a text a C++ program? DasAuto fhur zu sxhnell. Syntaxfehler: Wortbildung. I.e. is it grammatically correct? Rot das Auto ist. Syntaxfehler: Satzstellung. → Can be checked by a computer Man empfiehlt dem Dozenten Syntaxfehler: Satzzeichen fehlen . Semantics: nicht zu widersprechen What does a program mean ? Syntaktisch und grammatikalisch korrekt, Das Fahrrad galoppiert schnell. semantisch fehlerhaft. [Laufzeitfehler] Which algorithm does a program implement ? Syntaktisch und semantisch korrekt, Manche Tiere riechen gut. aber semantisch mehrdeutig. [kein → Requires human understanding Analogon] 26 27
Syntax and semantics of C++ Programming Tools The ISO/IEC Standard 14822 (1998, 2011, 2014, ...) Editor: Program to modify, edit and store C++ program texts is the “law” of C++ Compiler: program to translate a program text into machine language defines the grammar and meaning of C++ programs Computer: machine to execute machine language programs since 2011, continuously extended with features for advanced Operating System: program to organize all procedures such as file programming handling, editor-, compiler- and program execution. 28 29 Overview Project 1: Zahlenraten (Guess A Number) 3. Programming Projects Project 2: Galgenmännchen (Hangman) Project management is done completely online, on Code Expert: http://expert.ethz.ch All deadlines are shown on Code Expert Initial enrollment via https://expert.ethz.ch/enroll/AS19/itet0 , into group “students” 30 31
Passing the Projects “Defending” Projects Rules : Grading is done via automated tests If your submission was made before the deadline You can always check your status/progress and if it did not pass sufficiently many tests Adhere to task decriptions and pay attention to details then you get the chance to improve your solution and resubmit it before the next exercise session Adhere to submission deadlines Use the exercise sessions; we are here to help you → last resort, not the default 32 33 Live Coding Coming up next: Code Expert demo 34
Recommend
More recommend