Skip to content

Commit 6c58651

Browse files
committed
Add week 2 projects
1 parent 3778195 commit 6c58651

File tree

259 files changed

+75327
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+75327
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{18b87cb0-500c-4760-9f70-3bd1b2bd947c}</ProjectGuid>
25+
<RootNamespace>Classes2Basics</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>Console</SubSystem>
82+
<GenerateDebugInformation>true</GenerateDebugInformation>
83+
</Link>
84+
</ItemDefinitionGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<FunctionLevelLinking>true</FunctionLevelLinking>
89+
<IntrinsicFunctions>true</IntrinsicFunctions>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
</ClCompile>
94+
<Link>
95+
<SubSystem>Console</SubSystem>
96+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
97+
<OptimizeReferences>true</OptimizeReferences>
98+
<GenerateDebugInformation>true</GenerateDebugInformation>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102+
<ClCompile>
103+
<WarningLevel>Level3</WarningLevel>
104+
<SDLCheck>true</SDLCheck>
105+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106+
<ConformanceMode>true</ConformanceMode>
107+
</ClCompile>
108+
<Link>
109+
<SubSystem>Console</SubSystem>
110+
<GenerateDebugInformation>true</GenerateDebugInformation>
111+
</Link>
112+
</ItemDefinitionGroup>
113+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
114+
<ClCompile>
115+
<WarningLevel>Level3</WarningLevel>
116+
<FunctionLevelLinking>true</FunctionLevelLinking>
117+
<IntrinsicFunctions>true</IntrinsicFunctions>
118+
<SDLCheck>true</SDLCheck>
119+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
<ConformanceMode>true</ConformanceMode>
121+
</ClCompile>
122+
<Link>
123+
<SubSystem>Console</SubSystem>
124+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
125+
<OptimizeReferences>true</OptimizeReferences>
126+
<GenerateDebugInformation>true</GenerateDebugInformation>
127+
</Link>
128+
</ItemDefinitionGroup>
129+
<ItemGroup>
130+
<ClCompile Include="Container.cpp" />
131+
<ClCompile Include="main.cpp" />
132+
<ClCompile Include="Square.cpp" />
133+
<ClCompile Include="Time.cpp" />
134+
</ItemGroup>
135+
<ItemGroup>
136+
<ClInclude Include="Container.h" />
137+
<ClInclude Include="Square.h" />
138+
<ClInclude Include="Time.h" />
139+
</ItemGroup>
140+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
141+
<ImportGroup Label="ExtensionTargets">
142+
</ImportGroup>
143+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<ClCompile Include="Square.cpp">
15+
<Filter>Source Files</Filter>
16+
</ClCompile>
17+
<ClCompile Include="Time.cpp">
18+
<Filter>Source Files</Filter>
19+
</ClCompile>
20+
<ClCompile Include="main.cpp">
21+
<Filter>Source Files</Filter>
22+
</ClCompile>
23+
<ClCompile Include="Container.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
<ItemGroup>
28+
<ClInclude Include="Square.h">
29+
<Filter>Header Files</Filter>
30+
</ClInclude>
31+
<ClInclude Include="Time.h">
32+
<Filter>Header Files</Filter>
33+
</ClInclude>
34+
<ClInclude Include="Container.h">
35+
<Filter>Header Files</Filter>
36+
</ClInclude>
37+
</ItemGroup>
38+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ShowAllFiles>false</ShowAllFiles>
5+
</PropertyGroup>
6+
</Project>

Classes2Basics/Container.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Knapecz, Adam - 1DAE11
2+
#include "Container.h"
3+
#include <exception>
4+
5+
Container::Container(int capacity)
6+
: m_Size{}
7+
, m_Capacity{capacity}
8+
, m_pDynArray{nullptr}
9+
{
10+
m_pDynArray = new int[m_Capacity];
11+
}
12+
13+
Container::~Container()
14+
{
15+
delete m_pDynArray;
16+
}
17+
18+
int Container::Size() const
19+
{
20+
return m_Size;
21+
}
22+
23+
int Container::Capacity() const
24+
{
25+
return m_Capacity;
26+
}
27+
28+
int Container::Get(int index) const
29+
{
30+
if (index < 0)
31+
{
32+
throw std::exception{ "Negative out-of-range exception" };
33+
}
34+
if (index >= m_Size)
35+
{
36+
throw std::exception{ "Positive out-of-range exception" };
37+
}
38+
return m_pDynArray[index];
39+
}
40+
41+
void Container::Set(int index, int newValue)
42+
{
43+
if (index < 0)
44+
{
45+
throw std::exception{ "Negative out-of-range exception" };
46+
}
47+
if (index >= m_Size)
48+
{
49+
throw std::exception{ "Positive out-of-range exception" };
50+
}
51+
m_pDynArray[index] = newValue;
52+
}
53+
54+
void Container::PushBack(int element)
55+
{
56+
if (m_Capacity == m_Size)
57+
{
58+
m_Capacity *= 2;
59+
int* temp = new int[m_Capacity];
60+
for (int idx{0}; idx < m_Size; ++idx)
61+
{
62+
temp[idx] = m_pDynArray[idx];
63+
}
64+
delete m_pDynArray;
65+
m_pDynArray = temp;
66+
}
67+
m_pDynArray[m_Size++] = element;
68+
69+
}
70+
71+
void Container::Reserve(int newCapacity)
72+
{
73+
int* temp = new int[newCapacity];
74+
for (int idx{0}; idx < m_Size; ++idx)
75+
{
76+
temp[idx] = m_pDynArray[idx];
77+
}
78+
delete m_pDynArray;
79+
m_pDynArray = temp;
80+
}

Classes2Basics/Container.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Knapecz, Adam - 1DAE11
2+
#pragma once
3+
4+
class Container
5+
{
6+
public:
7+
explicit Container(int capacity = 10);
8+
~Container();
9+
int Size() const;
10+
int Capacity() const;
11+
int Get(int index) const;
12+
void Set(int index, int newValue);
13+
void PushBack(int element);
14+
void Reserve(int newCapacity);
15+
private:
16+
int m_Size;
17+
int m_Capacity;
18+
int* m_pDynArray;
19+
};
20+

Classes2Basics/Square.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Knapecz, Adam - 1DAE11
2+
#include "Square.h"
3+
#include <iostream>
4+
#include <iomanip>
5+
6+
Square::Square(float size)
7+
: m_Left{ }
8+
, m_Bottom{ }
9+
, m_Size{ size }
10+
{
11+
std::cout << "Constructor: Square( float size ), creates resources" << std::endl;
12+
}
13+
14+
Square::Square(float left, float bottom)
15+
: m_Left{left}
16+
, m_Bottom{bottom}
17+
, m_Size{10.0f}
18+
{
19+
std::cout << "Constructor: Square( float left, float bottom ), creates resources" << std::endl;
20+
}
21+
22+
Square::Square(float size, float left, float bottom)
23+
: m_Left{ left }
24+
, m_Bottom{ bottom }
25+
, m_Size{ size }
26+
{
27+
std::cout << "Constructor: Square( float left, float bottom, float size ), creates resources" << std::endl;
28+
}
29+
30+
Square::~Square()
31+
{
32+
std::cout << "Square destructor: release the resources\n";
33+
}
34+
35+
36+
void Square::Print() const
37+
{
38+
std::cout << std::fixed;
39+
std::cout << "Left: ";
40+
std::cout << std::setprecision(2) << m_Left;
41+
42+
std::cout << ", bottom: ";
43+
std::cout << std::setprecision(2) << m_Bottom << std::endl;
44+
45+
std::cout << "Size: ";
46+
std::cout << std::setprecision(2) << m_Size << std::endl;
47+
48+
std::cout << "Perimeter: ";
49+
std::cout << std::setprecision(2) << GetPerimeter() << std::endl;;
50+
std::cout << "Area: ";
51+
std::cout << std::setprecision(2) << GetArea() << std::endl;;
52+
}
53+
54+
void Square::Translate(float deltaLeft, float deltaBottom)
55+
{
56+
m_Left += deltaLeft;
57+
m_Bottom += deltaBottom;
58+
}
59+
void Square::SetSize(float newSize)
60+
{
61+
m_Size = newSize;
62+
}
63+
64+
float Square::GetArea() const
65+
{
66+
return m_Size * m_Size;
67+
}
68+
69+
float Square::GetPerimeter() const
70+
{
71+
return 4 * m_Size;
72+
}

Classes2Basics/Square.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Knapecz, Adam - 1DAE11
2+
#pragma once
3+
class Square
4+
{
5+
public:
6+
Square(float size);
7+
Square(float left, float bottom);
8+
Square(float size, float left, float bottom);
9+
~Square();
10+
11+
// Member functions
12+
void Print() const;
13+
void Translate(float deltaLeft, float deltaBottom);
14+
void SetSize(float newSize);
15+
16+
private:
17+
// Data members
18+
float m_Left;
19+
float m_Bottom;
20+
float m_Size;
21+
22+
// Helper functions
23+
float GetArea() const;
24+
float GetPerimeter() const;
25+
26+
};

0 commit comments

Comments
 (0)