139
Informatik Vorlesung am D-MATH/D-PHYS der ETH Z¨ urich Malte Schwerhoff, Felix Friedrich HS 2018 1

Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Informatik

Vorlesung am D-MATH/D-PHYS der ETH Zurich

Malte Schwerhoff, Felix Friedrich

HS 2018

1

Page 2: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Willkommen

zur Vorlesung Informatikam MATH/PHYS Department der ETH Zürich.

Ort und Zeit:

Tuesday 13:15 - 15:00, ML D28, ML E12.Pause 14:00 - 14:15, leichte Verschiebung möglich.

Vorlesungs-Webseite

http://lec.inf.ethz.ch/ifmp

2

Page 3: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

TeamChefassistent Vytautas AstrauskasBack-Office Inna Grijnevitch

Martin ClochardPavol Bielik

Assistenten Eliza Wszola Moritz SchneiderAlexander Hedges Patrik HadornViera Klasovita Philippe SchlattnerMax Egli Yannik AmmannChristopher Lehner Adrian LangenbachOrhan Saeedi David BaurMaximillian Holst Corminboeuf EtienneBenjamin Rothenberger Tobias KlenzeDavid Sommer Sefidgar Seyed Reza

Dozenten Dr. Malte Schwerhoff / Dr. Felix Friedrich

3

Page 4: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Einschreibung in Ubungsgruppen

Gruppeneinteilung selbstständig via WebseiteEinschreibung breits offen

19 Gruppen insgesamt: 9 Dienstags 15-17 Uhr, 10 Mittwochs10-12 Uhr16 Gruppen auf Deutsch, 3 auf Englisch

4

Page 5: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Einschreibung in Ubungsgruppen

Gruppeneinteilung selbstständig via WebseiteEinschreibung breits offen19 Gruppen insgesamt: 9 Dienstags 15-17 Uhr, 10 Mittwochs10-12 Uhr16 Gruppen auf Deutsch, 3 auf Englisch

4

Page 6: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

AblaufMo Di Mi Do Fr Sa So Mo Di Mi . . . Di Mi

VÜ Ü VÜ Ü Ü Ü

Ausgabe

Vorbesprechung StudyCenter

Abgabe

Nachbesprechung

Ü

Übungsblattausgabe zur Vorlesung (online)Vorbesprechung in der folgenden Übung (am selben/nächsten Tag)StudyCenter (studycenter.ethz.ch)Abgabe der Serie spätestens am Tag vor der nächsten Vorlesung (23:59h)Nachbesprechung der Serie in der übernächsten Übung. Feeback zu denAbgaben innerhalb einer Woche nach Abgabe.

5

Page 7: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

AblaufMo Di Mi Do Fr Sa So Mo Di Mi . . . Di Mi

VÜ Ü VÜ Ü Ü Ü

Ausgabe

Vorbesprechung

StudyCenter

Abgabe

Nachbesprechung

Ü

Übungsblattausgabe zur Vorlesung (online)Vorbesprechung in der folgenden Übung (am selben/nächsten Tag)StudyCenter (studycenter.ethz.ch)Abgabe der Serie spätestens am Tag vor der nächsten Vorlesung (23:59h)Nachbesprechung der Serie in der übernächsten Übung. Feeback zu denAbgaben innerhalb einer Woche nach Abgabe.

5

Page 8: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

AblaufMo Di Mi Do Fr Sa So Mo Di Mi . . . Di Mi

VÜ Ü VÜ Ü Ü Ü

Ausgabe

Vorbesprechung StudyCenter

Abgabe

Nachbesprechung

Ü

Übungsblattausgabe zur Vorlesung (online)Vorbesprechung in der folgenden Übung (am selben/nächsten Tag)StudyCenter (studycenter.ethz.ch)Abgabe der Serie spätestens am Tag vor der nächsten Vorlesung (23:59h)Nachbesprechung der Serie in der übernächsten Übung. Feeback zu denAbgaben innerhalb einer Woche nach Abgabe.

5

Page 9: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

AblaufMo Di Mi Do Fr Sa So Mo Di Mi . . . Di Mi

VÜ Ü VÜ Ü Ü Ü

Ausgabe

Vorbesprechung StudyCenter

Abgabe

Nachbesprechung

Ü

Übungsblattausgabe zur Vorlesung (online)Vorbesprechung in der folgenden Übung (am selben/nächsten Tag)StudyCenter (studycenter.ethz.ch)Abgabe der Serie spätestens am Tag vor der nächsten Vorlesung (23:59h)Nachbesprechung der Serie in der übernächsten Übung. Feeback zu denAbgaben innerhalb einer Woche nach Abgabe.

5

Page 10: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

AblaufMo Di Mi Do Fr Sa So Mo Di Mi . . . Di Mi

VÜ Ü VÜ Ü Ü Ü

Ausgabe

Vorbesprechung StudyCenter

Abgabe

Nachbesprechung

Ü

Übungsblattausgabe zur Vorlesung (online)Vorbesprechung in der folgenden Übung (am selben/nächsten Tag)StudyCenter (studycenter.ethz.ch)Abgabe der Serie spätestens am Tag vor der nächsten Vorlesung (23:59h)Nachbesprechung der Serie in der übernächsten Übung. Feeback zu denAbgaben innerhalb einer Woche nach Abgabe.

5

Page 11: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Zu den UbungenBearbeitung der wöchentlichen Uebungsserien ist also freiwillig,wird aber dringend empfohlen!

6

Page 12: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Zu den UbungenBearbeitung der wöchentlichen Uebungsserien ist also freiwillig,wird aber dringend empfohlen!

6

Page 13: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Relevantes fur die Prufung

Prüfungsstoff für die Endprüfung (in der Prüfungssession 2018)schliesst ein

Vorlesungsinhalt (Vorlesung, Handout) undÜbungsinhalte (Übungsstunden, Übungsaufgaben).

9

Page 14: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Relevantes fur die Prufung

Prüfung ist schriftlich.

Es wird sowohl praktisches Wissen (Programmierfähigkeit) als auchtheoretisches Wissen (Hintergründe, Systematik) geprüft.

9

Page 15: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Unser Angebot (VVZ)

Ihre Programmierübungen werden (halb)automatisch bewertet.Durch Bearbeitung der wöchentlichen Übungsserien kann einBonus von maximal 0.25 Notenpunkten erarbeitet werden, der andie Prüfung mitgenommen wird.Der Bonus ist proportional zur erreichten Punktzahl von speziellmarkierten Bonusaufgaben, wobei volle Punktzahl einem Bonusvon 0.25 entspricht. Die Zulassung zu speziell markiertenBonusaufgaben hängt von der erfolgreichen Absolvierung andererÜbungsaufgaben ab. Der erreichte Notenbonus verfällt, sobalddie Vorlesung neu gelesen wird.

10

Page 16: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Unser Angebot (Konkret)

Insgesamt 3 Bonusaufgaben; 2/3 der Punkte reichen für 0.25Bonuspunkte für die PrüfungSie können also z.B. 2 Bonusaufgaben zu 100% lösen, oder 3Bonusaufgaben zu je 66%, oder ...Bonusaufgaben müssen durch erfolgreich gelöste Übungsserienfreigeschaltet (→ Experience Points) werdenEs müssen wiederum nicht alle Übungsserien vollständig gelöstwerden, um eine Bonusaufgabe freizuschaltenDetails: Kurswebseite, Übungsstunden, Online-Übungssystem(Code Expert)

11

Page 17: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Akademische Lauterkeit

Regel: Sie geben nur eigene Lösungen ab, welche Sie selbstverfasst und verstanden haben.

Wir prüfen das (zum Teil automatisiert) nach und behalten unsinsbesondere mündliche Prüfgespräche vor.

Sollten Sie zu einem Gespräche eingeladen werden: geraten Sienicht in Panik. Es gilt primär die Unschuldsvermutung. Wir wollenwissen, ob Sie verstanden haben, was Sie abgegeben haben.

12

Page 18: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Einschreibung in Ubungsgruppen - IBesuchen Sie http://expert.ethz.ch/enroll/AS18/ifmp

Loggen Sie sich mit Ihrem nethz Account ein.

13

Page 19: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Einschreibung in Ubungsgruppen - IISchreiben Sie sich im folgenden Dialog in eine Übungsgruppe ein.

14

Page 20: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ubersicht

15

Page 21: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Programmierubung

16

Page 22: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Programmierubung

A: compileB: runC: test

16

Page 23: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Programmierubung

D: BeschreibungE: History

16

Page 24: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Testen und Abgeben

17

Page 25: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Testen und Abgeben

Testen

17

Page 26: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Testen und Abgeben

Testen

Abgeben

17

Page 27: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Wo ist der Save Knopf?

Das Filesystem ist transaktionsbasiert und es wird laufendgespeichert („autosave“). Beim Öffnen eines Projektes findet manimmer den zuletzt gesehenen Zustand wieder.Der derzeitige Stand kann als (benannter) Snapshot festgehaltenwerden. Zu gespeicherten Snapshots kann jederzeitzurückgekehrt werden.Der aktuelle Stand kann als Snapshot abgegeben (submitted)werden. Zudem kann jeder gespeicherts Snapshot abgegebenwerden.

18

Page 28: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Snapshots

19

Page 29: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Snapshots

Snapshot betrachten

19

Page 30: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Snapshots

Snapshot betrachten

Abgabe

Zurück zu

19

Page 31: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

1. Einfuhrung

Informatik: Definition und Geschichte, Algorithmen, TuringMaschine, Höhere Programmiersprachen, Werkzeuge derProgrammierung, Das erste C++ Programm und seinesyntaktischen und semantischen Bestandteile

22

Page 32: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Was ist Informatik?

Die Wissenschaft der systematischen Verarbeitung vonInformationen,. . .. . . insbesondere der automatischen Verarbeitung mit Hilfe vonDigitalrechnern.

(Wikipedia, nach dem „Duden Informatik“)

23

Page 33: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Was ist Informatik?

Die Wissenschaft der systematischen Verarbeitung vonInformationen,. . .

. . . insbesondere der automatischen Verarbeitung mit Hilfe vonDigitalrechnern.

(Wikipedia, nach dem „Duden Informatik“)

23

Page 34: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Was ist Informatik?

Die Wissenschaft der systematischen Verarbeitung vonInformationen,. . .. . . insbesondere der automatischen Verarbeitung mit Hilfe vonDigitalrechnern.

(Wikipedia, nach dem „Duden Informatik“)

23

Page 35: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Informatik vs. Computer

Computer science is not about machines, in the same waythat astronomy is not about telescopes.

Mike Fellows, US-Informatiker (1991)

24

Page 36: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Informatik vs. Computer

Die Informatik beschäftigt sich heute auch mit dem Entwurf vonschnellen Computern und Netzwerken. . .

. . . aber nicht als Selbstzweck, sondern zur effizienterensystematischen Verarbeitung von Informationen.

25

Page 37: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Informatik vs. Computer

Die Informatik beschäftigt sich heute auch mit dem Entwurf vonschnellen Computern und Netzwerken. . .. . . aber nicht als Selbstzweck, sondern zur effizienterensystematischen Verarbeitung von Informationen.

25

Page 38: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Informatik 6= EDV-Kenntnisse

EDV-Kenntnisse: Anwenderwissen („Computer Literacy”)

Umgang mit dem ComputerBedienung von Computerprogrammen (für Texterfassung, E-Mail,Präsentationen,. . . )

26

Page 39: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Informatik 6= EDV-Kenntnisse

Informatik: Grundlagenwissen

Wie funktioniert ein Computer?Wie schreibt man ein Computerprogramm?

26

Page 40: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

ETH: Pionierin der modernen Informatik

1950: ETH mietet Konrad Zuses Z4, den damals einzigenfunktionierenden Computer in Europa.

27

Page 41: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

ETH: Pionierin der modernen Informatik

1956: Inbetriebnahme der ERMETH, entwickelt und gebaut an derETH von Eduard Stiefel.

28

Page 42: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

ETH: Pionierin der modernen Informatik1958–1963: Entwicklung von ALGOL 60 (der ersten formaldefinierten Programmiersprache), unter anderem durch HeinzRutishauer, ETH

1964: Erstmals können ETH-Studierende selbst einen Computerprogrammieren (die CDC 1604, gebaut von Seymour Cray).

29

Page 43: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

ETH: Pionierin der modernen Informatik1958–1963: Entwicklung von ALGOL 60 (der ersten formaldefinierten Programmiersprache), unter anderem durch HeinzRutishauer, ETH

1964: Erstmals können ETH-Studierende selbst einen Computerprogrammieren (die CDC 1604, gebaut von Seymour Cray).

29

Page 44: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

ETH: Pionierin der modernen Informatik

Die Klasse 1964 im Jahr 2015 (mit einigen Gästen)

30

Page 45: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

ETH: Pionierin der modernen Informatik

Niklaus Wirth (* 1934)

30

Page 46: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

ETH: Pionierin der modernen Informatik

1968–1990: Niklaus Wirth entwickelt an der ETH dieProgrammiersprachen Pascal, Modula-2 und Oberon und 1980 dieLilith, einen der ersten Computer mit grafischer Benutzeroberfläche.

31

Page 47: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Zuruck in die Gegenwart: Inhalt dieser Vorlesung

Systematisches Problemlösen mit Algorithmen und derProgrammiersprache C++.Also:

nicht nur,aber auch Programmierkurs.

32

Page 48: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Algorithmus: Kernbegriff der Informatik

Algorithmus:

Handlungsanweisung zur schrittweisen Lösung eines Problems

Ausführung erfordert keine Intelligenz, nur Genauigkeit (sogarComputer können es)nach Muhammed al-Chwarizmi,Autor eines arabischenRechen-Lehrbuchs (um 825)

“Dixit algorizmi. . . ” (lateinische Übersetzung)

33

Page 49: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Algorithmus: Kernbegriff der Informatik

Algorithmus:

Handlungsanweisung zur schrittweisen Lösung eines ProblemsAusführung erfordert keine Intelligenz, nur Genauigkeit (sogarComputer können es)

nach Muhammed al-Chwarizmi,Autor eines arabischenRechen-Lehrbuchs (um 825)

“Dixit algorizmi. . . ” (lateinische Übersetzung)

33

Page 50: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Algorithmus: Kernbegriff der Informatik

