TP7: formattage

This commit is contained in:
2024-11-28 13:48:19 +01:00
parent 456150e6b1
commit 4077114c96
7 changed files with 178 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

@@ -0,0 +1,39 @@
#include "Entreprise.h"
using namespace std;
void Entreprise::saisie(ifstream& s) {
string tmp;
getline(s, m_company, ';');
getline(s, m_country, ';');
getfloat(s, m_market_value, ';');
getline(s, m_sector, ';');
getfloat(s, m_turnover, ';');
getfloat(s, m_employees, ';');
getint(s, m_rank_2015, ';');
getint(s, m_rank_2014, ';');
}
void Entreprise::affichage() {
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 {
return m_rank_2014 - m_rank_2015;
}
float Entreprise::turnover_empl() const {
return (float)m_turnover / m_employees;
}
float Entreprise::getTurnover() const {
return m_turnover;
}

View File

@@ -0,0 +1,32 @@
#include "Entreprise.h"
using namespace std;
void Entreprise::saisie(ifstream& s) {
string tmp;
getline(s, m_company, ';');
getline(s, m_country, ';');
getfloat(s, m_market_value, ';');
getline(s, m_sector, ';');
getfloat(s, m_turnover, ';');
getfloat(s, m_employees, ';');
getint(s, m_rank_2015, ';');
getint(s, m_rank_2014, ';');
}
void Entreprise::affichage() {
cout << m_company << " " << m_country << " " << m_market_value << " " << m_sector << " " << m_turnover << " " << m_employees << " " << m_rank_2015 << " " << m_rank_2014;
}
int Entreprise::rank_progress() const {
return m_rank_2014 - m_rank_2015;
}
float Entreprise::turnover_empl() const {
return (float)m_turnover / m_employees;
}
float Entreprise::getTurnover() const {
return m_turnover;
}

View File

@@ -0,0 +1,39 @@
#include "Entreprise.h"
using namespace std;
void Entreprise::saisie(ifstream& s) {
string tmp;
getline(s, m_company, ';');
getline(s, m_country, ';');
getfloat(s, m_market_value, ';');
getline(s, m_sector, ';');
getfloat(s, m_turnover, ';');
getfloat(s, m_employees, ';');
getint(s, m_rank_2015, ';');
getint(s, m_rank_2014, ';');
}
void Entreprise::affichage() {
// 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 {
return m_rank_2014 - m_rank_2015;
}
float Entreprise::turnover_empl() const {
return (float)m_turnover / m_employees;
}
float Entreprise::getTurnover() const {
return m_turnover;
}

View File

@@ -0,0 +1,40 @@
#include "Entreprise.h"
using namespace std;
void Entreprise::saisie(ifstream& s) {
string tmp;
getline(s, m_company, ';');
getline(s, m_country, ';');
getfloat(s, m_market_value, ';');
getline(s, m_sector, ';');
getfloat(s, m_turnover, ';');
getfloat(s, m_employees, ';');
getint(s, m_rank_2015, ';');
getint(s, m_rank_2014, ';');
}
void Entreprise::affichage() {
format(m_company, 20);
format(m_country, 15);
format(m_market_value, 10);
format(m_sector, 10);
format(m_turnover, 10);
format(m_employees, 10);
format(m_employees, 10);
format(m_rank_2015, 10);
format(m_rank_2014, 10);
}
int Entreprise::rank_progress() const {
return m_rank_2014 - m_rank_2015;
}
float Entreprise::turnover_empl() const {
return (float)m_turnover / m_employees;
}
float Entreprise::getTurnover() const {
return m_turnover;
}

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);
}