Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c178c7b35 | |||
| 40ef2c1de4 | |||
| d1b2cc19ee | |||
| c622b5cc6f | |||
| 98bbf386bf | |||
| dca133f8ea | |||
| 270e7cc872 | |||
| 3ac7122589 |
51
ax_funktions.hpp
Normal file
51
ax_funktions.hpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
105
main.cpp
105
main.cpp
@@ -1,9 +1,66 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "ax_funktions.hpp"
|
||||||
|
|
||||||
|
#include "SDL2/SDL.h"
|
||||||
|
|
||||||
int number = 12;
|
int number = 12;
|
||||||
|
|
||||||
void print_number (int);
|
char Buchstabe = 'a';
|
||||||
int sqrt (int);
|
|
||||||
|
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()
|
main()
|
||||||
{
|
{
|
||||||
@@ -15,22 +72,42 @@ main()
|
|||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
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++)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void print_number(int x)
|
|
||||||
{
|
{
|
||||||
std::cout << "Die Zahl ist: " << x << std::endl;
|
ax::print_char(Buchstabe+i);
|
||||||
std::cout << "Das doppelte der Zahl ist: " << x*2 << std::endl;
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sqrt(int x){
|
|
||||||
return x*x;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user