TP6
This commit is contained in:
31
TP6/TP6.sln
Normal file
31
TP6/TP6.sln
Normal 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}") = "TP6", "TP6.vcxproj", "{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}"
|
||||
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
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Debug|x64.Build.0 = Debug|x64
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Debug|x86.Build.0 = Debug|Win32
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Release|x64.ActiveCfg = Release|x64
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Release|x64.Build.0 = Release|x64
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Release|x86.ActiveCfg = Release|Win32
|
||||
{C1CE1082-4EB0-43D9-8755-76FB40FF79CE}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1F44335C-36DF-43F4-8EA1-044BA57E5AB7}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
135
TP6/TP6.vcxproj
Normal file
135
TP6/TP6.vcxproj
Normal 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>{c1ce1082-4eb0-43d9-8755-76fb40ff79ce}</ProjectGuid>
|
||||
<RootNamespace>TP6</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>
|
||||
22
TP6/TP6.vcxproj.filters
Normal file
22
TP6/TP6.vcxproj.filters
Normal 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>
|
||||
4
TP6/TP6.vcxproj.user
Normal file
4
TP6/TP6.vcxproj.user
Normal 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>
|
||||
279
TP6/main.cpp
Normal file
279
TP6/main.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Personne {
|
||||
int Id;
|
||||
string Nom;
|
||||
|
||||
public:
|
||||
using SAISIE = int;
|
||||
|
||||
Personne() {
|
||||
static int i = 0;
|
||||
|
||||
Id = ++i;
|
||||
}
|
||||
|
||||
Personne(int Id) : Id(Id) {};
|
||||
|
||||
void saisie() { getline(cin, Nom, ' '); }
|
||||
void afficher() { cout << left << setw(3) << Id << left << setw(8) << Nom; }
|
||||
|
||||
// paramètre saisie n'est pas utilisé par défaut
|
||||
static SAISIE parametre_saisie() { return 0; }
|
||||
static string nomclasse() { return "personne"; }
|
||||
|
||||
bool operator==(string nom) { return Nom == nom; }
|
||||
|
||||
bool operator<(Personne& b) const noexcept { return Nom < b.Nom; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Prof : public Personne {
|
||||
string service;
|
||||
|
||||
|
||||
public:
|
||||
static int i;
|
||||
using SAISIE = char;
|
||||
|
||||
Prof() : Personne(++i) {};
|
||||
|
||||
void saisie(SAISIE n) { Personne::saisie(); getline(cin, service, n); }
|
||||
void afficher() { Personne::afficher(); cout << left << setw(8) << service; }
|
||||
|
||||
static string nomclasse() { return "prof"; }
|
||||
static SAISIE parametre_saisie() {return '\n';}
|
||||
};
|
||||
|
||||
class Direction : public Prof {
|
||||
string Titre;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void saisie() { Prof::saisie(' '); getline(cin, Titre); }
|
||||
void afficher() { Prof::afficher(); cout << left << setw(8) << Titre; }
|
||||
|
||||
static string nomclasse() { return "direction"; };
|
||||
|
||||
template <class C>
|
||||
void moyennes(C& etudiants) {
|
||||
cout << "==Moyennes==" << endl;
|
||||
for (auto etud : etudiants) {
|
||||
cout << endl;
|
||||
etud.afficher();
|
||||
|
||||
etud.Moy = 0;
|
||||
for (int i = 0; i < etud.N_Note; i++) {
|
||||
etud.Moy += etud.Note[i];
|
||||
}
|
||||
etud.Moy = (float)etud.Moy / (float)etud.N_Note;
|
||||
cout << "M: " << setprecision(4) << etud.Moy;
|
||||
}
|
||||
cout << endl;
|
||||
};
|
||||
};
|
||||
|
||||
class Etudiant : public Personne {
|
||||
string An_Scol;
|
||||
int Note[3];
|
||||
int N_Note;
|
||||
float Moy;
|
||||
|
||||
friend class Direction;
|
||||
friend bool tri_etud(const Etudiant& a, const Etudiant& b);
|
||||
|
||||
public:
|
||||
static int i;
|
||||
|
||||
using SAISIE = int;
|
||||
|
||||
Etudiant() : Personne(++i) {};
|
||||
|
||||
void saisie(int n) {
|
||||
Personne::saisie();
|
||||
|
||||
getline(cin, An_Scol, ' ');
|
||||
|
||||
string tmp;
|
||||
N_Note = n;
|
||||
|
||||
for (int i = 0; i < N_Note-1; i++) {
|
||||
getline(cin, tmp, ' ');
|
||||
Note[i] = stoi(tmp);
|
||||
}
|
||||
cin >> Note[N_Note-1];
|
||||
cin.ignore();
|
||||
}
|
||||
|
||||
void afficher() { Personne::afficher(); cout << left << setw(6) << An_Scol; for (int i = 0; i < N_Note; i++) cout << left << setw(4) << Note[i]; }
|
||||
|
||||
// Retourne le nom de la classe pour la saisie
|
||||
static string nomclasse() { return "étudiant"; }
|
||||
|
||||
static SAISIE parametre_saisie() {
|
||||
int mat = 0;
|
||||
do {
|
||||
cout << "Nombre de matière (<= 3) : ";
|
||||
cin >> mat; cin.ignore();
|
||||
} while (mat <= 0 || mat > 3);
|
||||
|
||||
return mat;
|
||||
}
|
||||
};
|
||||
|
||||
int Prof::i = 0;
|
||||
int Etudiant::i = 0;
|
||||
|
||||
|
||||
template <class C>
|
||||
void saisie(C& conteneur) {
|
||||
// récupération du type stocké dans le conteneur, évite de devoir
|
||||
// passer un 2e variable en paramètre
|
||||
using A = typename C::value_type;
|
||||
|
||||
// Le type "SAISIE" stocké sur la classe,
|
||||
// permet de saisir virtuellement n'importe en quoi avant la saisie de chaque élémement
|
||||
// 1x avant les itérations
|
||||
using SAISIE = typename A::SAISIE;
|
||||
|
||||
int n;
|
||||
|
||||
cout << "Nombre de " << A::nomclasse() << " : ";
|
||||
cin >> n; cin.ignore();
|
||||
|
||||
SAISIE p = A::parametre_saisie();
|
||||
|
||||
while (n-- > 0) {
|
||||
// A a;
|
||||
// a.saisie();
|
||||
// conteneur.insert(conteneur.end(), a);
|
||||
|
||||
conteneur.emplace(conteneur.end())->saisie(p);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void afficher(C& conteneur) {
|
||||
using V = typename C::value_type;
|
||||
|
||||
cout << "Affichage de " << V::nomclasse() << endl;
|
||||
|
||||
for (auto &v : conteneur) {
|
||||
cout << endl; v.afficher();
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
bool recherche(C& conteneur, string recherche) {
|
||||
using T = typename C::value_type;
|
||||
|
||||
auto et = find(conteneur.begin(), conteneur.end(), recherche);
|
||||
|
||||
if (et != conteneur.end()) {
|
||||
cout << recherche << " existe. Il s'agit d'un " << T::nomclasse();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// a < b
|
||||
bool tri_etud(const Etudiant& a, const Etudiant& b) {
|
||||
if (a.An_Scol.length() != 3 || b.An_Scol.length() != 3) {
|
||||
return a.Moy < b.Moy;
|
||||
}
|
||||
|
||||
if (a.An_Scol[0] != b.An_Scol[0]) {
|
||||
return a.An_Scol[0] < b.An_Scol[0];
|
||||
}
|
||||
else if (a.An_Scol[2] != b.An_Scol[2]) {
|
||||
return a.An_Scol[2] < b.An_Scol[2];
|
||||
}
|
||||
else {
|
||||
return a.Moy < b.Moy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int menu() {
|
||||
int c;
|
||||
cout << endl;
|
||||
cout<< " 1. Saisir N Etudiants et afficher" << endl
|
||||
<< " 2. Saisir M Profs et affichage" << endl
|
||||
<< " 3. Doyen membre de Direction Calcule la moyenne de chaque étudiant et affichage" << endl
|
||||
<< " 4. Chercher selon le NOM si un Etud ou Prof existe et affichage" << endl
|
||||
<< " 5. Trier selon le Nom(Etud ou Prof) par ordre croissant et affichage" << endl
|
||||
<< " 6. Afficher la liste des étudiants par année scolaire et par ordre décroissant de leur moyenne" << endl
|
||||
<< " 7. Quitter" << endl;
|
||||
cout << "Choix :";
|
||||
cin >> c; cin.ignore();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int c;
|
||||
string r;
|
||||
|
||||
list<Etudiant> etudiants;
|
||||
vector<Prof> profs;
|
||||
Direction doyen;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
|
||||
while ((c = menu()) != 7) {
|
||||
switch (c) {
|
||||
case 1:
|
||||
saisie(etudiants);
|
||||
afficher(etudiants);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
saisie(profs);
|
||||
afficher(profs);
|
||||
|
||||
break;
|
||||
case 3:
|
||||
doyen.saisie();
|
||||
cout << "Affichage doyen" << endl; doyen.afficher(); cout << endl;
|
||||
doyen.moyennes(etudiants);
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
cout << "Entrer un Nom : " << endl;
|
||||
getline(cin, r);
|
||||
|
||||
recherche(etudiants, r) || recherche(profs, r) || (cout << r << " n'existe pas !! ");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
etudiants.sort();
|
||||
afficher(etudiants);
|
||||
|
||||
sort(profs.begin(), profs.end());
|
||||
afficher(profs);
|
||||
|
||||
|
||||
break;
|
||||
case 6:
|
||||
etudiants.sort(tri_etud);
|
||||
afficher(etudiants);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
277
TP6/main.cpp.txt
Normal file
277
TP6/main.cpp.txt
Normal file
@@ -0,0 +1,277 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Personne {
|
||||
int Id;
|
||||
string Nom;
|
||||
|
||||
public:
|
||||
using SAISIE = int;
|
||||
|
||||
Personne() {
|
||||
static int i = 0;
|
||||
Id = ++i;
|
||||
}
|
||||
|
||||
Personne(int Id) : Id(Id) {};
|
||||
|
||||
void saisie() { getline(cin, Nom, ' '); }
|
||||
void afficher() { cout << left << setw(3) << Id << left << setw(8) << Nom; }
|
||||
|
||||
// paramètre saisie n'est pas utilisé par défaut
|
||||
static SAISIE parametre_saisie() { return 0; }
|
||||
static string nomclasse() { return "personne"; }
|
||||
|
||||
bool operator==(string nom) { return Nom == nom; }
|
||||
|
||||
bool operator<(Personne& b) const noexcept { return Nom < b.Nom; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Prof : public Personne {
|
||||
string service;
|
||||
|
||||
|
||||
public:
|
||||
static int i;
|
||||
using SAISIE = char;
|
||||
|
||||
//Prof() : Personne(++i) {};
|
||||
|
||||
void saisie(SAISIE n) { Personne::saisie(); getline(cin, service, n); }
|
||||
void afficher() { Personne::afficher(); cout << left << setw(8) << service; }
|
||||
|
||||
static string nomclasse() { return "prof"; }
|
||||
static SAISIE parametre_saisie() {return '\n';}
|
||||
};
|
||||
|
||||
class Direction : public Prof {
|
||||
string Titre;
|
||||
|
||||
public:
|
||||
void saisie() { Prof::saisie(' '); getline(cin, Titre); }
|
||||
void afficher() { Prof::afficher(); cout << left << setw(8) << Titre; }
|
||||
|
||||
static string nomclasse() { return "direction"; };
|
||||
|
||||
template <class C>
|
||||
void moyennes(C& etudiants) {
|
||||
cout << "==Moyennes==" << endl;
|
||||
for (auto etud : etudiants) {
|
||||
cout << endl;
|
||||
etud.afficher();
|
||||
|
||||
etud.Moy = 0;
|
||||
for (int i = 0; i < etud.N_Note; i++) {
|
||||
etud.Moy += etud.Note[i];
|
||||
}
|
||||
etud.Moy = (float)etud.Moy / (float)etud.N_Note;
|
||||
cout << "M: " << setprecision(4) << etud.Moy;
|
||||
}
|
||||
cout << endl;
|
||||
};
|
||||
};
|
||||
|
||||
class Etudiant : public Personne {
|
||||
string An_Scol;
|
||||
int Note[3];
|
||||
int N_Note;
|
||||
float Moy;
|
||||
|
||||
friend class Direction;
|
||||
friend bool tri_etud(const Etudiant& a, const Etudiant& b);
|
||||
|
||||
public:
|
||||
static int i;
|
||||
|
||||
using SAISIE = int;
|
||||
|
||||
|
||||
//Etudiant() : Personne(++i) {};
|
||||
|
||||
void saisie(int n) {
|
||||
Personne::saisie();
|
||||
|
||||
getline(cin, An_Scol, ' ');
|
||||
|
||||
string tmp;
|
||||
N_Note = n;
|
||||
|
||||
for (int i = 0; i < N_Note-1; i++) {
|
||||
getline(cin, tmp, ' ');
|
||||
Note[i] = stoi(tmp);
|
||||
}
|
||||
cin >> Note[N_Note-1];
|
||||
cin.ignore();
|
||||
}
|
||||
|
||||
void afficher() { Personne::afficher(); cout << left << setw(6) << An_Scol; for (int i = 0; i < N_Note; i++) cout << left << setw(4) << Note[i]; }
|
||||
|
||||
// Retourne le nom de la classe pour la saisie
|
||||
static string nomclasse() { return "étudiant"; }
|
||||
|
||||
static SAISIE parametre_saisie() {
|
||||
int mat = 0;
|
||||
do {
|
||||
cout << "Nombre de matière (<= 3) : ";
|
||||
cin >> mat; cin.ignore();
|
||||
} while (mat <= 0 || mat > 3);
|
||||
|
||||
return mat;
|
||||
}
|
||||
};
|
||||
|
||||
int Prof::i = 0;
|
||||
int Etudiant::i = 0;
|
||||
|
||||
|
||||
template <class C>
|
||||
void saisie(C& conteneur) {
|
||||
// récupération du type stocké dans le conteneur, évite de devoir
|
||||
// passer un 2e variable en paramètre
|
||||
using A = typename C::value_type;
|
||||
|
||||
// Le type "SAISIE" stocké sur la classe,
|
||||
// permet de saisir virtuellement n'importe en quoi avant la saisie de chaque élémement
|
||||
// 1x avant les itérations
|
||||
using SAISIE = typename A::SAISIE;
|
||||
|
||||
int n;
|
||||
|
||||
cout << "Nombre de " << A::nomclasse() << " : ";
|
||||
cin >> n; cin.ignore();
|
||||
|
||||
SAISIE p = A::parametre_saisie();
|
||||
|
||||
while (n-- > 0) {
|
||||
// A a;
|
||||
// a.saisie();
|
||||
// conteneur.insert(conteneur.end(), a);
|
||||
|
||||
conteneur.emplace(conteneur.end())->saisie(p);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void afficher(C& conteneur) {
|
||||
using V = typename C::value_type;
|
||||
|
||||
cout << "Affichage de " << V::nomclasse() << endl;
|
||||
|
||||
for (auto &v : conteneur) {
|
||||
cout << endl; v.afficher();
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
bool recherche(C& conteneur, string recherche) {
|
||||
using T = typename C::value_type;
|
||||
|
||||
auto et = find(conteneur.begin(), conteneur.end(), recherche);
|
||||
|
||||
if (et != conteneur.end()) {
|
||||
cout << recherche << " existe. Il s'agit d'un " << T::nomclasse();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// a < b
|
||||
bool tri_etud(const Etudiant& a, const Etudiant& b) {
|
||||
if (a.An_Scol.length() != 3 || b.An_Scol.length() != 3) {
|
||||
return a.Moy < b.Moy;
|
||||
}
|
||||
|
||||
if (a.An_Scol[0] != b.An_Scol[0]) {
|
||||
return a.An_Scol[0] < b.An_Scol[0];
|
||||
}
|
||||
else if (a.An_Scol[2] != b.An_Scol[2]) {
|
||||
return a.An_Scol[2] < b.An_Scol[2];
|
||||
}
|
||||
else {
|
||||
return a.Moy < b.Moy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int menu() {
|
||||
int c;
|
||||
cout << endl;
|
||||
cout<< " 1. Saisir N Etudiants et afficher" << endl
|
||||
<< " 2. Saisir M Profs et affichage" << endl
|
||||
<< " 3. Doyen membre de Direction Calcule la moyenne de chaque étudiant et affichage" << endl
|
||||
<< " 4. Chercher selon le NOM si un Etud ou Prof existe et affichage" << endl
|
||||
<< " 5. Trier selon le Nom(Etud ou Prof) par ordre croissant et affichage" << endl
|
||||
<< " 6. Afficher la liste des étudiants par année scolaire et par ordre décroissant de leur moyenne" << endl
|
||||
<< " 7. Quitter" << endl;
|
||||
cout << "Choix :";
|
||||
cin >> c; cin.ignore();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int c;
|
||||
string r;
|
||||
|
||||
list<Etudiant> etudiants;
|
||||
vector<Prof> profs;
|
||||
Direction doyen;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
|
||||
while ((c = menu()) != 7) {
|
||||
switch (c) {
|
||||
case 1:
|
||||
saisie(etudiants);
|
||||
afficher(etudiants);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
saisie(profs);
|
||||
afficher(profs);
|
||||
|
||||
break;
|
||||
case 3:
|
||||
doyen.saisie();
|
||||
cout << "Affichage doyen" << endl; doyen.afficher(); cout << endl;
|
||||
doyen.moyennes(etudiants);
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
cout << "Entrer un Nom : " << endl;
|
||||
getline(cin, r);
|
||||
|
||||
recherche(etudiants, r) || recherche(profs, r) || (cout << r << " n'existe pas !! ");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
etudiants.sort();
|
||||
afficher(etudiants);
|
||||
|
||||
sort(profs.begin(), profs.end());
|
||||
afficher(profs);
|
||||
|
||||
|
||||
break;
|
||||
case 6:
|
||||
etudiants.sort(tri_etud);
|
||||
afficher(etudiants);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user