Commit 85ac65fc authored by Jaiem's avatar Jaiem
Browse files

Initial commit

parents
#ifndef ALL_INCLUDES_H
#define ALL_INCLUDES_H
#include "example.h"
#include "sm.h"
#include "veh.h"
#endif // ALL_INCLUDES_H
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
example.cpp \
sm.cpp \
veh.cpp
DISTFILES += \
cpp-git-and-gtest.pro.user
HEADERS += \
all_includes.h \
example.h \
sm.h \
veh.h
This diff is collapsed.
#include <iostream>
#include <example.h>
using namespace std;
float example_test(float a, float b){
return a + b;
}
float example_sqrtf(float a){
return a*a;
}
double example_sqrtd(double a){
return a*a;
}
#ifndef DEBUG_EXAMPLE_H
#define DEBUG_EXAMPLE_H
/*! \file debug_example.cpp
* Aufgabe: Fehler mit debugger finden -- ohne Aenderung am Code
* -- also nicht die sonst beliebten zusaetzlichen Konsole-Ausgaben einfuegen.
* \author Albrecht, Wolfgang
*/
//taken from INGICC https://olat.vcrp.de/auth/RepositoryEntry/3092185207/CourseNode/103542514315311
float example_add(float a, float b);
float example_sqrtf(float a);
double example_sqrtd(double a);
#endif // DEBUG_EXAMPLE_H
#ifndef DEBUG_EXAMPLE_H
#define DEBUG_EXAMPLE_H
//taken from INGICC https://olat.vcrp.de/auth/RepositoryEntry/3092185207/CourseNode/103542514315311
float example_add(float a, float b);
float example_sqrtf(float a);
double example_sqrtd(double a);
#endif // DEBUG_EXAMPLE_H
/*! \file sm_turbo.cpp
* Deterministischer endlicher Automat (DEA) zu "Turbo"-Beispiel aus Live-Folie
* Besprechen:
* 1. enum mit classe (nicht in Folien); static_cast<int> fuer state-Nummer;
* 2. Rahmenprogramm zum testen vs. Automaten-Kern;
* 3. Review "processEvent": a) viel reject b) MyState::end --> kein weiterer "input" erlaubt
* \author Albrecht, Wolfgang
* \version 2
* while-Schleife statt do-while, sonst Probleme mit Ende-Erkennung #
*/
#include<iostream>
#include <sm.h>
using namespace std;
MyState processEvent( MyState state, char input){
switch (state) {
case MyState::off:
if (input=='a'){
state= MyState::on;
} else {
state= MyState::reject;
}
break;
case MyState::on:
if (input=='b'){
state= MyState::turbo;
} else {
state= MyState::reject;
}
break;
case MyState::turbo:
if (input=='c'){
state= MyState::end;
} else if (input=='b'){
state= MyState::on;
} else {
state= MyState::reject;
}
break;
case MyState::end:
//if (input == irgendwas) !!!??? (kein weiterer "input" erlaubt! -- war das klar kommuniziert!? --> Anforderungsdefinition!)
state= MyState::reject;
break;
case MyState::reject:
break; //just stay
}
return state;
}
void runProcessEvent(void){
MyState actual_state= MyState::off;
char input;
cout << "Ihre Eingabe (bitte Zeichen fuer Zeichen mit Enter getrennt; Ende mit '#'):";
cin >> input;
while ( input != '#' ) {
actual_state= processEvent( actual_state, input); //(Trennung von unterschiedlichen Belangen: Ein-/Ausgabe vs. reiner Automat)
cout << "\n actual State (as number): " << static_cast<int>(actual_state) << endl;
cin >> input;
} ; // '#' ist Zusatz-Regel "ausserhalb" des Automaten; (frueherer Abbruch bei MyState::reject moeglich)
if (actual_state == MyState::end){
cout << "\n Final-State reached!" << endl;
} else {
cout << "\n Final-State NOT reached!" << endl;
}
}
#ifndef SM_H
#define SM_H
/*! \file sm_turbo.cpp
* Deterministischer endlicher Automat (DEA) zu "Turbo"-Beispiel aus Live-Folie
* Besprechen:
* 1. enum mit classe (nicht in Folien); static_cast<int> fuer state-Nummer;
* 2. Rahmenprogramm zum testen vs. Automaten-Kern;
* 3. Review "processEvent": a) viel reject b) MyState::end --> kein weiterer "input" erlaubt
* \author Albrecht, Wolfgang
* \version 2
* while-Schleife statt do-while, sonst Probleme mit Ende-Erkennung #
*/
enum class MyState {off, on, turbo, end, reject }; // reject fuer "ungueltiges" Zeichen in diesem Zustand
MyState processEvent( MyState state, char input);
void runProcessEvent(void);
#endif // SM_H
#include "veh.h"
veh veh1;
void init(double a_in,double v_in,double s_in,double Mass_in){
veh1.a = 0;
veh1.v = 0;
veh1.s = 0;
veh1.Mass = 500;
}
void simulate(){
veh1.a = veh1.F_act/veh1.Mass;
veh1.v += veh1.a;
veh1.s += veh1.v;
veh1.F_act = 0 ;
}
void accel(){
veh1.F_act = 1000;
}
#ifndef VEH_H
#define VEH_H
#include <iostream>
struct veh{
double a,v,s;
double Mass;
double F_act;
};
extern veh veh1;
void init(double a_in=0,double v_in=0,double s_in=0,double Mass_in=500);
void simulate();
void accel();
#endif // VEH_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment