diff --git a/eclipse-workspace/C_CPP/C_Praktikum/.settings/language.settings.xml b/.settings/language.settings.xml similarity index 87% rename from eclipse-workspace/C_CPP/C_Praktikum/.settings/language.settings.xml rename to .settings/language.settings.xml index 6c9259c..99b3cd4 100644 --- a/eclipse-workspace/C_CPP/C_Praktikum/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/Uebungen/01_AdvC03.cpp b/Uebungen/01_AdvC03.cpp new file mode 100644 index 0000000..b4d33dd --- /dev/null +++ b/Uebungen/01_AdvC03.cpp @@ -0,0 +1,60 @@ +#include +#include + +using namespace std; + +void ausgabe(char* p[], int max); +void freeArray(char* p[], int max); + +int main(int argc, char** argv) { + + printf("Anzahl der Parameter %i\n\n", (argc - 1)); + + char* cpArray[(argc - 1)]; + + argv++; + + for (int i = 0; i < (argc - 1); ++i) { + + printf("Übergabe: %s - ", *argv); + + int size = strlen(*argv); + printf("Laenge des Parameter %i\n", size); + + cpArray[i] = (char*) malloc((size - 1) * sizeof(char*)); + + strcpy(cpArray[i], *argv); + + argv++; + } + + free(*argv); + + ausgabe(cpArray, argc - 1); + + freeArray(cpArray, argc - 1); + + ausgabe(cpArray, argc - 1); + + cout << endl; + return 0; +} + +void ausgabe(char* p[], int max) { + + cout << endl; + + for (int i = 0; i < max; ++i) { + printf("Ausgabe: %s\n", p[i]); + } + +} + +void freeArray(char* p[], int max) { + + cout << endl << "Freigeben" << endl; + + for (int i = 0; i < max; ++i) { + free(p[i]); + } +} diff --git a/Uebungen/01_AdvC04.cpp b/Uebungen/01_AdvC04.cpp new file mode 100644 index 0000000..3e2873d --- /dev/null +++ b/Uebungen/01_AdvC04.cpp @@ -0,0 +1,15 @@ + +#define MAX(a, b) ((a) < (b) ? (b) : (a)) + +#include +using namespace std; + +int main() { + + int iwert2 = 1000; + unsigned int uiwert2 = -1500; + printf("Maximum: %d\n", MAX(iwert2, uiwert2)); +// --> nicht TypeSafe + + return 0; +} diff --git a/Uebungen/01_AdvC05.cpp b/Uebungen/01_AdvC05.cpp new file mode 100644 index 0000000..cbd5c1f --- /dev/null +++ b/Uebungen/01_AdvC05.cpp @@ -0,0 +1,16 @@ +/* + * C5.cpp + * + * Created on: 03.05.2018 + * Author: hendrik + */ + + +#include +using namespace std; + + +int main() { + + return 0; +} diff --git a/Uebungen/02_CPP01.cpp b/Uebungen/02_CPP01.cpp new file mode 100644 index 0000000..12f811d --- /dev/null +++ b/Uebungen/02_CPP01.cpp @@ -0,0 +1,65 @@ +/* + * Main.cpp + * + * Created on: 07.06.2018 + * Author: hendrik + */ + +#include +using namespace std; + +void callByReferenz(int* pi) { + *pi = 10; +} + +namespace na01 { +int zahl = 20; +} + +namespace na02 { +int zahl = 30; +} + +void defaultValues(int x = 2, int y = 4) { + printf("X: %i - Y: %i\n", x, y); +} + +void func() { + printf("01\n"); +} + +void func(int i) { + printf("02: %i\n", i); +} + +template +T add(T x, T y) { + T value; + value = x + y; + return value; +} + +int main(int argc, char *argv[]) { + + printf("Hallo Welt\n"); + + int i = 0; + callByReferenz(&i); + printf("Zahl: %i\n", i); + + printf("Namespace 01: %i\n", na01::zahl); + printf("Namespace 02: %i\n", na02::zahl); + + defaultValues(); + defaultValues(8); + defaultValues(12, 16); + + func(); + func(2); + + printf("tmp01 %i\n" , add(8,9)); + printf("tmp01 %f\n" , add(1.259,8985.5)); + + return 0; +} + diff --git a/Uebungen/02_CPP02.cpp b/Uebungen/02_CPP02.cpp new file mode 100644 index 0000000..9f33881 --- /dev/null +++ b/Uebungen/02_CPP02.cpp @@ -0,0 +1,113 @@ +#include +using namespace std; + +#define ERROR_RINGPUFFER_EMPTY -1 +#define ERROR_RINGPUFFER_FULL -2 +#define RINGPUFFER_SIZE 8 + +class ringpuffer { + +private: + unsigned int uispos; //schreib + unsigned int uirpos; //lese + unsigned int uinumelements; + int iArray[RINGPUFFER_SIZE]; + +public: + ringpuffer() { + cout << "Init\n" << endl; + uispos = 0; + uirpos = 0; + uinumelements = 0; + } + + int storeelement(int ielement) { + + if ((uispos + 1 == uirpos) + || (uirpos == 0 && uispos + 1 == uinumelements)) { + printf("ERROR_RINGPUFFER_FULL\n"); + return ERROR_RINGPUFFER_FULL; + } + + iArray[uispos] = ielement; + uinumelements++; + + uispos++; + + if (uispos >= RINGPUFFER_SIZE) { + uispos = 0; + } + return 0; + } + int readelement(int& ielement) { + + if ((uirpos == uispos) && (uinumelements == 0)) { + printf("ERROR_RINGPUFFER_EMPTY\n"); + return ERROR_RINGPUFFER_EMPTY; + } + ielement = iArray[uirpos]; + uinumelements--; + uirpos++; + + if (uirpos >= RINGPUFFER_SIZE) { + uirpos = 0; + } + return 0; + } + + void printArray() { + cout << "Print Array" << endl; + for (unsigned int i = 0; i < RINGPUFFER_SIZE; i++) { + printf("Index: %i --> %i", i, iArray[i]); + if (i == uirpos) { + printf(" --> Lesezeiger"); + } + if (i == uispos) { + printf(" --> Schreibzeiger"); + } + + printf("\n"); + + } + cout << endl; + } +}; + +int main() { + + ringpuffer* rb = new ringpuffer(); + int res; + int* i = &res; + + rb->storeelement(1); + rb->storeelement(2); + rb->storeelement(3); + rb->storeelement(4); + + rb->printArray(); + + rb->readelement(*i); + printf("Read: %i\n\n", res); //1 + rb->readelement(*i); + printf("Read: %i\n\n", res); //2 + rb->readelement(*i); + printf("Read: %i\n\n", res); //3 + rb->readelement(*i); + printf("Read: %i\n\n", res); //4 + + rb->printArray(); + + rb->storeelement(8); + rb->storeelement(1); + rb->storeelement(2); + rb->storeelement(3); + rb->storeelement(4); + rb->storeelement(1); + rb->storeelement(2); + + rb->readelement(*i); + printf("Read: %i\n\n", res); //8 + + rb->printArray(); + +} diff --git a/Uebungen/02_CPP03.cpp b/Uebungen/02_CPP03.cpp new file mode 100644 index 0000000..78055ba --- /dev/null +++ b/Uebungen/02_CPP03.cpp @@ -0,0 +1,118 @@ +#include +using namespace std; + +#define ERROR_RINGPUFFER_EMPTY -1 +#define ERROR_RINGPUFFER_FULL -2 +#define RINGPUFFER_SIZE 8 + +class ringpuffer { + +private: + unsigned int uispos; //schreib + unsigned int uirpos; //lese + unsigned int uinumelements; + int iArray[RINGPUFFER_SIZE]; + +public: + ringpuffer() { + cout << "Init\n" << endl; + uispos = 0; + uirpos = 0; + uinumelements = 0; + } + + int storeelement(int ielement) { + + if ((uispos + 1 == uirpos) + || (uirpos == 0 && uispos + 1 == uinumelements)) { + printf("ERROR_RINGPUFFER_FULL\n"); + return ERROR_RINGPUFFER_FULL; + } + + iArray[uispos] = ielement; + uinumelements++; + + uispos++; + + if (uispos >= RINGPUFFER_SIZE) { + uispos = 0; + } + return 0; + } + int readelement(int& ielement) { + + if (uirpos == uispos) { + printf("ERROR_RINGPUFFER_EMPTY\n"); + return ERROR_RINGPUFFER_EMPTY; + } + ielement = iArray[uirpos]; + uinumelements--; + uirpos++; + + if (uirpos >= RINGPUFFER_SIZE) { + uirpos = 0; + } + return 0; + } + + void printArray() { + cout << "Print Array" << endl; + for (unsigned int i = 0; i < RINGPUFFER_SIZE; i++) { + printf("Index: %i --> %i", i, iArray[i]); + if (i == uirpos) { + printf(" --> Lesezeiger"); + } + if (i == uispos) { + printf(" --> Schreibzeiger"); + } + + printf("\n"); + + } + cout << endl; + } +}; + +class IOChannel { + +private: + + ringpuffer rpA[3]; + +public: + + IOChannel() { + //rpA[0] = new ringpuffer(); + } + + int storeelement(unsigned int uichannel, int ielement) { + return rpA[uichannel].storeelement(ielement); + + } + + int readelement(unsigned int uichannel, int& ielement) { + return rpA[uichannel].readelement(ielement); + } + +}; + +int main() { + int res; + int* i = &res; + + IOChannel* ioc = new IOChannel(); + + ioc->storeelement(0, 5); + ioc->storeelement(1, 10); + ioc->storeelement(2, 15); + + ioc->readelement(0, res); + printf("Read: %i\n\n", res); //5 + + ioc->readelement(2, res); + printf("Read: %i\n\n", res); //15 + + ioc->readelement(1, res); + printf("Read: %i\n\n", res); //10 + +} diff --git a/Uebungen/02_CPP04.cpp b/Uebungen/02_CPP04.cpp new file mode 100644 index 0000000..dbccdab --- /dev/null +++ b/Uebungen/02_CPP04.cpp @@ -0,0 +1,108 @@ +#include +using namespace std; + +class Shape { +protected: + static int inumberofinstances; +public: + static void printInstanzen() { + printf("Instanzen %i \n", Shape::inumberofinstances); + } + + virtual void draw() { + } + + virtual ~Shape() { + } + + Shape() { + } +}; + +class Triangle: public Shape { +public: + void draw() { + printf("Zeichne Triangle \n"); + } + ~Triangle() { + printf("Zerstoere Triangle\n"); + Shape::inumberofinstances--; + } + + Triangle() { + printf("Erstelle Triangle\n"); + inumberofinstances++; + } + +}; + +class Circle: public Shape { +public: + void draw() { + printf("Zeichne Circle \n"); + } + ~Circle() { + printf("Zerstoere Circle\n"); + Shape::inumberofinstances--; + + } + + Circle() { + printf("Erstelle Circle\n"); + Shape::inumberofinstances++; + } + +}; + +class Rectangle: public Shape { +public: + void draw() { + printf("Zeichne Rectangle \n"); + } + ~Rectangle() { + printf("Zerstoere Rectangle\n"); + Shape::inumberofinstances--; + } + + Rectangle() { + printf("Erstelle Rectangle\n"); + Shape::inumberofinstances++; + } + +}; + +int Shape::inumberofinstances = 0; + +int main(int argc, char *argv[]) { + + Triangle* tri = new Triangle(); + Circle* cir = new Circle(); + Rectangle* rec = new Rectangle(); + printf("\n"); + + Shape* shapes[10] = { }; + + shapes[0] = tri; + shapes[1] = cir; + shapes[2] = rec; + + shapes[0]->draw(); + shapes[1]->draw(); + shapes[2]->draw(); + + Shape* shp = new Shape(); + shp->printInstanzen(); + + printf("\n"); + + tri->~Triangle(); + cir->~Circle(); + rec->~Rectangle(); + + printf("\n"); + + shp->printInstanzen(); + + return 0; +} + diff --git a/Uebungen/02_CPP05.cpp b/Uebungen/02_CPP05.cpp new file mode 100644 index 0000000..31f1665 --- /dev/null +++ b/Uebungen/02_CPP05.cpp @@ -0,0 +1,116 @@ +/* + * 02_CPP05.cpp + * + * Created on: 17.06.2018 + * Author: hendrik + */ +#include +#include +using namespace std; + +class Complex { + +private: + double real; + double img; + +public: + Complex(double real, double img) { + this->real = real; + this->img = img; + } + + Complex(const Complex& c) { + this->real = c.real; + this->img = c.img; + } + + void print() { + cout << real << " + j" << img << "\n"; + } + + Complex operator+(const Complex& c) { + Complex temp(0, 0); + temp.real = real + c.real; + temp.img = img + c.img; + return temp; + } + + Complex operator-(const Complex& c) { + Complex temp(0, 0); + temp.real = real - c.real; + temp.img = img - c.img; + return temp; + } + + Complex operator*(const Complex& c) { + Complex temp(0, 0); + temp.real = (real * c.real) - (img * c.img); + temp.img = (real * c.img) + (c.real * img); + return temp; + } + + Complex operator/(const Complex& c) { + Complex temp(0, 0); + double div = (pow(c.real, 2)) + (pow(c.img, 2)); + temp.real = ((real * c.real + img * c.img) / div); + temp.img = ((img * c.real - real * c.img) / div); + + return temp; + } + + Complex operator!() { + Complex temp(0, 0); + temp.real = (real) / (pow(real, 2)) + (pow(img, 2)); + temp.img = (img) / (pow(real, 2)) + (pow(img, 2)); + return temp; + } + + friend ostream& operator<<(ostream& ostr, const Complex& c) { + ostr << c.real << "+j" << c.img; + return ostr; + } + +}; + +int main() { + + Complex R1 = Complex(50, 0); + Complex R2 = Complex(50, 0); + Complex R3 = Complex(100, 0); + Complex R4 = Complex(200, 0); + + Complex XC1 = Complex(0, -100); + Complex XC2 = Complex(0, -100); + + Complex XL1 = Complex(0, 100); + Complex XL2 = Complex(0, 100); + Complex XL3 = Complex(0, 50); + + Complex Z = Complex(0, 0); + + Complex A = Complex(0, 0); + Complex B = Complex(0, 0); + Complex C = Complex(0, 0); + Complex D = Complex(0, 0); + + Complex E = Complex(0, 0); + Complex F = Complex(0, 0); + + A = (XL1 + R1); + B = (XC1 + R2); + + C = (XC2 + R3 + XL3); + D = (XL2 + R4); + + E = (A * B) / (A + B); + F = (C * D) / (C + D); + + Z = E + F; + + Z.print(); + + return 1; + +} + diff --git a/eclipse-workspace/C_CPP/C_Praktikum/.cproject b/eclipse-workspace/C_CPP/C_Praktikum/.cproject deleted file mode 100644 index e216538..0000000 --- a/eclipse-workspace/C_CPP/C_Praktikum/.cproject +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/eclipse-workspace/C_CPP/C_Praktikum/.gitignore b/eclipse-workspace/C_CPP/C_Praktikum/.gitignore deleted file mode 100644 index 3df573f..0000000 --- a/eclipse-workspace/C_CPP/C_Praktikum/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/Debug/ diff --git a/src/02_CPP06.d b/src/02_CPP06.d new file mode 100644 index 0000000..8fd5583 --- /dev/null +++ b/src/02_CPP06.d @@ -0,0 +1 @@ +src/02_CPP06.o: src/02_CPP06.cpp diff --git a/src/02_CPP06.o b/src/02_CPP06.o new file mode 100644 index 0000000..679b060 Binary files /dev/null and b/src/02_CPP06.o differ