Compare commits
No commits in common. "3405208295108a92583b8c1d7d422f2b65f3c603" and "b1ac6cfb4767532f6eb0cb4dff5774ae72c7c361" have entirely different histories.
3405208295
...
b1ac6cfb47
6 changed files with 1 additions and 191 deletions
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug",
|
||||
"program": "${command:cmake.launchTargetPath}",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
}
|
||||
]
|
||||
}
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
|
@ -1,8 +1,4 @@
|
|||
{
|
||||
"editor.detectIndentation": false,
|
||||
"editor.insertSpaces": false,
|
||||
"cmake.configureEnvironment": {
|
||||
"CC": "clang",
|
||||
"CXX": "clang++"
|
||||
},
|
||||
"editor.insertSpaces": false
|
||||
}
|
||||
|
|
|
@ -5,6 +5,3 @@ add_executable(sqrt sqrt.cc)
|
|||
target_link_libraries(sqrt PRIVATE Math)
|
||||
add_executable(inheritance inheritance.cc)
|
||||
add_executable(enumerations enumerations.cc)
|
||||
add_executable(namespaces namespaces.cc)
|
||||
add_executable(FunctionArguments FunctionArguments.cc)
|
||||
add_executable(exceptions exceptions.cc)
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
void sus(std::string susValue, std::string& susReference)
|
||||
{
|
||||
susValue = "sus?";
|
||||
susReference = "sussy?";
|
||||
|
||||
std::cout << "sus(std::string susValue, std::string& susReference) has ran" << std::endl;
|
||||
}
|
||||
|
||||
void print_string(std::string nameOf, std::string& string)
|
||||
{
|
||||
std::cout << "The value of " << nameOf << " is " << string << std::endl;
|
||||
}
|
||||
|
||||
void print_sussy_strings(std::string& sus1, std::string& sus2)
|
||||
{
|
||||
print_string("sus1", sus1);
|
||||
print_string("sus2", sus2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string sus1 = "this is the first sussy string";
|
||||
std::string sus2 = "this is the second sussy string";
|
||||
|
||||
print_sussy_strings(sus1, sus2);
|
||||
sus(sus1, sus2);
|
||||
print_sussy_strings(sus1, sus2);
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Crewmate {
|
||||
enum class Type {
|
||||
Imposter,
|
||||
Crewmate
|
||||
};
|
||||
class NotImposterException : public std::exception {
|
||||
private:
|
||||
const char* message;
|
||||
|
||||
public:
|
||||
NotImposterException(const char* msg)
|
||||
: message(msg)
|
||||
{
|
||||
}
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return message;
|
||||
}
|
||||
};
|
||||
class NotCrewmateException : public std::exception {
|
||||
private:
|
||||
const char* message;
|
||||
|
||||
public:
|
||||
NotCrewmateException(const char* msg)
|
||||
: message(msg)
|
||||
{
|
||||
}
|
||||
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return message;
|
||||
}
|
||||
};
|
||||
class Crewmate {
|
||||
public:
|
||||
Crewmate(Type type)
|
||||
{
|
||||
this->type = type;
|
||||
}
|
||||
|
||||
void is_imposter()
|
||||
{
|
||||
switch (this->type) {
|
||||
case Type::Imposter:
|
||||
std::cout << "this crewmate is an imposter. sussy." << std::endl;
|
||||
break;
|
||||
case Type::Crewmate:
|
||||
throw NotImposterException("this crewmate is not an imposter. not sussy.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
void is_crewmate()
|
||||
{
|
||||
switch (this->type) {
|
||||
case Type::Imposter:
|
||||
throw NotCrewmateException("this crewmate is not a crewmate. sussy.");
|
||||
break;
|
||||
case Type::Crewmate:
|
||||
std::cout << "this crewmate is a crewmate. not sussy." << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void invariant_testing()
|
||||
{
|
||||
switch (this->type) {
|
||||
|
||||
case Type::Imposter:
|
||||
throw NotCrewmateException("this crewmate is not a crewmate. sussy.");
|
||||
case Type::Crewmate:
|
||||
throw NotImposterException("this crewmate is not an imposter. not sussy.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Type type;
|
||||
};
|
||||
}
|
||||
|
||||
void exception_handler(const std::exception& exception, const std::string prefix = "Exception: ")
|
||||
{
|
||||
std::cerr << prefix << exception.what() << std::endl;
|
||||
}
|
||||
|
||||
void invariant_test(Crewmate::Crewmate& crewmate)
|
||||
{
|
||||
try {
|
||||
crewmate.invariant_testing();
|
||||
} catch (const Crewmate::NotImposterException& err) {
|
||||
exception_handler(err, "Imposter Exception: ");
|
||||
} catch (const Crewmate::NotCrewmateException& err) {
|
||||
exception_handler(err, "Crewmate Exception: ");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Crewmate::Crewmate imposter(Crewmate::Type::Imposter);
|
||||
Crewmate::Crewmate crewmate(Crewmate::Type::Crewmate);
|
||||
|
||||
try {
|
||||
imposter.is_imposter();
|
||||
imposter.is_crewmate();
|
||||
} catch (const Crewmate::NotCrewmateException& err) {
|
||||
exception_handler(err);
|
||||
}
|
||||
|
||||
try {
|
||||
crewmate.is_crewmate();
|
||||
crewmate.is_imposter();
|
||||
} catch (const Crewmate::NotImposterException& err) {
|
||||
exception_handler(err);
|
||||
}
|
||||
|
||||
invariant_test(imposter);
|
||||
invariant_test(crewmate);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
namespace Imposter {
|
||||
class Namespace {
|
||||
public:
|
||||
static void sussy_function() {
|
||||
std::cout << "This is a sus function." << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int main() {
|
||||
Imposter::Namespace::sussy_function();
|
||||
}
|
Loading…
Reference in a new issue