Algorithmus:

Handlungsanweisung zur schrittweisen Lösung eines ProblemsAusführung erfordert keine Intelligenz, nur Genauigkeit (sogarComputer können es)nach Muhammed al-Chwarizmi,Autor eines arabischenRechen-Lehrbuchs (um 825)

“Dixit algorizmi. . . ” (lateinische Übersetzung)33

Page 51: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Der alteste nichttriviale AlgorithmusEuklidischer Algorithmus (aus Euklids Elementen, 3. Jh. v. Chr.)

a b

a b a b a b

Eingabe: ganze Zahlen a > 0, b > 0

Ausgabe: ggT von a und b

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

34

Page 52: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Der alteste nichttriviale AlgorithmusEuklidischer Algorithmus (aus Euklids Elementen, 3. Jh. v. Chr.)

a b a b

a b a b

Eingabe: ganze Zahlen a > 0, b > 0

Ausgabe: ggT von a und b

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

34

Page 53: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Der alteste nichttriviale AlgorithmusEuklidischer Algorithmus (aus Euklids Elementen, 3. Jh. v. Chr.)

a b a b a b

a b

Eingabe: ganze Zahlen a > 0, b > 0

Ausgabe: ggT von a und b

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

34

Page 54: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Der alteste nichttriviale AlgorithmusEuklidischer Algorithmus (aus Euklids Elementen, 3. Jh. v. Chr.)

a b a b a b a b

Eingabe: ganze Zahlen a > 0, b > 0

Ausgabe: ggT von a und b

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

34

Page 55: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Der alteste nichttriviale AlgorithmusEuklidischer Algorithmus (aus Euklids Elementen, 3. Jh. v. Chr.)

a b a b a b a b

Eingabe: ganze Zahlen a > 0, b > 0

Ausgabe: ggT von a und b

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

34

Page 56: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Algorithmen: 3 Abstraktionsstufen

1. Kernidee (abstrakt):Die Essenz eines Algorithmus’ („Heureka-Moment“)

2. Pseudocode (semi-detailliert):Für Menschen gemacht (Bildung, Korrektheit- undEffizienzdiskussionen, Beweise)

3. Implementierung (sehr detailliert):Für Mensch & Computer gemacht (les- & ausführbar,bestimmte Programmiersprache, verschiedeneImplementierungen möglich)

Euklid: Kernidee und Pseudocode gesehen, Implementierung nochnicht

35

Page 57: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Algorithmen: 3 Abstraktionsstufen

1. Kernidee (abstrakt):Die Essenz eines Algorithmus’ („Heureka-Moment“)

2. Pseudocode (semi-detailliert):Für Menschen gemacht (Bildung, Korrektheit- undEffizienzdiskussionen, Beweise)

3. Implementierung (sehr detailliert):Für Mensch & Computer gemacht (les- & ausführbar,bestimmte Programmiersprache, verschiedeneImplementierungen möglich)

Euklid: Kernidee und Pseudocode gesehen, Implementierung nochnicht

35

Page 58: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Algorithmen: 3 Abstraktionsstufen

1. Kernidee (abstrakt):Die Essenz eines Algorithmus’ („Heureka-Moment“)

2. Pseudocode (semi-detailliert):Für Menschen gemacht (Bildung, Korrektheit- undEffizienzdiskussionen, Beweise)

3. Implementierung (sehr detailliert):Für Mensch & Computer gemacht (les- & ausführbar,bestimmte Programmiersprache, verschiedeneImplementierungen möglich)

Euklid: Kernidee und Pseudocode gesehen, Implementierung nochnicht

35

Page 59: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Algorithmen: 3 Abstraktionsstufen

1. Kernidee (abstrakt):Die Essenz eines Algorithmus’ („Heureka-Moment“)

2. Pseudocode (semi-detailliert):Für Menschen gemacht (Bildung, Korrektheit- undEffizienzdiskussionen, Beweise)

3. Implementierung (sehr detailliert):Für Mensch & Computer gemacht (les- & ausführbar,bestimmte Programmiersprache, verschiedeneImplementierungen möglich)

Euklid: Kernidee und Pseudocode gesehen, Implementierung nochnicht

35

Page 60: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0 1 2 3 4 5 6 7 8 9

Speicher

Links Rechts

Register36

Page 61: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8 9

Speicher

Programmcode

Links Rechts

Register36

Page 62: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Programmcode Daten

Links Rechts

Register36

Page 63: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Programmcode Daten

Links Rechts

Register

Daten

36

Page 64: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Links

b

Rechts

a

Register

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

36

Page 65: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Links

b

Rechts

a

Register

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

36

Page 66: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Links

b

Rechts

a

Register

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

36

Page 67: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Links

b

Rechts

a

Register

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

36

Page 68: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Links

b

Rechts

a

Register

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

36

Page 69: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Euklid in der Box

0

[8]→ L

1

