Advertisement
NickAndNick

Турнирная таблица по футболу

Nov 6th, 2020
1,902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std;
  6. class Football {
  7. public:
  8.     Football() :
  9.         game_(0), win_(0), draw_(0), losing_(0), gs_(0), gc_(0) {}
  10.     explicit Football(string& name) :
  11.         name_(name), game_(0), win_(0), draw_(0), losing_(0), gs_(0),gc_(0) {}
  12.     void win(unsigned value) {
  13.         win_ = value;
  14.         game_ += value;
  15.     }
  16.     void draw(unsigned value) {
  17.         draw_ = value;
  18.         game_ += value;
  19.     }
  20.     void losing(unsigned value) {
  21.         losing_ = value;
  22.         game_ += value;
  23.     }
  24.     void goals_scored(unsigned value) {
  25.         gs_ = value;
  26.     }
  27.     void goals_conceded(unsigned value) {
  28.         gc_ = value;
  29.     }
  30.     unsigned points_scored()const {
  31.         return win_ * 3 + draw_;
  32.     }
  33. private:
  34.     string name_;
  35.     unsigned game_;
  36.     unsigned win_;
  37.     unsigned draw_;
  38.     unsigned losing_;
  39.     unsigned gs_;
  40.     unsigned gc_;
  41.     friend ostream& operator<<(ostream& out, const Football& fb) {
  42.         out << left << setw(24) << fb.name_ << right
  43.             << setw(5) << fb.game_
  44.             << setw(5) << fb.win_
  45.             << setw(5) << fb.draw_
  46.             << setw(5) << fb.losing_
  47.             << setw(5) << fb.gs_
  48.             << " - " << setw(2) << fb.gc_
  49.             << setw(5) << fb.points_scored();
  50.         return out;
  51.     }
  52.     friend bool operator>(const Football& a, const Football& b) {
  53.         return a.points_scored() > b.points_scored();
  54.     }
  55. };
  56. unsigned input(const char* msg) {
  57.     cout << msg;
  58.     unsigned value;
  59.     cin >> value;
  60.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  61.     return value;
  62. }
  63. Football team() {
  64.     cout << "Название команды: ";
  65.     string name;
  66.     getline(cin, name);
  67.     Football club(name);
  68.     club.win(input("Количество побед: "));
  69.     club.draw(input("Количество ничьих: "));
  70.     club.losing(input("Количество поражений: "));
  71.     club.goals_scored(input("Количество забитых мячей: "));
  72.     club.goals_conceded(input("Количество пропущенных мячей: "));
  73.     return club;
  74. }
  75. void title() {
  76.     cout << "\n"
  77.         << setw(15) << "Команда"
  78.         << setw(14) << "И"
  79.         << setw(5) << "В"
  80.         << setw(5) << "Н"
  81.         << setw(5) << "П"
  82.         << setw(9) << "З - П"
  83.         << setw(8) << \n\n";
  84. }
  85. int main() {
  86.     system("chcp 1251 > nul");
  87.     Football table[8];
  88.     for (auto& club : table) club = team();
  89.     sort(begin(table), end(table), greater<Football>());
  90.     system("cls");
  91.     title();
  92.     for (const auto& club : table) cout << club << '\n';
  93.     system("pause > nul");
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement