From 9242f7d03c2ed4235a94245fa8924757c021d4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Skaaden?= Date: Wed, 6 Feb 2019 21:40:10 +0100 Subject: [PATCH] =?UTF-8?q?Update=20=C3=98ving=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Oving 5/Oving 5.sln | 31 +++++ Oving 5/Oving 5/Card.cpp | 79 +++++++++++++ Oving 5/Oving 5/Card.h | 45 ++++++++ Oving 5/Oving 5/Oving 5.vcxproj | 146 ++++++++++++++++++++++++ Oving 5/Oving 5/Oving 5.vcxproj.filters | 30 +++++ Oving 5/Oving 5/main.cpp | 35 ++++++ 6 files changed, 366 insertions(+) create mode 100644 Oving 5/Oving 5.sln create mode 100644 Oving 5/Oving 5/Card.cpp create mode 100644 Oving 5/Oving 5/Card.h create mode 100644 Oving 5/Oving 5/Oving 5.vcxproj create mode 100644 Oving 5/Oving 5/Oving 5.vcxproj.filters create mode 100644 Oving 5/Oving 5/main.cpp diff --git a/Oving 5/Oving 5.sln b/Oving 5/Oving 5.sln new file mode 100644 index 0000000..a43fc3a --- /dev/null +++ b/Oving 5/Oving 5.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.329 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Oving 5", "Oving 5\Oving 5.vcxproj", "{AB5577F7-8F95-4259-B198-2D9690F663F7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Debug|x64.ActiveCfg = Debug|x64 + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Debug|x64.Build.0 = Debug|x64 + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Debug|x86.ActiveCfg = Debug|Win32 + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Debug|x86.Build.0 = Debug|Win32 + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Release|x64.ActiveCfg = Release|x64 + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Release|x64.Build.0 = Release|x64 + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Release|x86.ActiveCfg = Release|Win32 + {AB5577F7-8F95-4259-B198-2D9690F663F7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {45C09BE7-875A-44D0-8CB8-6F2564F3F8C1} + EndGlobalSection +EndGlobal diff --git a/Oving 5/Oving 5/Card.cpp b/Oving 5/Oving 5/Card.cpp new file mode 100644 index 0000000..45d21dd --- /dev/null +++ b/Oving 5/Oving 5/Card.cpp @@ -0,0 +1,79 @@ +#include "Card.h" + +map suitNames = { {Suit::clubs, "Clubs" }, + {Suit::diamonds, "Diamonds"}, + {Suit::hearts, "Hearts"}, + {Suit::spades, "Spades"} }; + + + +string suitToString(Suit s) +{ + return suitNames[s]; +} + + +map rankNames = { {Rank::two, "Two" }, + {Rank::three, "Three"}, + {Rank::four, "Four"}, + {Rank::five, "Five"}, + {Rank::six, "Six"}, + {Rank::seven, "Seven"}, + {Rank::eight, "Eight"}, + {Rank::nine, "Nine"}, + {Rank::ten, "Ten"}, + {Rank::jack, "Jack"}, + {Rank::queen, "Queen"}, + {Rank::king, "King"}, + {Rank::ace, "Ace"} }; + +string rankToString(Rank r) +{ + return rankNames[r]; +} + + +string toString(CardStruct card) +{ + return rankToString(card.rank) + " of " + suitToString(card.suit); +} + +string toStringShort(CardStruct card) +{ + string suit = suitToString(card.suit); + string rank = to_string(int(card.rank)); + return suit.at(0) + rank; + +} + +Card::Card() +{ + valid = false; +} + +Card::Card(Suit suit, Rank rank) +{ + s = suit; + r = rank; + valid = true; +} + +inline Suit Card::suit() { return s; } +inline Rank Card::rank() { return r; } +inline bool Card::isValid() { return valid; } + +string Card::toString() +{ + if (valid) + return rankToString(r) + " of " + suitToString(s); + else + return "Invalid card"; +} + +string Card::toStringShort() +{ + if (valid) + return suitToString(s).at(0) + to_string(int(r)); + else + return "Invalid card"; +} diff --git a/Oving 5/Oving 5/Card.h b/Oving 5/Oving 5/Card.h new file mode 100644 index 0000000..49bf5e1 --- /dev/null +++ b/Oving 5/Oving 5/Card.h @@ -0,0 +1,45 @@ +#pragma once +#include "std_lib_facilities.h" + + +enum class Suit { clubs, diamonds, hearts, spades }; + +enum class Rank { two = 2, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace }; + +string suitToString(Suit s); + +string rankToString(Rank r); + +struct CardStruct +{ + Suit suit; + Rank rank; +}; + +string toString(CardStruct card); + +string toStringShort(CardStruct card); + +#pragma region Card - Class + + +class Card +{ +public: + Card(); + Card(Suit suit, Rank rank); + + Suit suit(); + Rank rank(); + bool isValid(); + string toString(); + string toStringShort(); +private: + Suit s; + Rank r; + bool valid; +}; + + + +#pragma endregion \ No newline at end of file diff --git a/Oving 5/Oving 5/Oving 5.vcxproj b/Oving 5/Oving 5/Oving 5.vcxproj new file mode 100644 index 0000000..1b09cd0 --- /dev/null +++ b/Oving 5/Oving 5/Oving 5.vcxproj @@ -0,0 +1,146 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {ab5577f7-8f95-4259-b198-2d9690f663f7} + Oving_5 + 10.0.17763.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + C:\Program Files\TDT4102\includes;$(IncludePath) + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + Console + + + + + + + + + + + + + \ No newline at end of file diff --git a/Oving 5/Oving 5/Oving 5.vcxproj.filters b/Oving 5/Oving 5/Oving 5.vcxproj.filters new file mode 100644 index 0000000..e542a30 --- /dev/null +++ b/Oving 5/Oving 5/Oving 5.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Source Files + + + \ No newline at end of file diff --git a/Oving 5/Oving 5/main.cpp b/Oving 5/Oving 5/main.cpp new file mode 100644 index 0000000..8f1ded8 --- /dev/null +++ b/Oving 5/Oving 5/main.cpp @@ -0,0 +1,35 @@ +#include "std_lib_facilities.h" +#include "Card.h" + +int main(){ + +#pragma region Task 1 + // a - d + // Testing functions and mapping + cout << suitToString(Suit::diamonds) << endl; + cout << rankToString(Rank::ace) << endl; + + // e + /* + Det er lurt å bruke symboler fordi + - Mindre sansynlighet for misforståelse + - Lettere å lese koden til senere + */ + +#pragma endregion + +#pragma region Task 2 + CardStruct card1 = { Suit::spades, Rank::ace }; + CardStruct card2 = { Suit::diamonds, Rank::ten }; + cout << toString(card1) << endl; + cout << toStringShort(card2) << endl; + + +#pragma endregion + + Card c = Card(Suit::clubs, Rank::two); + + cout << c.toString() << endl; + + return 0; +} \ No newline at end of file