[9]→ R

2

L = 0?stop

3

R > L?springe

zu 6

4

L − R→ [8]

5

springezu 0

6

R − L→ [9]

7

springezu 0

8

b

9

a

Speicher

Links Rechts

Register

Solange b 6= 0Wenn a > b dann

a← a− bSonst:

b← b− aErgebnis: a.

36

Page 70: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Computer – Konzept

Eine geniale Idee: Universelle Turingmaschine (Alan Turing, 1936)

Alan Turing37

Page 71: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Computer – Umsetzung

Z1 – Konrad Zuse (1938)ENIAC – John Von Neumann (1945)

Konrad Zuse

John von Neumann38

Page 72: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Speicher fur Daten und Programm

Folge von Bits aus {0, 1}.Programmzustand: Werte aller Bits.Zusammenfassung von Bits zu Speicherzellen (oft: 8 Bits = 1Byte).

40

Page 73: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Speicher fur Daten und Programm

Jede Speicherzelle hat eine Adresse.Random Access: Zugriffszeit auf Speicherzelle (nahezu)unabhängig von ihrer Adresse.

40

Page 74: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Programmieren

Mit Hilfe einer Programmiersprache wird dem Computer eineFolge von Befehlen erteilt, damit er genau das macht, was wirwollen.Die Folge von Befehlen ist das(Computer)-Programm.

The Harvard Computers, Menschliche Berufsrechner, ca.189041

Page 75: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Rechengeschwindigkeit

In der mittleren Zeit, die der Schall von mir zu Ihnen unterwegs ist...

30 m

arbeitet ein heutiger Desktop-PC mehr als 100 MillionenInstruktionen ab.1

1Uniprozessor Computer bei 1GHz42

Page 76: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Rechengeschwindigkeit

In der mittleren Zeit, die der Schall von mir zu Ihnen unterwegs ist...

30 m

arbeitet ein heutiger Desktop-PC mehr als 100

MillionenInstruktionen ab.1

1Uniprozessor Computer bei 1GHz42

Page 77: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Rechengeschwindigkeit

In der mittleren Zeit, die der Schall von mir zu Ihnen unterwegs ist...

30 m = mehr als 100.000.000 Instruktionen

arbeitet ein heutiger Desktop-PC mehr als 100 MillionenInstruktionen ab.1

1Uniprozessor Computer bei 1GHz42

Page 78: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum Programmieren?

Da hätte ich ja gleich Informatik studieren können ...

Es gibt doch schon für alles Programme ...Programmieren interessiert mich nicht ...Weil Informatik hier leider ein Pflichtfach ist .... . .

43

Page 79: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum Programmieren?

Da hätte ich ja gleich Informatik studieren können ...Es gibt doch schon für alles Programme ...

Programmieren interessiert mich nicht ...Weil Informatik hier leider ein Pflichtfach ist .... . .

43

Page 80: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum Programmieren?

Da hätte ich ja gleich Informatik studieren können ...Es gibt doch schon für alles Programme ...Programmieren interessiert mich nicht ...

Weil Informatik hier leider ein Pflichtfach ist .... . .

43

Page 81: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum Programmieren?

Da hätte ich ja gleich Informatik studieren können ...Es gibt doch schon für alles Programme ...Programmieren interessiert mich nicht ...Weil Informatik hier leider ein Pflichtfach ist ...

. . .

43

Page 82: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum Programmieren?

Da hätte ich ja gleich Informatik studieren können ...Es gibt doch schon für alles Programme ...Programmieren interessiert mich nicht ...Weil Informatik hier leider ein Pflichtfach ist .... . .

43

Page 83: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Mathematik war früher die Lingua franca der Naturwis-senschaften an allen Hochschulen. Und heute ist dies dieInformatik.Lino Guzzella, Präsident der ETH Zürich, NZZ Online, 1.9.2017

(Lino Guzzella ist übrigens nicht Informatiker, sondern Maschineningenieur und Prof. für Thermotronik )

44

Page 84: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Darum Programmieren!

Jedes Verständnis moderner Technologie erfordert Wissen überdie grundlegende Funktionsweise eines Computers.Programmieren (mit dem Werkzeug Computer) wird zu einerKulturtechnik wie Lesen und Schreiben (mit den WerkzeugenPapier und Bleistift)

Die meisten qualifizierten Jobs benötigen zumindest elementareProgrammierkenntnisse.Programmieren macht Spass (und ist nützlich)!

45

Page 85: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Darum Programmieren!

Jedes Verständnis moderner Technologie erfordert Wissen überdie grundlegende Funktionsweise eines Computers.Programmieren (mit dem Werkzeug Computer) wird zu einerKulturtechnik wie Lesen und Schreiben (mit den WerkzeugenPapier und Bleistift)Die meisten qualifizierten Jobs benötigen zumindest elementareProgrammierkenntnisse.

Programmieren macht Spass (und ist nützlich)!

