TP7: formattage

This commit is contained in:
2024-11-28 13:48:19 +01:00
parent 456150e6b1
commit 0a54ea3aca
3 changed files with 28 additions and 2 deletions

View File

@@ -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 {

View File

@@ -2,6 +2,8 @@
#include "Pays.h"
#include <iostream>
#include <iomanip>
#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;
}

View File

@@ -1,9 +1,21 @@
#pragma once
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;
void getfloat(ifstream& s, float& f, const char sep);
void getint(ifstream& s, int& f, const char sep);
template <class T>
void format(T t, int w) {
cout << left << setw(w) << t << " ";
}
template <class T>
void format(T t) {
format(t, 4);
}