| Код | #include <conio.h> #include <iostream>
using namespace std; enum Marks{COPPERY = 5, SILVER, GOLD};
typedef class T_TEAM { private: int num_of_gold_medal; int num_of_silver_medal; int num_of_coppery_medal; int mark; int team_number; public: T_TEAM() { num_of_gold_medal = 0; num_of_silver_medal = 0; num_of_coppery_medal = 0; mark = 0; team_number = 0; }; void SetValue(int value, int type) { if (type == GOLD) num_of_gold_medal = value; if (type == SILVER) num_of_silver_medal = value; if (type == COPPERY) num_of_coppery_medal = value; mark = num_of_gold_medal*GOLD+ num_of_silver_medal*SILVER+ num_of_coppery_medal*COPPERY; } void SetTeamNumber(int num) { team_number = num; } int GetTeamNumber() { return team_number; } int GetMark() { return mark; } } TEAM;
void Sort(TEAM*, int);
void main() { int NumOfTeam = 1; int NumOfGold = 0, NumOfSilver = 0, NumOfCoppery = 0; int temp, i; do { if (NumOfTeam <= 0) cout << "Entered value is wrong. Try again." << endl; cout << "Enter number of teams: "; cin >> NumOfTeam; } while (NumOfTeam <= 0); TEAM * RealTeam = new TEAM[NumOfTeam]; for (i = 0; i < NumOfTeam; i++) { RealTeam[i].SetTeamNumber(i+1); cout << "Enter number of gold medals in team " << i+1 << ": "; cin >> temp; RealTeam[i].SetValue(temp, GOLD); NumOfGold += temp; cout << "Enter number of silver medals in team " << i+1 << ": "; cin >> temp; RealTeam[i].SetValue(temp, SILVER); NumOfSilver += temp; cout << "Enter number of coppery medals in team " << i+1 << ": "; cin >> temp; RealTeam[i].SetValue(temp, COPPERY); NumOfCoppery += temp; cout << "==========" << endl; } cout << "=//=//=//= Totalics //=//=//=//" << endl; cout << "Full number of gold medals: " << NumOfGold << ". Total mark: " << NumOfGold*GOLD << endl; cout << "Full number of silver medals: " << NumOfSilver << ". Total mark: " << NumOfSilver*SILVER << endl; cout << "Full number of coppery medals: " << NumOfGold << ". Total mark: " << NumOfCoppery*COPPERY << endl; Sort(RealTeam, NumOfTeam); cout << "******************" << endl; cout << "Total results, sorted by marks: " << endl; for (i = 0; i < NumOfTeam; i++) { cout << "Command number: " << RealTeam[i].GetTeamNumber() << ". Mark: " << RealTeam[i].GetMark() << ".\n"; } delete[] RealTeam; }
void Sort(TEAM* RealTeam, int NumOfTeam) { TEAM Temp; int flag; do { flag = 0; for (int i = 0; i < NumOfTeam - 1; i++) { if (RealTeam[i].GetMark() < RealTeam[i+1].GetMark()) { flag = 1; Temp = RealTeam[i]; RealTeam[i] = RealTeam[i+1]; RealTeam[i+1] = Temp; } } } while (flag); }
|
|