TP8: Parcours Vita

This commit is contained in:
2024-12-01 20:38:22 +01:00
parent 3aede38c75
commit 3f473e5f99
6 changed files with 389 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ParcoursVita", "ParcoursVita.vcxproj", "{E000E911-87DE-426A-A425-A796F5A8CC97}"
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
{E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x64.ActiveCfg = Debug|x64
{E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x64.Build.0 = Debug|x64
{E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x86.ActiveCfg = Debug|Win32
{E000E911-87DE-426A-A425-A796F5A8CC97}.Debug|x86.Build.0 = Debug|Win32
{E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x64.ActiveCfg = Release|x64
{E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x64.Build.0 = Release|x64
{E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x86.ActiveCfg = Release|Win32
{E000E911-87DE-426A-A425-A796F5A8CC97}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6848ED2D-79A2-415E-B230-BEFE036DDB2C}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{e000e911-87de-426a-a425-a796f5a8cc97}</ProjectGuid>
<RootNamespace>ParcoursVita</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>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</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" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Fichiers sources">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Fichiers d%27en-tête">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Fichiers de ressources">
<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>Fichiers sources</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

197
TP8/ParcoursVita/main.cpp Normal file
View File

@@ -0,0 +1,197 @@
#include <iostream>
#include <list>
#include <vector>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
class Participant {
string Nom;
int age;
public:
void Affichage();
void Saisie();
int getAge() { return age; }
string getNom() { return Nom; }
// Tri par l'age
bool operator<(Participant p) {
return Nom < p.Nom;
}
};
template <class C, class T>
void saisie(C& c) {
int n;
cout << "Nombre de participants à saisir : ";
cin >> n; cin.ignore();
while ((n--) > 0) {
T participant;
participant.Saisie();
c.insert(c.begin(), participant);
}
}
template <class C>
void affichage(C c) {
for (auto p : c) {
p.Affichage(); cout << endl;
}
cout << endl;
}
void affichage(set<string> c) {
for (auto a : c) {
cout << a << endl;
}
cout << endl;
}
template <class C>
void affichage(C c, const string name) {
cout << "Affichage de " << name << endl;
affichage(c);
}
// template <class A, class B>
bool tri_age(Participant a, Participant b) {
return a.getAge() < b.getAge();
}
// template <class A, class B>
bool tri_age_dec(Participant a, Participant b) {
return !tri_age(a, b);
}
template <class A, class B, class F>
void erase_max(A& a, B& b, F cmp, string txt) {
auto ita = max_element(a.begin(), a.end(), cmp);
auto itb = max_element(b.begin(), b.end(), cmp);
cout << txt;
if (ita != a.end()
&& (itb == b.end() || cmp(*itb, *ita))) {
ita->Affichage();
a.erase(ita);
}
else if (itb != b.end()
&& (ita == a.end() || cmp(*ita, *itb))) {
itb->Affichage();
b.erase(itb);
}
else {
cout << "NULL";
}
cout << endl;
}
template <class A, class B>
void erase_jeune_age(A& a, B& b) {
erase_max(a, b, tri_age, "Le plus vieux = ");
erase_max(a, b, tri_age_dec, "Le plus jeune = ");
}
template <class A, class B>
void add_allnom(A source, B& b) {
for(auto a : source) {
b.insert(a.getNom());
}
}
int menu() {
int c;
cout << "1. Saisie liste L1 + affichage" << endl
<< "2. Saisie vector V1 + affichage" << endl
<< "3. Efface le + jeune et le + agé (L1/V1)" << endl
<< "4. Tri croissant selon age (L1/V1) + affichage" << endl
<< "5. Conteneur de noms de L1/V1 trié+sans doublons" << endl
<< "6. Afficher L1 et V1" << endl;
cout << "Choix : " << endl;
cin >> c; cin.ignore();
return c;
}
int main() {
list<Participant> L1;
vector<Participant> V1;
set<string> noms;
setlocale(LC_ALL, "");
while (true) {
switch (menu()) {
case 1:
saisie<list<Participant>, Participant>(L1);
affichage(L1, "L1");
break;
case 2:
saisie<vector<Participant>, Participant>(V1);
affichage(V1, "V1");
break;
case 3:
erase_jeune_age(L1, V1);
affichage(L1, "L1");
affichage(V1, "V1");
break;
case 4:
L1.sort(tri_age);
sort(V1.begin(), V1.end(), tri_age);
affichage(L1, "L1");
affichage(V1, "V1");
break;
case 5:
add_allnom(L1, noms);
add_allnom(V1, noms);
affichage(noms, "Affichage du conteneur :");
break;
case 6:
affichage(L1, "L1");
affichage(V1, "V1");
break;
default:
return 0;
}
}
}
template <class T>
void affiche(T t, int w) {
cout << left << setw(w) << t << " ";
}
void Participant::Affichage() {
affiche(Nom, 10);
affiche(age, 4);
}
void Participant::Saisie() {
// Saisie de du nom : via getline();
cout << "Son nom ? : ";
getline(cin, Nom);
// Saisie de l'age
cout << "Son age ? : ";
cin >> age; cin.ignore();
}