Compare commits
4
Commits
32c381ed6a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
872d122bb7 | ||
|
|
af8dca4694 | ||
|
|
3eb8785027 | ||
|
|
fc9f52f533 |
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* $Author: MahrTh $
|
||||
* $Rev: 118 $
|
||||
* $Date: 2015-03-21 21:39:51 +0100 (Sa, 21. Mär 2015) $
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Vektor {
|
||||
public:
|
||||
float x, y;
|
||||
|
||||
void add(Vektor vektor) {
|
||||
x += vektor.x;
|
||||
y += vektor.y;
|
||||
}
|
||||
void mul(float faktor) {
|
||||
x *= faktor;
|
||||
y *= faktor;
|
||||
}
|
||||
string text(){
|
||||
stringstream ss;
|
||||
ss << "(" << x << "," << y << ")";
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
class Koerper{
|
||||
public:
|
||||
Vektor position;
|
||||
Vektor geschwindigkeit;
|
||||
float masse;
|
||||
|
||||
Koerper(Vektor position, Vektor geschwindigkeit, float masse) {
|
||||
this->position = position;
|
||||
this->geschwindigkeit = geschwindigkeit;
|
||||
this->masse = masse;
|
||||
}
|
||||
Vektor lieferePosition() {
|
||||
return position;
|
||||
}
|
||||
Vektor liefereGeschwindigkeit() {
|
||||
return geschwindigkeit;
|
||||
}
|
||||
float liefereMasse() {
|
||||
return masse;
|
||||
}
|
||||
void bewegen(Vektor beschleunigung, float dt) {
|
||||
position.add({geschwindigkeit.x * dt, geschwindigkeit.y * dt});
|
||||
geschwindigkeit.add({beschleunigung.x * dt, beschleunigung.y * dt});
|
||||
}
|
||||
string text() {
|
||||
return position.text();
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
// Körper:
|
||||
const float MASSE = 10;
|
||||
const Vektor START_POSITION = {0,0};
|
||||
const Vektor START_GESCHWINDIGKEIT = {10,10};
|
||||
Koerper koerper = {START_POSITION,START_GESCHWINDIGKEIT,MASSE};
|
||||
// Parametrierung der auf den Körper wirkende Kräfte:
|
||||
const Vektor BESCHLEUNIGUNG_GRAVITATION = {0,-9.81}; // [m/s^2]
|
||||
const float REIBUNGSKOEFFIZIENT =-5; // [kg/s]
|
||||
// Simulation:
|
||||
const float dt = 0.1;
|
||||
for(;;) {
|
||||
cout << "Position des Koerpers: " << koerper.text() << endl;
|
||||
// Bestimmung der neuen Beschleunigung
|
||||
Vektor beschleunigung;
|
||||
beschleunigung = koerper.liefereGeschwindigkeit();
|
||||
beschleunigung.mul(REIBUNGSKOEFFIZIENT/koerper.liefereMasse());
|
||||
beschleunigung.add(BESCHLEUNIGUNG_GRAVITATION);
|
||||
// Ermittlung der neuen Position und neuen Geschwindigkeit
|
||||
koerper.bewegen(beschleunigung,dt);
|
||||
if(koerper.lieferePosition().y<=0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <iostream>
|
||||
#define EOF (-1)
|
||||
|
||||
using namespace std;
|
||||
|
||||
double addition(double ersteZahl, double zweiteZahl){
|
||||
double erg = ersteZahl + zweiteZahl;
|
||||
cout << ersteZahl<< " + " << zweiteZahl << " = " << erg << endl;
|
||||
return erg;
|
||||
}
|
||||
|
||||
double subtraktion(double ersteZahl, double zweiteZahl){
|
||||
int erg = ersteZahl - zweiteZahl;
|
||||
cout << ersteZahl<< " - " << zweiteZahl << " = " <<erg << endl;
|
||||
return erg;
|
||||
}
|
||||
|
||||
double multiplikation(double ersteZahl,double zweiteZahl){
|
||||
double erg = ersteZahl * zweiteZahl;
|
||||
cout << ersteZahl<< " * " << zweiteZahl << " = " <<erg << endl;
|
||||
return erg;
|
||||
}
|
||||
|
||||
double division(double ersteZahl, double zweiteZahl){
|
||||
double erg = ersteZahl / zweiteZahl;
|
||||
cout << ersteZahl<< " : " << zweiteZahl << " = " << erg << endl;
|
||||
return erg;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char operation, clear;
|
||||
int ersteZahl, zweiteZahl;
|
||||
bool pruef = false;
|
||||
|
||||
do {
|
||||
cout << "Welche Rechenoperation wollen Sie durchfuehren? [ + | - | / | * ]:";
|
||||
cin >> operation;
|
||||
|
||||
if (operation == '+')
|
||||
{
|
||||
pruef = true;
|
||||
} else if (operation == '*') {
|
||||
pruef = true;
|
||||
} else if (operation == '/') {
|
||||
pruef = true;
|
||||
} else if (operation == '-') {
|
||||
pruef = true;
|
||||
} else {
|
||||
cout << "Keine definierte Rechenoperation!" << endl;
|
||||
while ((clear = getchar()) != '\n' && clear != EOF) { }
|
||||
}
|
||||
} while (!pruef);
|
||||
|
||||
cout << "Erste Zahl:";
|
||||
cin >> ersteZahl;
|
||||
cout << "Zweite Zahl:";
|
||||
cin >> zweiteZahl;
|
||||
|
||||
switch (operation) {
|
||||
case '+':
|
||||
addition(ersteZahl, zweiteZahl);
|
||||
case '-':
|
||||
subtraktion(ersteZahl, zweiteZahl);
|
||||
break;
|
||||
case '*':
|
||||
multiplikation(ersteZahl, zweiteZahl);
|
||||
case '/':
|
||||
while (zweiteZahl == 0){
|
||||
cout << "Man kann nicht durch 0 teilen. Geben Sie eine neue zweite Zahl ein:";
|
||||
cin >> zweiteZahl;
|
||||
}
|
||||
division(ersteZahl, zweiteZahl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Basis {
|
||||
private:
|
||||
string name;
|
||||
public:
|
||||
Basis(string n) : name(n){}
|
||||
|
||||
string getName(){
|
||||
return name;
|
||||
}
|
||||
};
|
||||
|
||||
class Division : public Basis{
|
||||
private:
|
||||
int nenner;
|
||||
int zaehler;
|
||||
public:
|
||||
|
||||
Division(int x, int y, string z): Basis(z){
|
||||
this->nenner = x;
|
||||
this->zaehler = y;
|
||||
}
|
||||
|
||||
double getErgebnis (){
|
||||
return nenner/zaehler;
|
||||
}
|
||||
|
||||
};
|
||||
class Multiplikation : public Basis {
|
||||
private:
|
||||
int multiplikator;
|
||||
int multiplikand;
|
||||
public:
|
||||
|
||||
Multiplikation(int x, int y, string z) : Basis(z) {
|
||||
this->multiplikator = x;
|
||||
this->multiplikand = y;
|
||||
}
|
||||
|
||||
double getErgebnis() {
|
||||
return multiplikator * multiplikand;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Division d1(6, 2, "d1");
|
||||
Division d2 (4, 1, "d2");
|
||||
Multiplikation m1(5, 2, "m1");
|
||||
Multiplikation m2(d1.getErgebnis(), d2.getErgebnis(), "m2");
|
||||
Division d3(m2.getErgebnis(), 2, "d3");
|
||||
Multiplikation m3(d3.getErgebnis(), m1.getErgebnis(), "m3");
|
||||
|
||||
cout << "Ergebnisse...\n";
|
||||
cout << d1.getName() << ": " << d1.getErgebnis() << "\n";
|
||||
cout << d2.getName() << ": " << d2.getErgebnis() << "\n";
|
||||
cout << m1.getName() << ": " << m1.getErgebnis() << "\n";
|
||||
cout << m2.getName() << ": " << m2.getErgebnis() << "\n";
|
||||
cout << d3.getName() << ": " << d3.getErgebnis() << "\n";
|
||||
cout << m3.getName() << ": " << m3.getErgebnis() << "\n";
|
||||
|
||||
int iAuswahl;
|
||||
cin >> iAuswahl;
|
||||
}
|
||||
Reference in New Issue
Block a user