Commit 959f3697 authored by Alexander Kratz's avatar Alexander Kratz
Browse files

add p1

parent f196704c
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
Praktikum_1
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
\ 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
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Praktikum 1.iml" filepath="$PROJECT_DIR$/.idea/Praktikum 1.iml" />
</modules>
</component>
</project>
\ No newline at end of file
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
return 0;
}
\ No newline at end of file
#include <iostream>
#include <math.h>
#include "Decoder.hpp"
using namespace std;
void Decoder::decode(Widerstand r){
double result = 0;
/* Die ersten beiden Farbbänder werden in result überführt */
result = static_cast<double>(r.getErste())*10+static_cast<double>(r.getZweite());
/* Für Fünfbandwiderstände wird zusätzlich das dritte Farbband in result überführt */
if(!r.isVierband()){
result *= 10;
result += static_cast<double>(r.getDritte());
}
/* Der Multiplikator wird auf result angewendet */
result *= (static_cast<double>(pow(10,static_cast<signed int>(r.getMult()))));
/* Formatierte Ausgabe */
if((result/1000000)>=1){
cout << result/1000000 << "M";
} else if((result/1000)>=1){
cout << result/1000 << "k";
} else if(result<1){
cout << result*1000 << "m";
}else {
cout << result;
}
cout << "Ω ±" << static_cast<double>(r.getTol()) / 100 << "%" << endl;
}
Widerstand Decoder::encode(double r, double tol_d, bool vierband){
/* Anzahl der stellen von R */
int stellen = static_cast<int>(log10(r)) +1;
/* Führende Ziffer */
int first = static_cast<int>(r/(pow(10,stellen-1)));
/* Zweite Ziffer */
int second = static_cast<int>(r/(pow(10,stellen-2))) - 10*first;
/* Dritte Ziffer */
int third = static_cast<int>(r/(pow(10,stellen-3))) - 100*first - 10*second;
/* Multiplikator für Vierbandwiderstand*/
int mult =stellen-2;
/* Ermitteln des Toleranzbandes aus dem double */
Toleranz tol;
// switch(static_cast<int>(tol_d*100)){
// case 100: tol = Toleranz::braun; break;
// case 200: tol = Toleranz::rot; break;
// case 50: tol = Toleranz::gruen; break;
// case 25: tol = Toleranz::blau; break;
// case 10: tol = Toleranz::violett; break;
// case 500: tol = Toleranz::gold; break;
// case 1000: tol = Toleranz::silber; break;
// case 2000: tol = Toleranz::standart; break;
// default: tol = Toleranz::standart; cout << "Keine legale Toleranz. Toleranz wird auf ±20 gesetzt" << endl;
// }
tol = static_cast<Toleranz>(tol_d*100);
cout << static_cast<double>(tol) << endl;
/* Zurückgeben eines Fünfbandwiderstandes */
if(!vierband){
/* Prüfung ob Stellen abgeschnitten werden */
if(((static_cast<int>(r/pow(10,stellen-3))*pow(10,stellen-3))-r)!=0){
cout << "Widerstandswert " << r << " kann nicht ohne Abweichung encodiert werden" << endl;
}
/* Vor der Rückgabe wird Mult dekrementiert */
Widerstand rOut(static_cast<Farbband>(first),static_cast<Farbband>(second),static_cast<Farbband>(third),static_cast<Multiplikator>(--mult),tol);
return rOut;
}
if(((static_cast<int>(r/pow(10,stellen-2))*pow(10,stellen-2))-r)!=0){
cout << "Widerstandswert " << r << " kann nicht ohne Abweichung encodiert werden" << endl;
}
/* Zurückgeben eines Vierbandwiderstandes */
Widerstand rOut(static_cast<Farbband>(first),static_cast<Farbband>(second),static_cast<Multiplikator>(mult),tol);
return rOut;
}
#ifndef _DECODER_HPP
#define _DECODER_HPP
#include "Resistor.hpp"
class Decoder{
public:
void decode(Widerstand r);
Widerstand encode(double r, double tol_d, bool vierband);
};
#endif //_DECODER_HPP
\ No newline at end of file
#include "Resistor.hpp"
Widerstand::Widerstand(Farbband erste, Farbband zweite, Multiplikator mult, Toleranz tol) :
vierband(true),
erste(erste),
zweite(zweite),
dritte(dritte),
mult(mult),
tol(tol){
// this->vierband = true;
// this->erste = erste;
// this->zweite = zweite;
// this->mult = mult;
// this->tol = tol;
}
Widerstand::Widerstand(Farbband erste, Farbband zweite, Farbband dritte, Multiplikator mult, Toleranz tol) :
vierband(false),
erste(erste),
zweite(zweite),
dritte(dritte),
mult(mult),
tol(tol){
// this->vierband = false;
// this->erste = erste;
// this->zweite = zweite;
// this->dritte = dritte;
// this->mult = mult;
// this->tol = tol;
}
bool Widerstand::isVierband(){
return vierband;
}
Farbband Widerstand::getErste(){
return erste;
}
Farbband Widerstand::getZweite(){
return zweite;
}
Farbband Widerstand::getDritte(){
return dritte;
}
Multiplikator Widerstand::getMult(){
return mult;
}
Toleranz Widerstand::getTol(){
return tol;
}
#ifndef _RESISTOR_HPP
#define _RESISTOR_HPP
enum class Farbband {schwarz,braun,rot,orange,gelb,gruen,blau,violett,grau,weiss};
/* Multiplikatorwerte in 10^x*/
enum class Multiplikator {silber = -2,gold,schwarz,braun,rot,orange,gelb,gruen,blau};
/* Toleranzwerte in 1/100% */
enum class Toleranz {braun=100,rot=200,gruen=50,blau=25,violett=10,gold=500,silber=1000,standart=2000};
class Widerstand{
public:
Widerstand(Farbband erste, Farbband zweite, Multiplikator mult, Toleranz tol);
Widerstand(Farbband erste, Farbband zweite, Farbband dritte, Multiplikator mult, Toleranz tol);
bool isVierband();
Farbband getErste();
Farbband getZweite();
Farbband getDritte();
Multiplikator getMult();
Toleranz getTol();
private:
bool vierband;
Farbband erste,zweite,dritte;
Multiplikator mult;
Toleranz tol;
};
#endif //RESISTOR_HPP
#include <iostream>
#include "Decoder.hpp"
using namespace std;
int main(){
Widerstand r1(Farbband::schwarz,Farbband::braun,Multiplikator::silber,Toleranz::standart);
Widerstand r2(Farbband::gelb,Farbband::violett,Multiplikator::braun,Toleranz::standart);
Widerstand r3(Farbband::braun,Farbband::schwarz,Multiplikator::rot,Toleranz::gold);
Widerstand r4(Farbband::weiss,Farbband::gruen,Farbband::braun,Multiplikator::gelb,Toleranz::gruen);
Decoder decoder;
cout << "R1: ";
decoder.decode(r1);
cout << "R2: ";
decoder.decode(r2);
cout << "R3: ";
decoder.decode(r3);
cout << "R4: ";
decoder.decode(r4);
decoder.decode(decoder.encode(7400,0.3,true));
decoder.decode(decoder.encode(7450,0.5,true));
decoder.decode(decoder.encode(7456,0.5,false));
decoder.decode(decoder.encode(1,0.5,false));
decoder.decode(decoder.encode(1.5,0.5,false));
decoder.decode(decoder.encode(1.55,0.5,true));
return 0;
}
\ No newline at end of file
cmake_minimum_required(VERSION 3.17)
project(Praktikum_1)
set(CMAKE_CXX_STANDARD 17)
include_directories("Aufgabe 1")
include_directories("Aufgabe 2")
add_executable(Restistor
"Aufgabe 2/Decoder.cpp"
"Aufgabe 2/Decoder.hpp"
"Aufgabe 2/main.cpp"
"Aufgabe 2/Resistor.cpp"
"Aufgabe 2/Resistor.hpp")
add_executable(A1
"Aufgabe 1/main.cpp")
\ No newline at end of file
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 "")
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