45

Page 86: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Darum Programmieren!

Jedes Verständnis moderner Technologie erfordert Wissen überdie grundlegende Funktionsweise eines Computers.Programmieren (mit dem Werkzeug Computer) wird zu einerKulturtechnik wie Lesen und Schreiben (mit den WerkzeugenPapier und Bleistift)Die meisten qualifizierten Jobs benötigen zumindest elementareProgrammierkenntnisse.Programmieren macht Spass (und ist nützlich)!

45

Page 87: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Programmiersprachen

Sprache, die der Computer „versteht“, ist sehr primitiv(Maschinensprache).Einfache Operationen müssen in (extrem) viele Einzelschritteaufgeteilt werden.Sprache variiert von Computer zu Computer.

46

Page 88: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Hohere Programmiersprachen

darstellbar als Programmtext, der

von Menschen verstanden werden kannvom Computermodell unabhängig ist→ Abstraktion!

47

Page 89: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum C++?

Andere populäre höhere Programmiersprachen: Java, C#, Python,Javascript, Swift, Kotlin, Go, ... . . .

C++ ist relevant in der Praxis (weit verbreitet) und „läuft überall“Für das wissenschaftliche Rechnen (wie es in der Mathematikund Physik gebraucht wird), bietet C++ viele nützliche Konzepte.C++ ist standardisiert, d.h. es gibt ein „offizielles“ C++.C++ ist eine der „schnellsten“ ProgrammiersprachenC++ eignet sich gut für Systemprogrammierung da es einensorgfältigen Umgang mit Ressourcen (Speicher, ...)erlaubt/verlangt

48

Page 90: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum C++?

Andere populäre höhere Programmiersprachen: Java, C#, Python,Javascript, Swift, Kotlin, Go, ... . . .

C++ ist relevant in der Praxis (weit verbreitet) und „läuft überall“Für das wissenschaftliche Rechnen (wie es in der Mathematikund Physik gebraucht wird), bietet C++ viele nützliche Konzepte.C++ ist standardisiert, d.h. es gibt ein „offizielles“ C++.

C++ ist eine der „schnellsten“ ProgrammiersprachenC++ eignet sich gut für Systemprogrammierung da es einensorgfältigen Umgang mit Ressourcen (Speicher, ...)erlaubt/verlangt

48

Page 91: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Warum C++?

Andere populäre höhere Programmiersprachen: Java, C#, Python,Javascript, Swift, Kotlin, Go, ... . . .

C++ ist relevant in der Praxis (weit verbreitet) und „läuft überall“Für das wissenschaftliche Rechnen (wie es in der Mathematikund Physik gebraucht wird), bietet C++ viele nützliche Konzepte.C++ ist standardisiert, d.h. es gibt ein „offizielles“ C++.C++ ist eine der „schnellsten“ ProgrammiersprachenC++ eignet sich gut für Systemprogrammierung da es einensorgfältigen Umgang mit Ressourcen (Speicher, ...)erlaubt/verlangt

48

Page 92: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Syntax und Semantik

Programme müssen, wie unsere Sprache, nach gewissen Regelngeformt werden.

Syntax: Zusammenfügungsregeln für elementare Zeichen (Buchstaben).Semantik: Interpretationsregeln für zusammengefügte Zeichen.

Entsprechende Regeln für ein Computerprogramm sind einfacher,aber auch strenger, denn Computer sind vergleichsweise dumm.

49

Page 93: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Syntax und Semantik

Programme müssen, wie unsere Sprache, nach gewissen Regelngeformt werden.

Syntax: Zusammenfügungsregeln für elementare Zeichen (Buchstaben).Semantik: Interpretationsregeln für zusammengefügte Zeichen.

Entsprechende Regeln für ein Computerprogramm sind einfacher,aber auch strenger, denn Computer sind vergleichsweise dumm.

49

Page 94: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Deutsch vs. C++

DeutschAlleen sind nicht gefährlich, Rasen ist gefährlich!(Wikipedia: Mehrdeutigkeit)

C++

// computationint b = a ∗ a; // b = a2

b = b ∗ b; // b = a4

50

Page 95: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Syntax und Semantik von C++

Syntax:

Wann ist ein Text ein C++Programm?

D.h. ist es grammatikalisch korrekt?

→ Kann vom Computer überprüft werden

Semantik:

Was bedeutet ein Programm?

Welchen Algorithmus implementiert ein Programm?

→ Braucht menschliches Verständnis52

Page 96: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Was braucht es zum Programmieren?

Editor: Programm zum Ändern, Erfassen und Speichern vonC++-ProgrammtextCompiler: Programm zum Übersetzen des Programmtexts inMaschinensprache

Computer: Gerät zum Ausführen von Programmen inMaschinenspracheBetriebssystem: Programm zur Organisation all dieser Abläufe(Dateiverwaltung, Editor-, Compiler- und Programmaufruf)

