Commit f196704c authored by Alexander Kratz's avatar Alexander Kratz
Browse files

initial commit

parents
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
Praktikum_2
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
\ No newline at end of file
//
// Created by etiuser on 08.12.20.
//
#include "Bauteil.hpp"
string Bauteil::getName() const{
return this->name;
}
void Bauteil::setName(string name) {
this->name = name;
}
bool Bauteil::isPrinted() const {
return this->printed;
}
void Bauteil::setPrinted(bool printed) {
this->printed = printed;
}
int Bauteil::getId() const{
return this->id;
}
void Bauteil::setId(int id) {
this->id = id;
}
\ No newline at end of file
//
// Created by etiuser on 05.12.20.
//
#ifndef PRAKTIKUM_2_BAUTEIL_HPP
#define PRAKTIKUM_2_BAUTEIL_HPP
#include <vector>
#include <string>
using namespace std;
struct PARAMETER{
double wert;
string einheit;
string art;
};
class Bauteil{
public:
virtual PARAMETER getParameter() = 0;
[[nodiscard]] string getName() const;
void setName(string name);
[[nodiscard]] bool isPrinted() const;
void setPrinted(bool printed);
[[nodiscard]] int getId() const;
void setId(int id);
vector<Bauteil*> nachfolger;
private:
int id = 0;
bool printed = false;
string name;
};
#endif //PRAKTIKUM_2_BAUTEIL_HPP
cmake_minimum_required(VERSION 3.17)
project(Praktikum_2)
set(CMAKE_CXX_STANDARD 17)
add_executable(Praktikum_2 main.cpp Bauteil.hpp Spannungsquelle.cpp Spannungsquelle.hpp Widerstand.cpp Widerstand.hpp Stromkreis.cpp Stromkreis.hpp Bauteil.cpp)
\ No newline at end of file
//
// Created by etiuser on 05.12.20.
//
#include "Spannungsquelle.hpp"
#include <stdexcept>
Spannungsquelle::Spannungsquelle(std::string name, double spannung) : Bauteil() , spannung(spannung){
this->setName(name);
if(spannung == 0){
throw invalid_argument("Die Spannungsquelle muss eine Spannung erzeugen");
}
}
PARAMETER Spannungsquelle::getParameter(){
return {this->spannung,"V","Spannungsquelle"};
}
\ No newline at end of file
//
// Created by etiuser on 05.12.20.
//
#ifndef PRAKTIKUM_2_SPANNUNGSQUELLE_HPP
#define PRAKTIKUM_2_SPANNUNGSQUELLE_HPP
#include "Bauteil.hpp"
class Spannungsquelle : public Bauteil{
public:
Spannungsquelle(std::string name, double spannung);
private:
double spannung;
PARAMETER getParameter() override;
};
#endif //PRAKTIKUM_2_SPANNUNGSQUELLE_HPP
//
// Created by etiuser on 05.12.20.
//
#include <iostream>
#include <algorithm>
#include "Stromkreis.hpp"
#include "Bauteil.hpp"
using namespace std;
Stromkreis::Stromkreis(Spannungsquelle &anfang) : anfang(&anfang){
if(anfang.getId() != 0){
throw logic_error("Die Spannungsquelle ist bereits in einem anderen Stromkreis verbaut!");
} else{
this->id = counter;
counter++;
anfang.setId(this->id);
}
}
//Verbindet 2 Bauteile. Vorgaenger muss dafür bereits teil des Stromkreises sein
void Stromkreis::verbinde(Bauteil& vorgaenger, Bauteil& nachfolger){
if(vorgaenger.getId() == this->id){
if(nachfolger.getId() == 0 || nachfolger.getId() == this->id) {
vorgaenger.nachfolger.push_back(&nachfolger);
nachfolger.setId(this->id);
} else {
// cout << nachfolger.getName() << " ist schon in einem anderen Stromkreis" << endl;
throw invalid_argument(nachfolger.getName() + " ist bereits in einem anderen Stromkreis verbaut");
}
} else {
// cout << vorgaenger.getName() << " ist nicht Teil des Stomkreises" << endl;
throw invalid_argument(vorgaenger.getName() + " ist nicht Teil des Stomkreises");
}
}
//Nimmt den Stromkreis in Betrieb und gibt die Parameter der Bauteile aus
void Stromkreis::startRek(Bauteil &anfang){
if(find(this->anfang->nachfolger.begin(), this->anfang->nachfolger.end(),this->anfang) != this->anfang->nachfolger.end()){
throw runtime_error("Kurzschluss");
}
if(find(anfang.nachfolger.begin(), anfang.nachfolger.end(), this->anfang) != anfang.nachfolger.end()){
uHatVorgaenger = true;
}
if(anfang.nachfolger.empty() ){
offenerZweig = true;
}
cout << anfang.getParameter().art << " " << anfang.getName() << ": " << anfang.getParameter().wert << anfang.getParameter().einheit << endl;
anfang.setPrinted(true);
for(auto teil : anfang.nachfolger){
if(teil == this->anfang || teil->isPrinted()) continue; //Verhindert unendliches durchiterieren
startRek(*teil);
}
if(&anfang == this->anfang){
setAllUnprinted(anfang);
if(!uHatVorgaenger || offenerZweig){
cout << "Vg: " << uHatVorgaenger << endl << "offen: " << offenerZweig << endl;
throw logic_error("Der Stromkreis ist offen");
}
uHatVorgaenger = false;
offenerZweig = false;
}
}
void Stromkreis::start(){
startRek(*this->anfang);
}
//Prüft rekursiv, ob sich ein Bauteil im Stromkreis befindet
//bool Stromkreis::istVorhanden(Bauteil &anfang, Bauteil &pruef){
// if(&anfang==&pruef) return true;
// for(auto teil: anfang.nachfolger){
// if(teil == this->anfang) continue; //Verhindert unendliches durchiterieren
// if(istVorhanden(*teil, pruef)){
// return true;
// }
//
// }
// return false;
//}
void Stromkreis::setAllUnprinted(Bauteil &anfang){
if(&anfang == this->anfang){
this->anfang->setPrinted(false);
}
if(!anfang.nachfolger.empty()) {
for (auto teil : anfang.nachfolger) {
if (teil == this->anfang || !teil->isPrinted()) continue; //Verhindert unendliches durchiterieren
teil->setPrinted(false);
setAllUnprinted(*teil);
}
}
}
void Stromkreis::getGesamt(Bauteil &anfang) {
if(typeid(anfang) != typeid(*this->anfang) ){
}
// for(auto teil : anfang.nachfolger){
// if(teil == this->anfang) continue; //Verhindert unendliches durchiterieren
// getGesamt(*teil);
// }
}
//
// Created by etiuser on 05.12.20.
//
#ifndef PRAKTIKUM_2_STROMKREIS_HPP
#define PRAKTIKUM_2_STROMKREIS_HPP
#include <vector>
#include "Bauteil.hpp"
#include "Spannungsquelle.hpp"
using namespace std;
class Stromkreis{
public:
explicit Stromkreis(Spannungsquelle& anfang);
void verbinde(Bauteil& vorgaenger, Bauteil& nachfolger);
void start();
void getGesamt(Bauteil &anfang);
private:
Spannungsquelle* anfang;
void startRek(Bauteil &anfang);
void setAllUnprinted(Bauteil &anfang);
int id;
};
static int counter = 1;
static bool uHatVorgaenger = false;
static bool offenerZweig = false;
#endif //PRAKTIKUM_2_STROMKREIS_HPP
//
// Created by etiuser on 05.12.20.
//
#include <stdexcept>
#include <iostream>
#include "Widerstand.hpp"
Widerstand::Widerstand(std::string name, double widerstandwert) : Bauteil() , widerstandswert(widerstandwert){
this->setName(name);
if(widerstandwert <= 0){
throw invalid_argument("Der Widerstand muss einen positiven Widerstandswert haben");
}
}
PARAMETER Widerstand::getParameter(){
return {this->widerstandswert,"Ω","Widerstand"};
}
Widerstand::~Widerstand(){
std::cout << "destroy " << this->getName() << "\n";
}
//
// Created by etiuser on 05.12.20.
//
#ifndef PRAKTIKUM_2_WIDERSTAND_HPP
#define PRAKTIKUM_2_WIDERSTAND_HPP
#include "Bauteil.hpp"
class Widerstand : public Bauteil{
public:
Widerstand(std::string name, double widerstandwert);
~Widerstand();
private:
double widerstandswert;
PARAMETER getParameter() override;
};
#endif //PRAKTIKUM_2_WIDERSTAND_HPP
This diff is collapsed.
set(CMAKE_C_COMPILER "/usr/bin/cc")
set(CMAKE_C_COMPILER_ARG1 "")
set(CMAKE_C_COMPILER_ID "GNU")
set(CMAKE_C_COMPILER_VERSION "9.3.0")
set(CMAKE_C_COMPILER_VERSION_INTERNAL "")
set(CMAKE_C_COMPILER_WRAPPER "")
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "11")
set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert")
set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes")
set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros")
set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert")
set(CMAKE_C_PLATFORM_ID "Linux")
set(CMAKE_C_SIMULATE_ID "")
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "")
set(CMAKE_C_SIMULATE_VERSION "")
set(CMAKE_AR "/usr/bin/ar")
set(CMAKE_C_COMPILER_AR "/usr/bin/gcc-ar-9")
set(CMAKE_RANLIB "/usr/bin/ranlib")
set(CMAKE_C_COMPILER_RANLIB "/usr/bin/gcc-ranlib-9")
set(CMAKE_LINKER "/usr/bin/ld")
set(CMAKE_MT "")
set(CMAKE_COMPILER_IS_GNUCC 1)
set(CMAKE_C_COMPILER_LOADED 1)
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_C_ABI_COMPILED TRUE)
set(CMAKE_COMPILER_IS_MINGW )
set(CMAKE_COMPILER_IS_CYGWIN )
if(CMAKE_COMPILER_IS_CYGWIN)
set(CYGWIN 1)
set(UNIX 1)
endif()
set(CMAKE_C_COMPILER_ENV_VAR "CC")
if(CMAKE_COMPILER_IS_MINGW)
set(MINGW 1)
endif()
set(CMAKE_C_COMPILER_ID_RUN 1)
set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m)
set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
set(CMAKE_C_LINKER_PREFERENCE 10)
# Save compiler ABI information.
set(CMAKE_C_SIZEOF_DATA_PTR "8")
set(CMAKE_C_COMPILER_ABI "ELF")
set(CMAKE_C_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
if(CMAKE_C_SIZEOF_DATA_PTR)
set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}")
endif()
if(CMAKE_C_COMPILER_ABI)
set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}")
endif()
if(CMAKE_C_LIBRARY_ARCHITECTURE)
set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
endif()
set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "")
if(CMAKE_C_CL_SHOWINCLUDES_PREFIX)
set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}")
endif()
set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include")
set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "gcc;gcc_s;c;gcc;gcc_s")
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib")
set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
set(CMAKE_CXX_COMPILER "/usr/bin/c++")
set(CMAKE_CXX_COMPILER_ARG1 "")
set(CMAKE_CXX_COMPILER_ID "GNU")
set(CMAKE_CXX_COMPILER_VERSION "9.3.0")
set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "")
set(CMAKE_CXX_COMPILER_WRAPPER "")
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "14")
set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20")
set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters")
set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates")
set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates")
set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17")
set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20")
set(CMAKE_CXX_PLATFORM_ID "Linux")
set(CMAKE_CXX_SIMULATE_ID "")
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "")
set(CMAKE_CXX_SIMULATE_VERSION "")
set(CMAKE_AR "/usr/bin/ar")
set(CMAKE_CXX_COMPILER_AR "/usr/bin/gcc-ar-9")
set(CMAKE_RANLIB "/usr/bin/ranlib")
set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/gcc-ranlib-9")
set(CMAKE_LINKER "/usr/bin/ld")
set(CMAKE_MT "")
set(CMAKE_COMPILER_IS_GNUCXX 1)
set(CMAKE_CXX_COMPILER_LOADED 1)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
set(CMAKE_CXX_ABI_COMPILED TRUE)
set(CMAKE_COMPILER_IS_MINGW )
set(CMAKE_COMPILER_IS_CYGWIN )
if(CMAKE_COMPILER_IS_CYGWIN)
set(CYGWIN 1)
set(UNIX 1)
endif()
set(CMAKE_CXX_COMPILER_ENV_VAR "CXX")
if(CMAKE_COMPILER_IS_MINGW)
set(MINGW 1)
endif()
set(CMAKE_CXX_COMPILER_ID_RUN 1)
set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;CPP)
set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)
foreach (lang C OBJC OBJCXX)
if (CMAKE_${lang}_COMPILER_ID_RUN)
foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS)
list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension})
endforeach()
endif()
endforeach()
set(CMAKE_CXX_LINKER_PREFERENCE 30)
set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1)
# Save compiler ABI information.
set(CMAKE_CXX_SIZEOF_DATA_PTR "8")
set(CMAKE_CXX_COMPILER_ABI "ELF")
set(CMAKE_CXX_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
if(CMAKE_CXX_SIZEOF_DATA_PTR)
set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}")
endif()
if(CMAKE_CXX_COMPILER_ABI)
set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}")
endif()
if(CMAKE_CXX_LIBRARY_ARCHITECTURE)
set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
endif()
set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "")
if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX)
set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}")
endif()
set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/usr/include/c++/9;/usr/include/x86_64-linux-gnu/c++/9;/usr/include/c++/9/backward;/usr/lib/gcc/x86_64-linux-gnu/9/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include")
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "stdc++;m;gcc_s;gcc;c;gcc_s;gcc")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-linux-gnu/9;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib")
set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
set(CMAKE_HOST_SYSTEM "Linux-5.4.0-56-generic")
set(CMAKE_HOST_SYSTEM_NAME "Linux")
set(CMAKE_HOST_SYSTEM_VERSION "5.4.0-56-generic")
set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64")
set(CMAKE_SYSTEM "Linux-5.4.0-56-generic")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION "5.4.0-56-generic")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(CMAKE_CROSSCOMPILING "FALSE")
set(CMAKE_SYSTEM_LOADED 1)
Markdown is supported
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