School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Seminar3_Week2_stub", "Seminar3_Week2_stub\Seminar3_Week2_stub.vcxproj", "{2A052F8F-28D2-4143-B482-193BF264A62E}"
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
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x64.ActiveCfg = Debug|x64
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x64.Build.0 = Debug|x64
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x86.ActiveCfg = Debug|Win32
{2A052F8F-28D2-4143-B482-193BF264A62E}.Debug|x86.Build.0 = Debug|Win32
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x64.ActiveCfg = Release|x64
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x64.Build.0 = Release|x64
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x86.ActiveCfg = Release|Win32
{2A052F8F-28D2-4143-B482-193BF264A62E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {07D2633E-81F6-4DE8-AE18-5DF14D6DD1F3}
EndGlobalSection
EndGlobal
@@ -0,0 +1,178 @@
#pragma once
#include <iterator>
template <typename T>
class DynamicVector
{
private:
T* elems;
int size;
int capacity;
public:
// default constructor for a DynamicVector
DynamicVector(int capacity = 10);
// copy constructor for a DynamicVector
DynamicVector(const DynamicVector& v);
~DynamicVector();
// assignment operator for a DynamicVector
DynamicVector& operator=(const DynamicVector& v);
/*
Overloading the subscript operator
Input: pos - a valid position within the vector.
Output: a reference to the element o position pos.
*/
T& operator[](int pos);
// Adds an element to the current DynamicVector.
void add(const T& e);
int getSize() const;
void setSize(int s) { size = s; }
private:
// Resizes the current DynamicVector, multiplying its capacity by a given factor (real number).
void resize(double factor = 2);
public:
class iterator
{
private:
T* ptr;
public:
// constructor
iterator(T* p);
// prefix operator
iterator operator++();
// postfix operator
iterator operator++(int dummy);
T& operator*();
T* operator->();
bool operator!=(const iterator& it);
};
iterator begin()
{
return this->elems;
}
iterator end()
{
return this->elems + this->size;
}
};
template <typename T>
DynamicVector<T>::DynamicVector(int capacity)
{
this->size = 0;
this->capacity = capacity;
this->elems = new T[capacity];
}
template <typename T>
DynamicVector<T>::DynamicVector(const DynamicVector<T>& v)
{
this->size = v.size;
this->capacity = v.capacity;
this->elems = new T[this->capacity];
for (int i = 0; i < this->size; i++)
this->elems[i] = v.elems[i];
}
template <typename T>
DynamicVector<T>::~DynamicVector()
{
delete[] this->elems;
}
template <typename T>
DynamicVector<T>& DynamicVector<T>::operator=(const DynamicVector<T>& v)
{
if (this == &v)
return *this;
this->size = v.size;
this->capacity = v.capacity;
delete[] this->elems;
this->elems = new T[this->capacity];
for (int i = 0; i < this->size; i++)
this->elems[i] = v.elems[i];
return *this;
}
template <typename T>
T& DynamicVector<T>::operator[](int pos)
{
return this->elems[pos];
}
template <typename T>
void DynamicVector<T>::add(const T& e)
{
if (this->size == this->capacity)
this->resize();
this->elems[this->size] = e;
this->size++;
}
template <typename T>
void DynamicVector<T>::resize(double factor)
{
this->capacity *= static_cast<int>(factor);
T* els = new T[this->capacity];
for (int i = 0; i < this->size; i++)
els[i] = this->elems[i];
delete[] this->elems;
this->elems = els;
}
template <typename T>
int DynamicVector<T>::getSize() const
{
return this->size;
}
template <typename T>
DynamicVector<T>::iterator::iterator(T* p){
ptr = p;
}
template <typename T>
typename DynamicVector<T>::iterator DynamicVector<T>::iterator::operator++(){
ptr++;
return *this;
}
template <typename T>
typename DynamicVector<T>::iterator DynamicVector<T>::iterator::operator++(int dummy){
iterator it = *this;
ptr++;
return it;
}
template <typename T>
T& DynamicVector<T>::iterator::operator*(){
return *ptr;
}
template <typename T>
T* DynamicVector<T>::iterator::operator->(){
return ptr;
}
template <typename T>
bool DynamicVector<T>::iterator::operator!=(const iterator& it){
return ptr != it.ptr;
}
@@ -0,0 +1,162 @@
#pragma once
template <typename T>
class Node
{
public:
T value;
Node *nextNode;
Node()
{
this->value = 0;
this->nextNode = nullptr;
}
~Node()
{
delete nextNode;
}
Node(const Node &n)
{
value = n.value;
nextNode = n.nextNode;
}
Node &operator=(const Node &n)
{
this->value = n.value;
this->nextNode = n.nextNode;
return *this;
}
Node &operator=(const T &value)
{
this->value = value;
return *this;
}
};
template <typename T>
class LinkedList
{
private:
Node<T> *beginingNode;
int size;
public:
LinkedList(Node<T> *f = nullptr);
LinkedList(const LinkedList &l);
~LinkedList();
// assignment operator for a LinkedList
LinkedList &operator=(const LinkedList &l);
T &operator[](int pos);
// Adds an element to the current LinkedList.
void add(const T &e);
int getSize() const;
};
template <typename T>
LinkedList<T>::LinkedList(Node<T> *f)
{
this->beginingNode = f;
this->size = 0;
if (f != nullptr)
{
this->size++;
while (f->nextNode != nullptr)
this->size++;
}
}
template <typename T>
LinkedList<T>::LinkedList(const LinkedList &l)
{
Node<T> *currentNode = new Node<T>();
if (l.beginingNode == nullptr)
{
beginingNode = nullptr;
size = 0;
return;
}
*currentNode = *l.beginingNode;
beginingNode = currentNode;
size = 1;
Node<T> *nextNode = l.beginingNode->nextNode;
while (nextNode != nullptr)
{
*(currentNode->nextNode) = *nextNode;
currentNode = currentNode->nextNode;
nextNode = nextNode->nextNode;
size++;
}
}
template <typename T>
LinkedList<T>::~LinkedList()
{
delete this->beginingNode;
}
template <typename T>
LinkedList<T> &LinkedList<T>::operator=(const LinkedList &l)
{
Node<T> *currentNode = new Node<T>();
if (l.beginingNode == nullptr)
{
this->beginingNode = nullptr;
this->size = 0;
return *this;
}
*currentNode = *l.beginingNode;
this->beginingNode = currentNode;
this->size = 1;
Node<T> *nextNode = l.beginingNode->nextNode;
while (nextNode != nullptr)
{
*(currentNode->nextNode) = *nextNode;
currentNode = currentNode->nextNode;
nextNode = nextNode->nextNode;
this->size++;
}
return *this;
}
template <typename T>
T &LinkedList<T>::operator[](int pos)
{
if (pos >= this->size || pos < 0)
throw std::invalid_argument("Invalid position");
Node<T> *currentNode = this->beginingNode;
for (int i = 0; i < pos; i++)
{
currentNode = currentNode->nextNode;
}
return currentNode->value;
}
template <typename T>
void LinkedList<T>::add(const T &e)
{
if (this->beginingNode == nullptr)
{
this->beginingNode = new Node<T>();
this->beginingNode->value = e;
this->size = 1;
return;
}
Node<T> *currentNode = this->beginingNode;
for (int i = 1; i < this->size; i++)
{
currentNode = currentNode->nextNode;
}
currentNode->nextNode = new Node<T>();
currentNode->nextNode->value = e;
this->size++;
}
template <typename T>
int LinkedList<T>::getSize() const
{
return this->size;
}
@@ -0,0 +1,131 @@
<?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>{2A052F8F-28D2-4143-B482-193BF264A62E}</ProjectGuid>
<RootNamespace>Seminar3Week2stub</RootNamespace>
<WindowsTargetPlatformVersion>10.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>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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 />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</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>
</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>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="Song.cpp" />
<ClCompile Include="Tests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DynamicVector.h" />
<ClInclude Include="LinkedList.h" />
<ClInclude Include="Song.h" />
<ClInclude Include="Tests.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,42 @@
<?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="Song.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Tests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Song.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Tests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DynamicVector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LinkedList.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
@@ -0,0 +1,23 @@
#include "Song.h"
#include <Windows.h>
#include <shellapi.h>
Song::Song(): title(""), artist(""), duration(Duration()), source("") {}
Song::Song(const std::string& artist, const std::string& title, const Duration& duration, const std::string& source)
{
this->artist = artist;
this->title = title;
this->duration = duration;
this->source = source;
}
bool Song::operator==(const Song & s)
{
return (this->artist == s.artist && this->title == s.title);
}
void Song::play()
{
ShellExecuteA(NULL, NULL, "chrome.exe", this->getSource().c_str(), NULL, SW_SHOWMAXIMIZED);
}
@@ -0,0 +1,42 @@
#pragma once
#include <iostream>
class Duration
{
private:
double minutes;
double seconds;
public:
Duration() : minutes(0), seconds(0) {}
Duration(double min, double sec) : minutes(min), seconds(sec) {}
double getMinutes() const { return minutes; }
double getSeconds() const { return seconds; }
};
class Song
{
private:
std::string title;
std::string artist;
Duration duration;
std::string source; // youtube Link
public:
// default constructor for a song
Song();
// constructor with parameters
Song(const std::string& artist, const std::string& title, const Duration& duration, const std::string& source);
std::string getTitle() const { return title; }
std::string getArtist() const { return artist; }
std::string getSource() const { return source; }
Duration getDuration() const { return duration; }
bool operator==(const Song& s);
// Plays the current song: the page corresponding to the source link is opened in a browser.
void play();
};
@@ -0,0 +1,51 @@
#include "Tests.h"
#include "DynamicVector.h"
#include "LinkedList.h"
#include <assert.h>
void Tests::testDynamicVector()
{
DynamicVector<int> v1{};
v1.add(10);
v1.add(20);
assert(v1.getSize() == 2);
assert(v1[1] == 20);
v1[1] = 40;
assert(v1[1] == 40);
v1.add(30);
assert(v1.getSize() == 3);
DynamicVector<int> v2{ v1 };
assert(v2.getSize() == 3);
DynamicVector<int> v3;
v3 = v1;
assert(v3[0] == 10);
// test iterator
DynamicVector<int>::iterator it = v1.begin();
assert(*it == 10);
assert(it != v1.end());
++it;
assert(*it == 40);
}
void Tests::testLinkedList()
{
LinkedList<int> l1{};
l1.add(10);
l1.add(20);
assert(l1.getSize() == 2);
assert(l1[1] == 20);
l1[1] = 40;
assert(l1[1] == 40);
l1.add(30);
assert(l1.getSize() == 3);
LinkedList<int> l2{ l1 };
assert(l2.getSize() == 3);
LinkedList<int> l3;
l3 = l1;
assert(l3[0] == 10);
}
@@ -0,0 +1,8 @@
#pragma once
class Tests
{
public:
static void testDynamicVector();
static void testLinkedList();
};
@@ -0,0 +1,15 @@
#include "DynamicVector.h"
#include "LinkedList.h"
#include "LinkedList.h"
#include "Song.h"
#include "Tests.h"
#include <assert.h>
int main()
{
Tests::testDynamicVector();
Tests::testLinkedList();
return 0;
}