1 / 5

Lösung 4.1 Strukturierte Datentypen

Lösung 4.1 Strukturierte Datentypen. 1. Umformen der „Kneisel“-Notation - Einfache Datentypen bool switch1; switch1 = false; // = 0 switch1 = switch1 && (!switch1); // = 1 and 0 = 0 int i; i = 1; // = 1 i = i + 32;´ // = 1 + 32 = 33

halil
Download Presentation

Lösung 4.1 Strukturierte Datentypen

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lösung 4.1 Strukturierte Datentypen • 1. Umformen der „Kneisel“-Notation - Einfache Datentypen • bool switch1;switch1 = false; // = 0switch1 = switch1 && (!switch1); // = 1 and 0 = 0 • int i;i = 1; // = 1i = i + 32;´ // = 1 + 32 = 33 • char symbol;symbol = ´A´; // = „A“symbol = symbol + 32;´ // = „A“ + 32 = „a“ • enum ampelfarbe {gruen,gelb,rot};ampelfarbe = gruen; // = gruenampelfarbe = ampelfarbe +1 ; ´ // = gruen + 1 = gelb • float pi, flaeche, radius; // all real !pi = 3.141; // needs not to be more accurateradius = 5; // might be changed by userflaeche = 2 * pi * pow(radius,2); // common formula

  2. Lösung 4.1 Strukturierte Datentypen • 1. Umformen der „Kneisel“-Notation - Strukturierte Datentypen • float m[3][2];float v[4];v[2] = 5.03; v[3] = 4.12;m[0][1] = v[2] * 12 - v[3]; • struct { int tag; int monat; } d ;d.monat = 10;d.tag = 20; • struct { char[20] name; enum {m,f} sex;union { int IQ; real muscle; } } adam, eva; • typedef struct Datum {int year; enum month {jan,feb,...}; int day; } Akt_Datum; // Akt_Datum hierstruct { char[20] surname; char[20] forename; Datum birthday; } Person; // alternativ: Datum Akt_Datum;

  3. Lösung 4.1 Strukturierte Datentypen • siehe Kapitel 4.1 • Arrays verkettete Listen maximale Anzahl der Elemente maximale Anzahl der Elementeist bekannt ist nicht bekannt Elemente nur eines Typs Elemente unterschiedlichenerlaubt Typs (einfacher) möglich Belegung des Speicherbereichs für Belegung nur des tatsächlich maximale Anzahl von Elementen benötigten Speicherbereiches Einfacher Zugriff über Index Zugriff durch Durchlaufen der Liste Einfache Implementierung „Komplexere“ Implementierung Sortierung „nur“ durch Umkopieren Sortierung durch neue Verkettungmöglich möglich ... ...

  4. Lösung 4.1 Strukturierte Datentypen 4,5 Es gibt (unendlich) viele Lösungen für die Konstruktion einer Datenstruktur, daher sei hier nur eine mögliche Vorgehensweise beschrieben: • Suche alle beteiligten Objekte (z.B. durch Brainstorming) • Stelle die Objekte zueinander in Beziehung • Ist-Teil-von-Beziehung (Aggregation) • ... (bei OO-Sprachen insb.: Erbt von) • Stelle die Wertebereiche fest • Gibt es „generische“ Objekte ( = grundlegende Objekte, die z.B. in mehrerern Aggregationen vorkommen, auch in anderen Objekten) • Bilde „generische Objekte entsprechend Ihrer Aggregationen als Record (oder bei Listenstruktur als Array) ab • Bilde das zu modellierende Objekt - auch unter Verwendung der generischen Objekte -als Record (bzw. Liste) ab. • Beachte die Vor- und Nachteile dynamischer Strukturen. Eventuell benötigt man aus Effizienzgründen (-> Algorithmik) weitere Hilfsobjekte.

  5. in C++ Notationstruct list {int value; struct list{ int value; next *list; }; naxt *list; prev *list; } in C++ Notatioonstruct net (int value; next* net[max_succesors]; }; Lösung 4.2 Abstrakte Datentypen <int> <int> <int> <int> <int> <int> ... ... <int> <int> <int> <int> <int> <int> <int> <int> <int>

More Related