TP8: EtudProf

This commit is contained in:
2024-11-27 18:33:48 +01:00
parent a7adcbfd9f
commit bc02b5e336
8 changed files with 433 additions and 0 deletions

Binary file not shown.

31
TP8/EtudProf/EtudProf.sln Normal file
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}") = "EtudProf", "EtudProf.vcxproj", "{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}"
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
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x64.ActiveCfg = Debug|x64
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x64.Build.0 = Debug|x64
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x86.ActiveCfg = Debug|Win32
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Debug|x86.Build.0 = Debug|Win32
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x64.ActiveCfg = Release|x64
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x64.Build.0 = Release|x64
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x86.ActiveCfg = Release|Win32
{D6DEC2BC-4A3C-4AA0-BD88-5FE3113CF810}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2112B69A-D512-4F99-A3CE-CBDB944F07B8}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,139 @@
<?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>{d6dec2bc-4a3c-4aa0-bd88-5fe3113cf810}</ProjectGuid>
<RootNamespace>EtudProf</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>
<ItemGroup>
<Text Include="Etud_M.txt" />
<Text Include="Prof_M.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -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="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>
<ItemGroup>
<Text Include="Prof_M.txt">
<Filter>Fichiers de ressources</Filter>
</Text>
<Text Include="Etud_M.txt">
<Filter>Fichiers de ressources</Filter>
</Text>
</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>

4
TP8/EtudProf/Etud_M.txt Normal file
View File

@@ -0,0 +1,4 @@
15103A;Aladdin;3;5;15;13;
15095X;Jasmine;5;15;11;19;7;18;
14109C;Asterix;4;12;10;14;8;
19150B;Obelix;2;0;20;

5
TP8/EtudProf/Prof_M.txt Normal file
View File

@@ -0,0 +1,5 @@
Tournesol;3;Math;Philo;Chimie;
Einstein;2;Physique;Méca;
BruceLee;4;kungfu;Karaté;TaiChiChuan;Gung-Li;
StephenWilliamHawking;2;Cosmologie;Physique;
IsaacNewton;4;Math;Physique;Philo;Astronomie;

220
TP8/EtudProf/main.cpp Normal file
View File

@@ -0,0 +1,220 @@
#include <iostream>
#include <string>
#include <map>
#include <fstream>
#include <iomanip>
#include <set>
using namespace std;
const int ENTREE_MAX = 10;
template <class T>
class Personne {
string nom;
int nbr_entrees;
T entrees[ENTREE_MAX];
public:
void Lire(ifstream& f);
void afficher();
T lire_entree(ifstream& f);
string get_key() { return nom; }
string get_nom() { return nom; }
};
class Etud : public Personne<float> {
string Id;
public:
void Lire(ifstream& f);
void afficher();
string get_key() { return Id; }
};
class Prof : public Personne<string> {};
template <class M, class T>
void lecture(M& mp, const string fname) {
ifstream f(fname);
if (!f.is_open()) {
cout << "Erreur lors de la lecture du fichier"<<endl;
exit(1);
}
while (!f.eof()) {
T obj;
obj.Lire(f);
f.ignore();
mp[obj.get_key()] = obj;
}
}
template <class C>
void afficher(const C& mp) {
for (auto pair : mp) {
pair.second.afficher();
cout << endl;
}
cout << endl;
}
template <class C>
void afficher(const set<C>& s) {
for (auto e : s) {
cout << e;
cout << endl;
}
cout << endl;
}
int menu() {
int c;
cout << "1 : Lire Etud_M.txt et stocker les données dans une Map1 dEtudiants + affichage" << endl
<< "2 : Lire Prof_M.txt et stocker les données dans une Map2 de PROFs + affichage" << endl
<< "3 : Chercher selon le nom dans Map1 et dans Map2 si élément existe et lEffacer + affichage" << endl
<< "4 : Mettre les noms des étudiants et des PROFs dans un CnTri + affichage" << endl
<< "5 : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << endl;
cout << "Choix : ";
cin >> c; cin.ignore();
return c;
}
bool is_equal_ignorecase(string s1, string s2) {
if (s1.size() != s2.size()) return false;
for (int i = 0; i < s1.size(); i++) {
if (tolower(s1[i]) != tolower(s2[i]))
return false;
}
return true;
}
template <class T>
auto find(T& t, const string nom) {
auto it = t.begin();
for (; it != t.end(); it++) {
if (is_equal_ignorecase(it->second.get_nom(), nom))
break;
}
return it;
}
void effacer_nom(map<string, Etud>& etuds, map<string, Prof>& profs) {
string nom;
cout << "Nom : ";
getline(cin, nom);
auto itE = find(etuds, nom);
auto itP = find(profs, nom);
if (itE == etuds.end() && itP == profs.end()) {
cout << "Ce nom n'existe pas" << endl;
return;
}
if (itE != etuds.end()) {
etuds.erase(itE);
}
if (itP != profs.end()) {
profs.erase(itP);
}
afficher(etuds);
afficher(profs);
}
template <class T>
void ajout_nom(set<string>& noms, T& map) {
for (auto& p : map) {
noms.insert(p.second.get_nom());
}
}
int main() {
map<string, Etud> etuds;
map<string, Prof> profs;
set<string> noms;
while (true) {
switch (menu()) {
case 1:
lecture<map<string, Etud>, Etud>(etuds, "Etud_M.txt");
afficher(etuds);
break;
case 2:
lecture<map<string, Prof>, Prof>(profs, "Prof_M.txt");
afficher(profs);
break;
case 3:
effacer_nom(etuds, profs);
break;
case 4:
noms.clear();
ajout_nom(noms, etuds);
ajout_nom(noms, profs);
afficher(noms);
break;
default:
return 0;
}
}
}
template <class T>
void Personne<T>::Lire(ifstream& f) {
getline(f, nom, ';');
f >> nbr_entrees; f.ignore();
for (int i = 0; i < nbr_entrees; i++) {
entrees[i] = lire_entree(f);
}
}
string Personne<string>::lire_entree(ifstream& f) {
string entree;
getline(f, entree, ';');
return entree;
}
float Personne<float>::lire_entree(ifstream& f) {
float entree;
f >> entree; f.ignore();
return entree;
}
void Etud::Lire(ifstream& f) {
getline(f, Id, ';');
Personne::Lire(f);
}
template <class T>
void Personne<T>::afficher() {
cout << left << setw(22) << nom << " " << nbr_entrees << " ";
for (int i = 0; i < nbr_entrees; i++) {
cout << left << setw(8) << entrees[i] << " ";
}
}
void Etud::afficher() {
cout << setw(6) << Id << " ";
Personne<float>::afficher();
}