TP8: Coq
This commit is contained in:
31
TP8/COQ/COQ.sln
Normal file
31
TP8/COQ/COQ.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}") = "COQ", "COQ.vcxproj", "{B01EA899-3FB4-4537-BC98-F70A30C56399}"
|
||||
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
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Debug|x64.Build.0 = Debug|x64
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Debug|x86.Build.0 = Debug|Win32
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Release|x64.ActiveCfg = Release|x64
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Release|x64.Build.0 = Release|x64
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Release|x86.ActiveCfg = Release|Win32
|
||||
{B01EA899-3FB4-4537-BC98-F70A30C56399}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {CEFA4EB7-CAEA-4B51-B46C-5AAD3C89E542}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
135
TP8/COQ/COQ.vcxproj
Normal file
135
TP8/COQ/COQ.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>{b01ea899-3fb4-4537-bc98-f70a30c56399}</ProjectGuid>
|
||||
<RootNamespace>COQ</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
TP8/COQ/COQ.vcxproj.filters
Normal file
22
TP8/COQ/COQ.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
TP8/COQ/COQ.vcxproj.user
Normal file
4
TP8/COQ/COQ.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>
|
||||
BIN
TP8/COQ/Côté_Coq_Poule.pdf
Normal file
BIN
TP8/COQ/Côté_Coq_Poule.pdf
Normal file
Binary file not shown.
245
TP8/COQ/main.cpp
Normal file
245
TP8/COQ/main.cpp
Normal file
@@ -0,0 +1,245 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Poule;
|
||||
class Oeuf;
|
||||
|
||||
template <class C>
|
||||
void affiche_cont(C& cont) {
|
||||
for (auto& volaille : cont) {
|
||||
volaille.affiche();
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
class Coq {
|
||||
string Nom;
|
||||
int Age;
|
||||
|
||||
public:
|
||||
void saisie();
|
||||
void affiche();
|
||||
|
||||
Oeuf Cocorico(Poule p);
|
||||
|
||||
bool operator<(Coq& c2) {
|
||||
return Age < c2.Age;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void CocoricoPoules(C&c) {
|
||||
vector<Oeuf> oeufs;
|
||||
oeufs.reserve(c.size());
|
||||
for (auto poule : c) {
|
||||
oeufs.push_back(Cocorico(poule));
|
||||
}
|
||||
affiche_cont(oeufs);
|
||||
}
|
||||
};
|
||||
|
||||
class Poule {
|
||||
string Nom;
|
||||
int Poids;
|
||||
|
||||
friend Coq;
|
||||
|
||||
protected:
|
||||
void set_poids(int poids) { Poids = poids; }
|
||||
|
||||
public:
|
||||
void saisie();
|
||||
void affiche();
|
||||
|
||||
float get_poids() {
|
||||
return Poids;
|
||||
}
|
||||
|
||||
bool operator<(Poule& c2) {
|
||||
return Poids < c2.Poids;
|
||||
}
|
||||
};
|
||||
|
||||
class Oeuf : public Poule {
|
||||
char Qualite;
|
||||
|
||||
public:
|
||||
Oeuf(int poids) {
|
||||
set_poids(poids);
|
||||
|
||||
cout << "L'oeuf a bien ete pondu et pese : "<<poids<<"(gr)" << endl;
|
||||
}
|
||||
|
||||
void saisie();
|
||||
void affiche();
|
||||
};
|
||||
|
||||
template <class C, class T>
|
||||
void saisie(C& cont, const string nom) {
|
||||
int n;
|
||||
|
||||
cout << "Combien de " << nom << " ? : ";
|
||||
cin >> n; cin.ignore();
|
||||
|
||||
while (n-- > 0) {
|
||||
T p;
|
||||
p.saisie();
|
||||
cont.insert(cont.begin(), p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int poids_poules(list<Poule> poules) {
|
||||
int S = 0;
|
||||
for (Poule& p : poules) {
|
||||
S += p.get_poids() / 1000;
|
||||
}
|
||||
return S;
|
||||
}
|
||||
|
||||
pair<Poule, Coq> couple(list<Poule> poules, vector<Coq> coqs) {
|
||||
auto poule = max_element(poules.begin(), poules.end());
|
||||
auto coq = min_element(coqs.begin(), coqs.end());
|
||||
|
||||
if (poule == poules.end() || coq == coqs.end()) {
|
||||
cout << "Aucun couple n'a pu être formé";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cout << "Le couple formé est ";
|
||||
coq->affiche();
|
||||
cout << " et ";
|
||||
poule->affiche();
|
||||
cout << endl;
|
||||
|
||||
return make_pair(*poule, *coq);
|
||||
}
|
||||
|
||||
Coq plus_vieux_coq(vector<Coq> coqs) {
|
||||
auto coq = max_element(coqs.begin(), coqs.end());
|
||||
if (coq == coqs.end()) {
|
||||
cout << "Il n'y a pas de coq!";
|
||||
exit(1);
|
||||
}
|
||||
return *coq;
|
||||
}
|
||||
|
||||
// Faut-il effacer l'unique élément si le conteneur ne contient qu'un seul élément ?
|
||||
// Supprimer la première moitié? que vaut la moitié pour 1 élement.
|
||||
template <class C>
|
||||
void effacer_moitie(C& c) {
|
||||
auto it = c.begin();
|
||||
for (int i = 0; i < c.size() / 2; i++) it++;
|
||||
|
||||
c.erase(c.begin(), it);
|
||||
}
|
||||
|
||||
int menu() {
|
||||
int c;
|
||||
|
||||
cout << "1) Saisir_Clav 1 List de Poule(s) (insertion au début) + Affichage" << endl
|
||||
<< "2) Saisir_Clav 1 Vector de Coq(s) (insertion au début) + Affichage" << endl
|
||||
<< "3) Calculer et afficher la Somme des poids en Kg : Sp" << endl
|
||||
<< "4) Le plus jeune des Coqs épouse la Poule la plus lourde" << endl
|
||||
<< "5) Le Coq fait Cocorico et toutes les Poules pondent + Affichage" << endl
|
||||
<< "6) Effacer la première moitié de List et de Vector + Affichage" << endl
|
||||
<< "Votre choix : ";
|
||||
|
||||
cin >> c; cin.ignore();
|
||||
return c;
|
||||
}
|
||||
|
||||
int main() {
|
||||
list<Poule> poules;
|
||||
vector<Coq> coqs;
|
||||
|
||||
float Sp;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
while (true) {
|
||||
switch (menu()) {
|
||||
case 1:
|
||||
saisie<list<Poule>, Poule>(poules, "Poules");
|
||||
affiche_cont(poules);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
saisie<vector<Coq>, Coq>(coqs, "Coqs");
|
||||
affiche_cont(coqs);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Sp = poids_poules(poules);
|
||||
cout << "Somme de Poids des poules en Kg : " << Sp;
|
||||
|
||||
break;
|
||||
case 4:
|
||||
couple(poules, coqs);
|
||||
|
||||
break;
|
||||
|
||||
// Cocorico
|
||||
case 5:
|
||||
plus_vieux_coq(coqs).CocoricoPoules(poules);
|
||||
break;
|
||||
case 6:
|
||||
effacer_moitie(coqs);
|
||||
effacer_moitie(poules);
|
||||
|
||||
affiche_cont(coqs);
|
||||
affiche_cont(poules);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Poule::saisie() {
|
||||
cout << "Le nom ? : ";
|
||||
getline(cin, Nom);
|
||||
cout << "Le poids ? : ";
|
||||
cin >> Poids; cin.ignore();
|
||||
}
|
||||
|
||||
void Coq::saisie() {
|
||||
cout << "Le nom ? : ";
|
||||
getline(cin, Nom);
|
||||
cout << "L' age ? : ";
|
||||
cin >> Age; cin.ignore();
|
||||
}
|
||||
|
||||
void Poule::affiche() {
|
||||
cout << Nom << "(" << Poids << ") ";
|
||||
}
|
||||
|
||||
void Coq::affiche() {
|
||||
cout << Nom << "(" << Age << ") ";
|
||||
}
|
||||
|
||||
void Oeuf::affiche() {
|
||||
cout << Qualite << "(" << get_poids() << "gr)";
|
||||
}
|
||||
|
||||
void Oeuf::saisie() {
|
||||
cout << "Saisir qualité de l'oeuf (A, B ou C) ? : ";
|
||||
cin >> Qualite;
|
||||
}
|
||||
|
||||
Oeuf Coq::Cocorico(Poule p) {
|
||||
Oeuf oeuf(p.get_poids() / 10);
|
||||
|
||||
oeuf.saisie();
|
||||
|
||||
return oeuf;
|
||||
}
|
||||
Reference in New Issue
Block a user