54

Page 97: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Was braucht es zum Programmieren?

Editor: Programm zum Ändern, Erfassen und Speichern vonC++-ProgrammtextCompiler: Programm zum Übersetzen des Programmtexts inMaschinenspracheComputer: Gerät zum Ausführen von Programmen inMaschinenspracheBetriebssystem: Programm zur Organisation all dieser Abläufe(Dateiverwaltung, Editor-, Compiler- und Programmaufruf)

54

Page 98: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Das erste C++ Programm

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}56

Page 99: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Wichtigste Bestandteile. . . Anweisungen

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Mache etwas (lies a ein)!

56

Page 100: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Wichtigste Bestandteile. . . Ausdrucke

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Berechne einen Wert (a2)!

56

Page 101: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

“Beiwerk”: Kommentare

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}58

Page 102: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

“Beiwerk”: Kommentare

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Kommentare

58

Page 103: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Kommentare und Layout

Dem Compiler ist’s egal...

#include <iostream>

int main(){std::cout << "Compute a^8 for a =? ";

int a; std::cin >> a; int b = a * a; b = b * b;

std::cout << a << "^8 = " << b*b << "\n";return 0;}

... uns aber nicht!

60

Page 104: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Kommentare und Layout

Dem Compiler ist’s egal...

#include <iostream>

int main(){std::cout << "Compute a^8 for a =? ";

int a; std::cin >> a; int b = a * a; b = b * b;

std::cout << a << "^8 = " << b*b << "\n";return 0;}

... uns aber nicht!

60

Page 105: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

”Beiwerk“: Include und Main-Funktion

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}61

Page 106: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

”Beiwerk“: Include und Main-Funktion

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Include-Direktive

61

Page 107: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

”Beiwerk“: Include und Main-Funktion

// Program: power8.cpp// Raise a number to the eighth power.#include <iostream>int main() {

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Funktionsdeklaration der main-Funktion

61

Page 108: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Anweisungen: Mache etwas!

