From 0a54ea3aca7bf9bff535bc9eab72badbe2010cda Mon Sep 17 00:00:00 2001 From: theking90000 Date: Thu, 28 Nov 2024 13:48:19 +0100 Subject: [PATCH] TP7: formattage --- TP7/Entreprise.cpp | 9 ++++++++- TP7/Pays.cpp | 9 ++++++++- TP7/getio.h | 12 ++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/TP7/Entreprise.cpp b/TP7/Entreprise.cpp index 617fc34..b369c53 100644 --- a/TP7/Entreprise.cpp +++ b/TP7/Entreprise.cpp @@ -16,7 +16,14 @@ void Entreprise::saisie(ifstream& s) { } void Entreprise::affichage() { - cout << m_company << " " << m_country << " " << m_market_value << " " << m_sector << " " << m_turnover << " " << m_employees << " " << m_rank_2015 << " " << m_rank_2014; + format(m_company, 20); + format(m_country, 15); + format(m_market_value, 10); + format(m_sector, 10); + format(m_turnover, 10); + format(m_employees, 6); + format(m_rank_2015, 3); + format(m_rank_2014, 3); } int Entreprise::rank_progress() const { diff --git a/TP7/Pays.cpp b/TP7/Pays.cpp index 3013977..49199a6 100644 --- a/TP7/Pays.cpp +++ b/TP7/Pays.cpp @@ -2,6 +2,8 @@ #include "Pays.h" #include +#include +#include "getio.h" using namespace std; @@ -14,5 +16,10 @@ void Pays::saisie(ifstream &in) { } void Pays::affichage() { - cout << Region << " " << Nom << " " << Population; + // format(Region, 10); + format(Nom, 20); + cout << setprecision(10); + format(Population, 10); + format(Area, 10); + // << setprecision(10) << Population << " " << Area; } \ No newline at end of file diff --git a/TP7/getio.h b/TP7/getio.h index b4a8a57..10c6ca9 100644 --- a/TP7/getio.h +++ b/TP7/getio.h @@ -1,9 +1,21 @@ #pragma once #include +#include +#include using namespace std; void getfloat(ifstream& s, float& f, const char sep); void getint(ifstream& s, int& f, const char sep); + +template +void format(T t, int w) { + cout << left << setw(w) << t << " "; +} + +template +void format(T t) { + format(t, 4); +} \ No newline at end of file