Update Øving 5
parent
2f86b5e6e9
commit
9242f7d03c
|
@ -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
|
|
@ -0,0 +1,79 @@
|
|||
#include "Card.h"
|
||||
|
||||
map<Suit, string> suitNames = { {Suit::clubs, "Clubs" },
|
||||
{Suit::diamonds, "Diamonds"},
|
||||
{Suit::hearts, "Hearts"},
|
||||
{Suit::spades, "Spades"} };
|
||||
|
||||
|
||||
|
||||
string suitToString(Suit s)
|
||||
{
|
||||
return suitNames[s];
|
||||
}
|
||||
|
||||
|
||||
map<Rank, string> 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";
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,146 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{ab5577f7-8f95-4259-b198-2d9690f663f7}</ProjectGuid>
|
||||
<RootNamespace>Oving_5</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>C:\Program Files\TDT4102\includes;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Card.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Card.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Card.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Card.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue