diff --git a/Mathe/Classes.cpp b/Mathe/Classes.cpp new file mode 100644 index 0000000..5f62639 --- /dev/null +++ b/Mathe/Classes.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +class Point +{ + public: + double X, Y; + + void setX(double x) + { + X = x; + } + + void setY(double y) + { + Y = y; + } + + Point(double x = 0, double y = 0) + { + X = x; + Y = y; + } + + void print() + { + std::cout << "(" << X << "," << Y << ")"; + } +}; + +class Line +{ + public: + Point P, Q; + double b, m; + + void setPoint(bool p, Point point) + { + if(p==0) + { + Q.setX(point.X); + Q.setY(point.Y); + } + else + { + P.setX(point.X); + P.setY(point.Y); + } + } + + void distance() + { + std::cout << sqrt((P.X-Q.X)*(P.X-Q.X)+(P.Y-Q.Y)*(P.Y-Q.Y)); + } + + void gradient() + { + m = (P.Y-Q.Y)/(P.X-Q.X); + } + + void nullPointX() + { + b = (-P.X)*(P.Y-Q.Y)/(P.X-Q.X)+(P.Y); + std::cout << b; + } + + void nullPointY() + { + std::cout << (P.X)*(P.Y-Q.Y)/(P.X-Q.X)/((P.Y-Q.Y)/(P.X-Q.X)); + } + + void print() + { + gradient(); + + std::cout << m <<"*x + "; + + nullPointX(); + } +}; + +int main() +{ + Point P(3,5), Q(5,3); + Line g; + g.setPoint(0, Q); + g.setPoint(1, P); + g.print(); + getchar(); +} diff --git a/Schleifen.cpp b/Schleifen.cpp new file mode 100644 index 0000000..a803f67 --- /dev/null +++ b/Schleifen.cpp @@ -0,0 +1,92 @@ +#include +#include +#include + +int main() +{ + long long depth; + std::string input; + + std::cout << "Geben sie die Tiefe ein: "; + getline(std::cin, input); + std::stringstream(input) >> depth; + + if(depth<2) + { + std::cout << "ERROR: Zahl muss größer als 1 sein."; + getchar(); + return(1); + } + + for(long long idx = 0; idx0) std::cout << "*"; + + std::cout << "\n"; + } + + for(long long idx = 0; idx<2*depth-1; idx++) + { + std::cout << "*"; + } + + for(long long idx = 0; idx +#include +#include +int main() +{ + std::string stringInput; + unsigned long long day, month, year; + short daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30}; + + std::cout << "Gib den Tag des Monats ein: "; + getline(std::cin, stringInput); + std::stringstream(stringInput) >> day; + + if(day>31 || day<1) + { + std::cout << "ERROR: Der eingegebene Tag existiert nicht."; + return(1); + } + + std::cout << "Gib den Monat ein: "; + getline(std::cin, stringInput); + std::stringstream(stringInput) >> month; + + if(month>12 || month<1) + { + std::cout << "ERROR: Der eingegebene Monat existiert nicht."; + return(1); + } + + if(day>daysInMonth[month] && month!=2 || month==2 && day>29) + { + std::cout << "ERROR: Es wurden zuviele Tage f\x81r diesen Monat eingegeben."; + return(1); + } + + if(day==29 && month==2) daysInMonth[1]++; + + std::cout << "Gib das Jahr ein: "; + getline(std::cin, stringInput); + std::stringstream(stringInput) >> year; + + if(year<0) + { + std::cout << "ERROR: Der 1. Januar 0 liegt in der Zukunft."; + return(1); + } + + if(day==29 && month == 2 && (year%4!=0 || year%100==0 && year%400!=0)) + { + std::cout << "ERROR: Die bereits erfolgten Eingaben benötigen ein Schaltjahr."; + return(1); + } + + std::cout << "\nVom 1. Januar 0 bis zum " << day << "." << month << "." << year; + + for(short idx = 0; idx +#include +#include +#include + +int main() +{ + std::string input; + short day, month, daysInMonth[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, weekday, year; + + std::cout << "Gib das Tagesdatum ein: "; + getline(std::cin, input); + std::stringstream(input) >> day; + + if(day==0 || day>31) + { + std::cout << "\nERROR: Das eingegebene Tagesdatum existiert nicht."; + getch(); + return(1); + } + + std::cout << "Gib den Monat ein: "; + getline(std::cin, input); + std::stringstream(input) >> month; + + if(daysInMonth[month-1]12 || month==0) + { + std::cout << "\nERROR: Der eingegebene Tag existiert nicht."; + getch(); + return(1); + } + + std::cout << "Gib das jahr ein: "; + getline(std::cin, input); + std::stringstream(input) >> year; + + if(year>10000 || year<0) + { + std::cout << "\nERROR: Im eingegeben Jahr lässt sich der Wochentag nicht ermitteln."; + getch(); + return(1); + } + + if(day==29 && month==2 && (year%4!=0 || year%100==0)) + { + std::cout << "\nERROR: Die Eingaben ben\x94tigen ein Schaltjahr."; + getch(); + return(1); + } + + std::cout << "\nDer " << day << "." << month << "." << year << " war ein "; + + if(month==1 || month==2) year -=1; + + switch (month) + { + case 1: month = 0; break; + case 8: month = 1; break; + case 2: + case 6: month = 3; break; + case 9: + case 12: month = 4; break; + case 4: + case 7: month = 5; break; + case 10: month = 6; break; + default: month = 2; break; + } + + weekday = (day+month+(year%100)+(year%100/4)+year/400-2*(year/100))%7; + + while(weekday<0) weekday += 7; + + switch(weekday) + { + case 0: std::cout << "Sonntag"; break; + case 1: std::cout << "Montag"; break; + case 2: std::cout << "Dienstag"; break; + case 3: std::cout << "Mittwoch"; break; + case 4: std::cout << "Donnerstag"; break; + case 5: std::cout << "Freitag"; break; + case 6: std::cout << "Samstag"; break; + } + + getch(); + return(0); +}