Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d6367a0851 |
@@ -1,51 +0,0 @@
|
|||||||
//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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
103
main.cpp
103
main.cpp
@@ -1,66 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
#include "ax_funktions.hpp"
|
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
|
|
||||||
int number = 12;
|
int number = 12;
|
||||||
|
|
||||||
char Buchstabe = 'a';
|
void print_number (int);
|
||||||
|
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()
|
||||||
{
|
{
|
||||||
@@ -72,42 +15,22 @@ main()
|
|||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
ax::print_number(i); // neue Funktion unsicher und unvollständig
|
print_number(i); // neue Funktion unsicher und unvollständig
|
||||||
}
|
}
|
||||||
|
|
||||||
ax::print_number(ax::sqrt(3));
|
print_number(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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user