Tutoren

LV Termin Tutor Kontakt
Gruppe 1 Mo, 13:00 - 15:00 David Bidner prog-tutor-david@iicm.edu
Gruppe 2 Mo, 15:00 - 17:00 Michael Hancianu prog-tutor-michael@iicm.edu
Gruppe 3 Mo, 17:00 - 19:00 Roman Walch prog-tutor-roman@iicm.tugraz.at
Gruppe 10 Di, 11:00 - 13:00 Valentin Leutgeb prog-tutor-leutgeb@iicm.tugraz.at
Gruppe 4 Di, 13:00 - 15:00 Florian Hager prog-tutor-fhager@iicm.tugraz.at
Gruppe 5 Di, 15:00 - 17:00 Paul Nagele prog-tutor-paul@iicm.tugraz.at
Gruppe 6 Di, 17:00 - 19:00 Philipp Loibl prog-tutor-ploibl@iicm.tugraz.at
Gruppe 7 Mi, 13:00 - 15:00 Florian Bernhardt prog-tutor-fbernhardt@iicm.tugraz.at
Gruppe 8 Mi, 15:00 - 17:00 Marcel Nageler prog-tutor-marcel@iicm.tugraz.at
Gruppe 9 Mi, 17:00 - 19:00 Angela Promitzer prog-tutor-angela@iicm.edu

Tutoriumsinhalt

  • Fragen zur Vorlesung
  • Hilfestellungen zu den Beispielen
  • Erarbeiten ähnlicher Beispiele
  • Eure Vorschläge?
Achtung: Tutorien nicht jede Woche!
siehe Zeiteinteilung

Ablauf des heutigen Tutoriums

  • Ablauf Übung
  • stdin/stdout
  • Namespaces
  • Wert vs. Zeiger vs. Referenz
  • Vectoren und Strings
  • GIT

Resourcen

Wiki:
https://palme.iicm.tugraz.at/wiki/SEP
Abgabesystem:
https://palme.iicm.tugraz.at/
Tutorium:
http://progslides.github.io/ss18/
Newsgroup (nntp://news.tugraz.at:119/):
  • tu-graz.lv.sep
  • tu-graz.lv.sep.organisatorisches
  • tu-graz.lv.sep.uebungsgruppen

Alle nicht persönlichen Fragen ausschließlich in der Newsgroup stellen!

Bewertung - Teil I

  • Praxis Teil (3er Gruppen)
    • 3 Deliverables
    • Alle 3 Abgaben verpflichtend
    • Keine Spätabgabe
    • TU Graz Git verpflichtend!
    • 60 Punkte
  • Vorlesungsteil Teil (= Klausur)
    • 40 Punkte

Bewertung - Teil II

  • Verteilung der Punkte im Praxisteil
    • Formale Kriterien
      • Deliverable 1 - 3: 8 Punkte
    • Funktionale Kriterien
      • Deliverable 1: 6 Punkte
      • Deliverable 2: 12 Punkte
      • Deliverable 3 Basis: 6 Punkte
      • Deliverable 3 Aufbau: 12 Punkte
  • 2 Abgabegespräche
    • Anwesenheitspflicht für alle Gruppenmitglieder

Bewertung - Teil III

  • Keine Gruppenanmeldung = keine Beurteilung

  • Negative Beurteilung, bei
    • fehlenden Abgaben (DEADLINE!)
    • Plagiaten, zusätzlich Meldung an Studiendekan!
    • Weniger als 50% der Punkte auf den Praxis Teil
    • Weniger als 50% der Punkte auf die Klausur

  • Mitarbeiten am Übungsbeispiel!
    • Sonst: Punkteabzüge beim AG! (Bis zu -100%)

Lernziele

  • Korrektheit und Struktur des Codes
    • Speicherfehler
    • Warnings
    • Sinnvolle Aufteilung in Funktionen
    • Übersichtlicher Kontrollfluß
    • etc. ...
  • OOP Konzepte
    • Richtige Kapselung
    • Sinnvolle Einteilung in Klassen
    • etc. ...
  • Dokumentation und Programmierstil
  • Testcases

Für genaue Auflistung möglicher Fehler, siehe Palme Fehlerquellen

Schreiben auf stdout

#include <iostream>

int main()
{
  std::cout << "Hallo Welt!" << std::endl;
  return 0;
}

Verketten von Strings und anderen Datentypen möglich
std::cout << "The answer to life, the universe "
        << "and everything is " << 42 << std::endl;
std::cout << " string1 is "  << string1
        << " , it's length is "  << string1.length() << std::endl;
std::cout << 3.14 << " * " << 5 << std::endl;

Formatieren der Ausgabe

  • Ändern der Basis
    int value = 32;
    std::cout << value << " = 0x" << std::hex
            << value << std::endl;
    std::cout << value << " = 0" << std::oct
            << value << std::endl;
    
  • Ausrichtung
    #include <iomanip>
    int value = 32;
    std::cout << std::setw(8) << value << std::endl;
    std::cout << std::setfill('0') << std::setw(8)
            << value << std::endl;
  • Kommastellen
    #include <iomanip>
    double value = 3.14159265;
    std::cout << std::setprecision(3) << value << std::endl;
    

Lesen von stdin

#include <iostream>

int main()
{
  int age, number;
  std::cout << "Type in age and matrikelnumber" << std::endl;
  std::cin >> age >> number;
  std::cout << "Age:" << age << " Number:" << number << std::endl;

  return 0;
}

Namespaces

#include <iostream>
using std::endl;

int main()
{
  int age, number;
  std::cout << "Hello World!" << endl;
}

#include <iostream>
using namespace std; // possible but bad!

int main()
{
  int age, number;
  cout << "Hello World!" << endl;
}

Wert vs. Zeiger vs. Referenz (Beispiel 1)

#include <iostream>

void funcValue(int x, int val)
{
  x += val;
}

int main()
{
  int v = 3;
  funcValue(v, 4);
  std::cout << v << std::endl;
}

Wert vs. Zeiger vs. Referenz (Beispiel 2)

#include <iostream>

void funcPointer(int* x, int val)
{
  *x += val;
}

int main()
{
  int v = 3;
  funcPointer(&v, 4);
  std::cout << v << std::endl;
}

Wert vs. Zeiger vs. Referenz (Beispiel 3)

#include <iostream>

void funcReference(int& x, int val)
{
  x += val;
}

int main()
{
  int v = 3;
  funcReference(v, 4);
  std::cout << v << std::endl;
}

Wert vs. Zeiger vs. Referenz

  • Referenzen können nicht NULL sein, Pointer schon
  • Referenzen können wie normale Variablen verwendet werden
  • Bei Referenzen und Pointern wird nur die Adresse übergeben, bei Werten wird kopiert

Vector

  • inkludieren mit
  • #include <vector>
  • Erstellen eines Vektors
    using std::vector;
    ...
    vector<int> int_vector;
    oder
    std::vector<int> int_vector;

  • Wichtigste Methoden

    Anzahl der Elemente im Vektor
    int len = int_vector.size();
    Wert 3 an Position 0 einfügen
    int_vector.insert(0, 3);
    Wert 3 an letzter Stelle einfügen
    int_vector.push_back(3);
    Wert an Position 0
    int element = int_vector[0];

Vector

std::vector<int> int_vector;
int_vector.push_back(42);
int_vector.push_back(13);
int_vector.push_back(37);
Zugriff auf alle Elemente durch Index...
int i;
for(i = 0; i < int_vector.size(); i++)
  std::cout << int_vector[i] << std::endl;
...oder durch Iterator
for(vector<int>::iterator it = int_vector.begin(); it != int_vector.end(); it++)
  std::cout << *it << std::endl;
...oder einfach
for(auto &it : int_vector)
  std::cout << it << std::endl;

Strings

  • Repräsentieren Text bzw. Zeichenketten
  • C++ Variante von char*
  • Bietet sehr viele komfortable Funktionen zur Bearbeitung von Text
#include <string>
#include <iostream>

int main()
{
  std::string str("Hello World!");

  std::cout << str << std::endl;

  return 0;
}
Ausgabe:
Hello World!

Strings: Zugriff auf Zeichen mit "[ ]" oder string::at

#include <string>
#include <iostream>

int main()
{
  std::string str("Hello World!");

  std::cout << "Second character of str: " << str[1] << std::endl;

  std::cout << "Seventh character of str: " << str.at(6) << std::endl;

  str[1] = 'Y';

  std::cout << "Second character of str: " << str[1] << std::endl;

  return 0;
}
Ausgabe:
Second character of str: e
Seventh character of str: W
Second character of str: Y

Strings: Anhängen von Text mit string::append

#include <string>
#include <iostream>

int main()
{
  std::string str("Hello World!");
  std::string strSEP("SEP> ");

  std::cout << strSEP << std::endl;

  strSEP.append(str);

  std::cout << strSEP << std::endl;

  return 0;
}
Ausgabe:
SEP>
SEP> Hello World!

Strings: Anhängen von Text mit "+="-Operator

#include <string>
#include <iostream>

int main()
{
  std::string str("Hello World!");
  std::string strSEP("SEP> ");

  std::cout << strSEP << std::endl;

  strSEP += str;

  std::cout << strSEP << std::endl;

  return 0;
}
Ausgabe:
SEP>
SEP> Hello World!

Strings: Kopieren/Zuweisen mit "="-Operator

#include <string>
#include <iostream>

int main()
{
  std::string str;
  str = "Hello";

  std::cout << str << std::endl;

  str = "World!";

  std::cout << str << std::endl;

  return 0;
}
Ausgabe:
Hello
World!

Strings: Kopieren/Zuweisen mit "="-Operator

#include <string>
#include <iostream>

int main()
{
  std::string str("Hello World!");
  std::string strSEP("SEP> ");

  std::cout << strSEP << std::endl;

  strSEP = str;

  std::cout << strSEP << std::endl;

  return 0;
}
Ausgabe:
SEP>
Hello World!

Strings: Länge bestimmen mit string::length

#include <string>
#include <iostream>

int main()
{
  std::string str("SEP> ");

  std::cout << "length of " << str << ": " << str.length() << std::endl;

  str += "Hello World!";

  std::cout << "length of " << str << ": " << str.length() << std::endl;

  return 0;
}
Ausgabe:
length of SEP> : 5
length of SEP> Hello World!: 17

Strings: Vergleichen mit string::compare

#include <string>
#include <iostream>

int main()
{
  std::string str("Hello World!");
  std::string strSEP("SEP> ");

  if(str.compare(strSEP) == 0)
  {
    //strings are equal
    std::cout << str << " == " << strSEP << std::endl;
  }
  else
  {
    //strings are not equal
    std::cout << str << " != " << strSEP << std::endl;
  }

  return 0;
}
Ausgabe:
Hello World! != SEP>

Strings: Vergleichen mit "=="-Operator

#include <string>
#include <iostream>

int main()
{
  std::string str("Hello World!");
  std::string strSEP("SEP> ");

  if(str == strSEP)
  {
    //strings are equal
    std::cout << str << " == " << strSEP << std::endl;
  }
  else
  {
    //strings are not equal
    std::cout << str << " != " << strSEP << std::endl;
  }

  return 0;
}
Ausgabe:
Hello World! != SEP>

Strings: Umwandlung von Zahlen zu Strings mit std::to_string

#include <string>
#include <iostream>

int main()
{
  std::string pi_str = "pi is ";
  pi_str += std::to_string(3.1415926);

  std::cout << pi_str << std::endl;

  int forty_two = 42;

  std::string str = "answer to life the universe and everything is ";

  str += std::to_string(forty_two);

  std::cout << str << std::endl;

  return 0;
}
Ausgabe:
pi is 3.141593
answer to life the universe and everything is 42

Strings erzeugen

#include <string>
#include <sstream>
#include <iostream>

int main()
{
  int groupno = 2;

  std::ostringstream buffer;
  buffer << "Hallo Gruppe " << groupno << "!";
  std::string text(buffer.str());
  std::cout << text << std::endl;

  // oder einfach
  std::string text2 = "Hallo Gruppe " + std::to_string(groupno) + "!";
  std::cout << text2 << std::endl;
}

GIT

GIT

  • Das Übungsbeispiel muss mit GIT versioniert werden
  • Repository erstellen auf git.tugraz.at
    • Name: SEP18_GroupXXXXX (Bsp Gr24.: SEP18_Group00024)
    • Euren Tutor einladen!
    • Repository auf private lassen!
  • Framework Upstream einrichten!
    • Siehe Anleitung in der Aufgabenstellung ab Donnerstag

GIT - commands

  • clone
    • git clone <repository-url>
  • add
    • git add <filename(s)>
  • commit
    • git commit -m "<message>"
  • push
    • git push origin <branchname>
  • pull
    • git pull origin <branchname>

GIT - sonstiges

  • gitk
  • branching / merging
  • ssh Key support
  • tagging

Bis zum nächsten Tutorium!