int main() {// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

64

Page 109: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Anweisungen: Mache etwas!

int main() {// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Ausdrucksanweisungen

64

Page 110: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Anweisungen: Mache etwas!

int main() {// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}Rückgabeanweisung

64

Page 111: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Anweisungen – Effekte

int main() {// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Effekt: Ausgabe des Strings Compute ...

Effekt: Eingabe einer Zahl und Speichern in a

Effekt: Speichern des berechneten Wertes von a*a in b

Effekt: Speichern des berechneten Wertes von b*b in b

Effekt: Ausgabe des Wertes von a und desberechneten Wertes von b*b

Effekt: Rückgabe des Wertes 068

Page 112: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Anweisungen – Variablendefinitionen

int main() {// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b ∗ b << "\n";return 0;

}

Deklarationsanweisungen

Typ-namen

70

Page 113: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Literale

repräsentieren konstante Wertehaben festen Typ und Wertsind „syntaktische Werte“

Beispiele:

0 hat Typ int, Wert 0.

1.2e5 hat Typ double, Wert 1.2 · 105.

74

Page 114: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Variablen

repräsentieren (wechselnde)Wertehaben

NameTypWertAdresse

Beispielint a; definiert Variable mit

Name: a

Typ: int

Wert: (vorerst) undefiniert

Addresse: durch Compilerbestimmt

75

Page 115: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Variablen

repräsentieren (wechselnde)Wertehaben

NameTypWertAdresse

Beispielint a; definiert Variable mit

Name: a

Typ: int

Wert: (vorerst) undefiniert

Addresse: durch Compilerbestimmt

75

Page 116: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke: Berechne einen Wert!

repräsentieren Berechnungen

sind entweder primär (b)

oder zusammengesetzt (b*b). . .

. . . aus anderen Ausdrücken, mit Hilfe von Operatoren

haben einen Typ und einen Wert

Analogie: Baukasten

78

Page 117: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke: Berechne einen Wert!

repräsentieren Berechnungen

sind entweder primär (b)

oder zusammengesetzt (b*b). . .

. . . aus anderen Ausdrücken, mit Hilfe von Operatoren

haben einen Typ und einen Wert

Analogie: Baukasten

78

Page 118: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke: Berechne einen Wert!

repräsentieren Berechnungen

sind entweder primär (b)

oder zusammengesetzt (b*b). . .

. . . aus anderen Ausdrücken, mit Hilfe von Operatoren

haben einen Typ und einen Wert

Analogie: Baukasten

78

Page 119: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke: Berechne einen Wert!

repräsentieren Berechnungen

sind entweder primär (b)

oder zusammengesetzt (b*b). . .

. . . aus anderen Ausdrücken, mit Hilfe von Operatoren

haben einen Typ und einen Wert

Analogie: Baukasten

78

Page 120: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke: Berechne einen Wert!

repräsentieren Berechnungen

sind entweder primär (b)

oder zusammengesetzt (b*b). . .

. . . aus anderen Ausdrücken, mit Hilfe von Operatoren

haben einen Typ und einen Wert

Analogie: Baukasten

78

Page 121: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke: Berechne einen Wert!

repräsentieren Berechnungen

sind entweder primär (b)

oder zusammengesetzt (b*b). . .

. . . aus anderen Ausdrücken, mit Hilfe von Operatoren

haben einen Typ und einen Wert

Analogie: Baukasten

78

Page 122: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b * b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a<< "^8 = " << b * b << ".\ n";

return 0; 79

Page 123: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b * b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a<< "^8 = " << b * b << ".\ n";

return 0;

Variablenname, primärer Ausdruck (+ Name und Adresse)

Variablenname, primärer Ausdruck (+ Name und Adresse)

Literal, primärer Ausdruck79

Page 124: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke Baukasten

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b * b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a<< "^8 = " << b * b << ".\ n";

return 0;

Zusammengesetzer Ausdruck

Zusammengesetzer Ausdruck

79

Page 125: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Ausdrucke Baukasten

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b * b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a<< "^8 = " << b * b << ".\ n";

return 0;

Zweifach zusammengesetzter Ausdruck

Vierfach zusammengesetzter Ausdruck 79

Page 126: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b * b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a<< "^8 = " << b * b << ".\ n";return 0;

82

Page 127: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b * b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a<< "^8 = " << b * b << ".\ n";return 0;

L-Wert (Ausdruck + Adresse)

L-Wert (Ausdruck + Adresse)

R-Wert (Ausdruck, der kein L-Wert ist)82

Page 128: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b * b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a<< "^8 = " << b * b << ".\ n";return 0;

R-Wert

R-Wert

82

Page 129: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

L-Wert (“Links vom Zuweisungsoperator”)

Ausdruck mit Adresse

Wert ist der Inhalt an der Speicheradresse entsprechend demTyp des Ausdrucks.

L-Wert kann seinen Wert ändern (z.B. per Zuweisung).

Beispiel: Variablenname

83

Page 130: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

L-Wert (“Links vom Zuweisungsoperator”)

Ausdruck mit Adresse

Wert ist der Inhalt an der Speicheradresse entsprechend demTyp des Ausdrucks.

L-Wert kann seinen Wert ändern (z.B. per Zuweisung).

Beispiel: Variablenname

83

Page 131: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

R-Wert (“Rechts vom Zuweisungsoperator”)

Ausdruck der kein L-Wert ist

Beispiel: Literal 0

Jeder L-Wert kann als R-Wert benutzt werden (aber nichtumgekehrt).

Ein R-Wert kann seinen Wert nicht ändern.

84

Page 132: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

R-Wert (“Rechts vom Zuweisungsoperator”)

Ausdruck der kein L-Wert ist

Beispiel: Literal 0

Jeder L-Wert kann als R-Wert benutzt werden (aber nichtumgekehrt).

Ein R-Wert kann seinen Wert nicht ändern.

84

Page 133: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

R-Wert (“Rechts vom Zuweisungsoperator”)

Ausdruck der kein L-Wert ist

Beispiel: Literal 0

Jeder L-Wert kann als R-Wert benutzt werden (aber nichtumgekehrt).

Jedes e-Bike kann als normales Fahrrad benutzt werden, abernicht umgekehrt.

Ein R-Wert kann seinen Wert nicht ändern.

84

Page 134: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

R-Wert (“Rechts vom Zuweisungsoperator”)

Ausdruck der kein L-Wert ist

Beispiel: Literal 0

Jeder L-Wert kann als R-Wert benutzt werden (aber nichtumgekehrt).

Ein R-Wert kann seinen Wert nicht ändern.

84

Page 135: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

L-Werte und R-Werte

85

Page 136: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Operatoren und Operanden Baukasten

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b * b << "\n";return 0;

86

Page 137: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Operatoren und Operanden Baukasten

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b * b << "\n";return 0;

Linker Operand (Ausgabestrom)Rechter Operand (String)Ausgabe-Operator

86

Page 138: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Operatoren und Operanden Baukasten

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b * b << "\n";return 0;

Linker Operand (Eingabetrom)

Rechter Operand (Variablenname)Eingabe-Operator

86

Page 139: Malte Schwerho , Felix Friedrich HS 2018Informatik vs. Computer Computer science is not about machines, in the same way that astronomy is not about telescopes. Mike Fellows, US-Informatiker

Operatoren und Operanden Baukasten

// inputstd::cout << "Compute a^8 for a =? ";int a;std::cin >> a;

// computationint b = a ∗ a; // b = a^2b = b ∗ b; // b = a^4

// output b ∗ b, i.e., a^8std::cout << a << "^8 = " << b * b << "\n";return 0;

Zuweisungsoperator

Multiplikationsoperator 86