summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Prakt3/Aufg1/Table.cpp
blob: 9b6a2bf7731c2fe0336a281c0856319dd7f0ebce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Table.h"
#include "Team.h"
#include <iostream>
#include <iomanip>

using std::cout;
using std::endl;
using std::string;
using std::ostream;
using std::left;
using std::setw;

void Table::setTeam(const Team& toSet)
{
	teams.push_back(toSet);
}

void Table::print(ostream& output)
{
	int n=0;
	output << left << setw(22) << "Team" << setw(9) << "Matches" << setw(12) << "Games won" << setw(12)
		<< "Games lost" << setw(12) << "Points won" << setw(12) << "Points lost" << endl;;

	while(n<teams.size())
	{
		output << left << setw(22) << teams[n].getTeamName() << setw(9) << teams[n].getmatchesPlayed() << setw(12) << teams[n].getgamesWon() 
			<< setw(12)	<< teams[n].getgamesLost() << setw(12) << teams[n].getpointsWon() << setw(12) << teams[n].getpointsLost() <<endl;
		n++;
	}
}

void Table::sort()
{
	Team temp;
	int n;
	for (n=0;n<teams.size();n++)
	{	
		// start from actual position...
		for (int j=n;j<teams.size();j++)
		{   
			// ... search the maximum...
			//if(teams[j].getpointsWon()>teams[n].getpointsWon())
			if(!(teams[j]<teams[n]))
			{
				//... and insert it
				temp=teams[n];
				teams[n]=teams[j];
				teams[j]=temp;
			}
		}
	} 
}