Compare commits

...

8 Commits

Author SHA1 Message Date
1c178c7b35 Classe hinzugefügt 2025-10-12 19:40:57 +02:00
40ef2c1de4 Fahrzeugklasse begonnen, theorie verstanden nächstes thema 2025-10-11 18:45:39 +02:00
d1b2cc19ee Call By Ref test 2025-10-11 18:06:31 +02:00
c622b5cc6f Main.cpp aktualisiert 2025-10-11 08:30:42 +02:00
98bbf386bf templeteFunktion allgemein und speziell eingefügt 2025-10-04 15:26:39 +02:00
dca133f8ea test 2025-10-04 14:12:44 +02:00
270e7cc872 charshift funktion 2025-10-04 13:50:24 +02:00
3ac7122589 funktionsheader und funktionsnamespace hinzugefügt 2025-10-04 10:47:38 +02:00
2 changed files with 141 additions and 13 deletions

51
ax_funktions.hpp Normal file
View File

@@ -0,0 +1,51 @@
//Funktionsdeklaration ax_funktions.hpp
#pragma once
namespace ax{
void print_number(int x)
{
std::cout << "Die Zahl ist: " << x << std::endl;
std::cout << "Das doppelte der Zahl ist: " << x*2 << std::endl;
}
void print_char(char x)
{
std::cout << x;
}
int sqrt(int x){
return x*x;
}
char shift(char x){
return x-1;
}
//allgmeine Funktion Deklaration ohne Argumente oder returns für einen unbekannten Datentyp
template<typename T> std::string type_name();
//Spezialisierte Implementation von type_name() für einen entsprechenden Datentyp vgl. mit überladung
template<> std::string type_name<int>() {return "Integer";}
template<> std::string type_name<char>(){return "Char";}
template<> std::string type_name<float>(){return "Float";}
template<> std::string type_name<double>(){return "Double";}
template<> std::string type_name<bool>(){return "Bool";}
template<typename T>
void ausgebene(T a){
std::cout << a << " ist vom Type " << type_name<T>()<< std::endl ;
}
//CallByRefference
int fn_CtUp (int &a){
a = ++a;
return 1;
}
}

101
main.cpp
View File

@@ -1,9 +1,66 @@
#include <iostream>
#include <string>
#include "ax_funktions.hpp"
#include "SDL2/SDL.h"
int number = 12;
void print_number (int);
int sqrt (int);
char Buchstabe = 'a';
class Fahrzeug
{
private:
int kw;
float ps;
float verbrauch;
public:
std::string Hersteller;
Fahrzeug(std::string s_Hersteller, int i_kw);
~Fahrzeug();
void mechanical_view();
float fn_enginechange(int new_kw);
};
Fahrzeug::Fahrzeug(std::string s_Hersteller, int i_kw)
{
kw = i_kw;
ps = i_kw * 1.36;
Hersteller = s_Hersteller;
verbrauch = 6.3;
}
Fahrzeug::~Fahrzeug()
{
}
float Fahrzeug::fn_enginechange(int new_kw){
float cost = 0;
cost = 100+new_kw*10;
this->verbrauch = new_kw/(100*.3);
this->kw = new_kw;
this->ps = new_kw*1.36;
return cost;
}
void Fahrzeug::mechanical_view(){
std::cout <<"Das Gerät ist von "<< Hersteller << " und hat eine Leistung von "<< kw <<"kw ("<<ps <<" ps)"<<std::endl;
}
float fn_tunung(Fahrzeug &geraet){
float cost = 0.0;
geraet.Hersteller = "BMW M";
cost = 25;
return cost;
}
main()
{
@@ -15,22 +72,42 @@ main()
for (int i = 0; i < 2; i++)
{
print_number(i); // neue Funktion unsicher und unvollständig
ax::print_number(i); // neue Funktion unsicher und unvollständig
}
print_number(sqrt(3));
ax::print_number(ax::sqrt(3));
};
for (int i = 0; i < 26; i++)
{
ax::print_char(Buchstabe+i);
std::cout<< " wird zu: " << ax::shift(Buchstabe + i)<< std::endl;
}
double testdouble = 3.1416;
ax::ausgebene(Buchstabe);
ax::ausgebene(42);
ax::ausgebene(true);
ax::ausgebene(testdouble);
ax::ausgebene(number);
ax::fn_CtUp(number);
ax::ausgebene(number);
Fahrzeug erstes_Auto("BMW", 100);
erstes_Auto.mechanical_view();
std::cout << "Ich wusste nur das es ein " << erstes_Auto.Hersteller << " ist"<<std::endl;
fn_tunung(erstes_Auto);
std::cout << "Nun ist es ein " << erstes_Auto.Hersteller << " !"<<std::endl;
erstes_Auto.fn_enginechange(180);
erstes_Auto.mechanical_view();
void print_number(int x)
{
std::cout << "Die Zahl ist: " << x << std::endl;
std::cout << "Das doppelte der Zahl ist: " << x*2 << std::endl;
}
int sqrt(int x){
return x*x;
}