60
Uebungen/01_AdvC03.cpp
Normal file
60
Uebungen/01_AdvC03.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
15
Uebungen/01_AdvC04.cpp
Normal file
15
Uebungen/01_AdvC04.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
int iwert2 = 1000;
|
||||
unsigned int uiwert2 = -1500;
|
||||
printf("Maximum: %d\n", MAX(iwert2, uiwert2));
|
||||
// --> nicht TypeSafe
|
||||
|
||||
return 0;
|
||||
}
|
16
Uebungen/01_AdvC05.cpp
Normal file
16
Uebungen/01_AdvC05.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* C5.cpp
|
||||
*
|
||||
* Created on: 03.05.2018
|
||||
* Author: hendrik
|
||||
*/
|
||||
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
return 0;
|
||||
}
|
65
Uebungen/02_CPP01.cpp
Normal file
65
Uebungen/02_CPP01.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Main.cpp
|
||||
*
|
||||
* Created on: 07.06.2018
|
||||
* Author: hendrik
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
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<typename T>
|
||||
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;
|
||||
}
|
||||
|
113
Uebungen/02_CPP02.cpp
Normal file
113
Uebungen/02_CPP02.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
#include <iostream>
|
||||
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();
|
||||
|
||||
}
|
118
Uebungen/02_CPP03.cpp
Normal file
118
Uebungen/02_CPP03.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
#include <iostream>
|
||||
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
|
||||
|
||||
}
|
108
Uebungen/02_CPP04.cpp
Normal file
108
Uebungen/02_CPP04.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
#include <iostream>
|
||||
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;
|
||||
}
|
||||
|
116
Uebungen/02_CPP05.cpp
Normal file
116
Uebungen/02_CPP05.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 02_CPP05.cpp
|
||||
*
|
||||
* Created on: 17.06.2018
|
||||
* Author: hendrik
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
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;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user