main
Jan-Niclas Loosen 7 months ago
parent 16177ffa79
commit 70afef6560

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CIDR" type="CPP_MODULE" version="4" />

@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/UNI_Python.iml" filepath="$PROJECT_DIR$/.idea/UNI_Python.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/UNI_Python2.iml" filepath="$PROJECT_DIR$/.idea/UNI_Python2.iml" />
</modules>
</component>
</project>

@ -3,47 +3,72 @@
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="CMakeSettings">
<configurations>
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="42ed9a51-9564-48c5-b5fa-035301b1578d" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/hosts.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ha_11/loosen_janniclas_1540907_12.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ha_09/loosen_janniclas_1540907_10.py" beforeDir="false" afterPath="$PROJECT_DIR$/ha_09/loosen_janniclas_1540907_10.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ClangdSettings">
<option name="formatViaClangd" value="false" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 0
}]]></component>
<component name="ProjectId" id="2ad23KMVrbf8YEYMjvnrmBZ8MSS" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Universitaet/UNI_Python&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;python.debugger.dataview.coloredbydefault&quot;: &quot;false&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"C/C++ File.loosen_janniclas_1540907_12.cpp.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
"RunOnceActivity.readMode.enableVisualFormatting": "true",
"WebServerToolWindowFactoryState": "false",
"cf.first.check.clang-format": "false",
"cidr.known.project.marker": "true",
"git-widget-placeholder": "main",
"last_opened_file_path": "C:/Universitaet/UNI_Python",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"python.debugger.dataview.coloredbydefault": "false",
"vue.rearranger.settings.migration": "true"
}
}</component>
}]]></component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Universitaet\UNI_Python\ueb_01" />
</key>
</component>
<component name="RunManager" selected="Python.loosen_janniclas_1540907_10">
<component name="RunManager" selected="C/C++ File.loosen_janniclas_1540907_12.cpp">
<configuration name="loosen_janniclas_1540907_12.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="UNI_Python" TARGET_NAME="loosen_janniclas_1540907_12.cpp" CONFIG_NAME="loosen_janniclas_1540907_12.cpp">
<option name="sourceFile" value="ha_11\loosen_janniclas_1540907_12.cpp" />
<method v="2">
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="control" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="UNI_Python" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
@ -66,6 +91,7 @@
</configuration>
<configuration name="loosen_janniclas_1540907_09 (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="UNI_Python" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
@ -88,6 +114,7 @@
</configuration>
<configuration name="loosen_janniclas_1540907_09" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="UNI_Python" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
@ -110,6 +137,7 @@
</configuration>
<configuration name="loosen_janniclas_1540907_10" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="UNI_Python" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
@ -132,6 +160,7 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="C/C++ File.loosen_janniclas_1540907_12.cpp" />
<item itemvalue="Python.loosen_janniclas_1540907_10" />
<item itemvalue="Python.control" />
<item itemvalue="Python.loosen_janniclas_1540907_09 (1)" />
@ -160,6 +189,7 @@
<workItem from="1705419658987" duration="941000" />
<workItem from="1705431087533" duration="5323000" />
<workItem from="1705489565514" duration="13418000" />
<workItem from="1707215006454" duration="7963000" />
</task>
<servers />
</component>

@ -0,0 +1,66 @@
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
// use generics for a reusable method
template <typename number>
std::string create_overflow() {
number next = 2;
number valid = 0;
number iter = 0;
while(true) {
next = next * 2;
if(valid > next) {
std::string message = typeid(number).name();
message += " overflow occurred: 2**" + std::to_string(iter) + " = " + std::to_string(next);
message += " should be bigger as 2**" + std::to_string(iter - 1) + " != " + std::to_string(valid);
return message;
}
iter++; valid = next;
}
}
std::vector<bool> sieve_of_eratosthenes(int limit) {
// avoid edge cases limit=0 or limit=1
int length = limit + 2;
// preparation of a bool vector
std::vector<bool> primes(length, true);
primes[0] = false;
primes[1] = false;
// calculate sieve
for(int i = 2; i <= std::sqrt(limit); i++) {
if(primes[i]) {
for(int p = i * i; p <= limit; p += i) {
primes[p] = false;
}
}
}
return primes;
}
/*
* Anmerkung:
* Ich mag es nicht wirklich Pointer in C++ zu benutzen. Deshalb verwende ich die Klassen std::string und std::vector
* um zu verhindern, dass die Funktionen bool* bzw. char* pointer ausgeben müssen.
*/
int main() {
std::cout << create_overflow<short>() << std::endl;
std::cout << create_overflow<int>() << std::endl;
std::cout << create_overflow<long>() << std::endl;
int limit = 100;
std::vector<bool> primes = sieve_of_eratosthenes(limit);
std::cout << "Prime numbers up to " << limit << " are: ";
for (int i = 0; i < limit; ++i) {
if (primes[i]) {
std::cout << i << " ";
}
}
std::cout << std::endl;
return 0;
}

Binary file not shown.
Loading…
Cancel
Save