chore: Add course material

This commit is contained in:
2026-10-05 11:27:21 +02:00
parent 971813c351
commit e8241fd1ff
660 changed files with 26658 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ex61", "Ex61.vcxproj", "{71B1E667-58E2-4C71-A6A3-73F9502928D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{71B1E667-58E2-4C71-A6A3-73F9502928D7}.Debug|Win32.ActiveCfg = Debug|Win32
{71B1E667-58E2-4C71-A6A3-73F9502928D7}.Debug|Win32.Build.0 = Debug|Win32
{71B1E667-58E2-4C71-A6A3-73F9502928D7}.Release|Win32.ActiveCfg = Release|Win32
{71B1E667-58E2-4C71-A6A3-73F9502928D7}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
BIN
View File
Binary file not shown.
+121
View File
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding = "Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="Ex61"
ProjectGUID="{71B1E667-58E2-4C71-A6A3-73F9502928D7}"
Keyword="ManagedCProj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2"
ManagedExtensions="TRUE">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG"
MinimalRebuild="FALSE"
BasicRuntimeChecks="0"
RuntimeLibrary="1"
WarningLevel="3"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/Ex61.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2"
ManagedExtensions="TRUE">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG"
MinimalRebuild="FALSE"
WarningLevel="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/Ex61.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="Person.cpp">
</File>
<File
RelativePath="PersonException.cpp">
</File>
<File
RelativePath="YoungPerson.cpp">
</File>
<File
RelativePath="main.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="Person.h">
</File>
<File
RelativePath="PersonException.h">
</File>
<File
RelativePath="YoungPerson.h">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
+92
View File
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.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>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{71B1E667-58E2-4C71-A6A3-73F9502928D7}</ProjectGuid>
<Keyword>ManagedCProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>OldSyntax</CLRSupport>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>false</CLRSupport>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)Ex61.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<OutputFile>$(OutDir)Ex61.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Person.cpp" />
<ClCompile Include="PersonException.cpp" />
<ClCompile Include="YoungPerson.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Person.h" />
<ClInclude Include="PersonException.h" />
<ClInclude Include="YoungPerson.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+38
View File
@@ -0,0 +1,38 @@
<?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>{216ad10e-da13-4e74-bd7b-3d1fd4babd53}</UniqueIdentifier>
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{57ab839f-9334-4b02-aa8e-af153d217a12}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Person.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PersonException.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="YoungPerson.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Person.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PersonException.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="YoungPerson.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+3
View File
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
+37
View File
@@ -0,0 +1,37 @@
#include "Person.h"
#include "PersonException.h"
#include "YoungPerson.h"
#include <iostream>
using std::cout;
Person::Person(std::string name, int age) : name(name), age(age) {
if (age < 0) {
throw PersonException("negative age");
}
cout << "Person ctor\n";
Count++;
}
Person::Person(const Person &) {
cout << "Copy ctor\n";
Count++;
}
Person::~Person() {
cout << "Dtor\n";
Count--;
}
void Person::setSalary(int sal) {
if (sal < 0) {
throw PersonException("negative salary");
}
salary = sal;
}
int Person::GetCount() { return Count; }
int Person::Count = 0;
+28
View File
@@ -0,0 +1,28 @@
#ifndef Person_h
#define Person_h
#include <string>
class Person {
public:
virtual ~Person();
static int GetCount();
Person(std::string name, int age);
void setSalary(int sal);
private:
Person(const Person &);
std::string name;
int age;
int salary;
static int Count;
};
#endif
+5
View File
@@ -0,0 +1,5 @@
#include "PersonException.h"
PersonException::PersonException(std::string m) : msg(m) {}
const char *PersonException::what() const throw() { return msg.c_str(); }
+16
View File
@@ -0,0 +1,16 @@
#ifndef Person_Exception_h
#define Person_Exception_h
#include <exception>
#include <string>
class PersonException : public std::exception {
public:
PersonException(std::string m);
const char *what() const throw();
private:
std::string msg;
};
#endif
+5
View File
@@ -0,0 +1,5 @@
#include "YoungPerson.h"
#include <iostream>
YoungPerson::YoungPerson(std::string name, int age) : Person(name, age) { std::cout << "YoungPerson ctor\n"; }
+13
View File
@@ -0,0 +1,13 @@
#ifndef YoungPerson_h
#define YoungPerson_h
#include "Person.h"
class YoungPerson : public Person {
public:
YoungPerson(std::string name, int age);
};
#endif
+75
View File
@@ -0,0 +1,75 @@
#include <exception>
#include <string>
#include <vector>
#include "Person.h"
#include "PersonException.h"
#include <iostream>
using std::cin;
using std::cout;
using std::string;
using std::exception;
int main() {
std::vector<Person *> people;
string namePrompt = "Enter name: ";
string name;
string agePrompt = "Enter age: ";
int age;
string salaryPrompt = "Enter salary: ";
int salary;
cout << namePrompt;
cin >> name;
while (name != "q") {
try {
cout << agePrompt;
cin >> age;
if (!cin) {
cin.clear();
string dummy;
cin >> dummy;
throw PersonException("invalid age");
}
Person *personPtr = new Person(name, age);
cout << salaryPrompt;
cin >> salary;
if (!cin) {
cin.clear();
string dummy;
cin >> dummy;
throw PersonException("invalid salary");
}
personPtr->setSalary(salary);
people.push_back(personPtr);
}
catch (exception &e) {
cout << "PersonException thrown: " << e.what() << '\n';
}
cout << "There are " << Person::GetCount() << " Person(s), " << people.size() << " in vector\n";
cout << namePrompt;
cin >> name;
}
// delete all the person(s) in the vector
for (std::vector<Person *>::iterator iter = people.begin(); iter != people.end(); ++iter) {
delete *iter;
}
cout << "There are " << Person::GetCount() << " Person(s) left dangling\n";
return 0;
}