-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.cpp
90 lines (79 loc) · 2.6 KB
/
display.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <math.h>
#include <stdio.h>
#include <string>
#include "partylist.cpp"
#include "settings.h"
#pragma once
namespace panachage
{
void displayAllCandidates(std::vector<partylist *> lists)
{
const int cols = 3;
const int rows = floor(lists.size() / cols) + 1;
std::string margin(3, ' ');
partylist *row_lists[cols];
int row_length = cols;
int index;
int seats;
for (int row = 0; row < rows; row++)
{
for (int i = 0; i < cols; i++)
{
index = row * cols + i;
if (index >= lists.size())
{
row_length = i;
break;
}
row_lists[i] = lists[index];
}
seats = 0;
for (int i = 0; i < row_length; i++)
{
partylist *plist = row_lists[i];
seats = std::max(seats, (int)plist->candidate_votes.size());
printf("| List: %-3i ALV: %-6i", plist->id, plist->at_large_votes);
printf(margin.c_str());
}
printf("\n");
for (int r = 1; r <= seats; r++)
{
for (int i = 0; i < row_length; i++)
{
partylist *list = row_lists[i];
if (r <= list->candidate_votes.size())
{
std::vector<candidate::id_type> cs = list->candidateList();
const candidate::id_type cand_id = cs[r - 1];
printf("| %-3i | %-5i | %-5i |", r, cand_id, list->candidate_votes[cand_id]);
printf(margin.c_str());
}
}
printf("\n");
}
for (int i = 0; i < row_length; i++)
{
partylist *list = row_lists[i];
printf("| %-11s | %-5i |", "Party total", list->totalVotes());
printf(margin.c_str());
}
printf("\n");
if (row != rows - 1)
{
printf("\n");
}
}
}
void electedCandidates(std::vector<partylist> lists, const int partyc, party *parties)
{
for (partylist pl : lists)
{
const int seats = party_get_seats(partyc, parties, pl.id);
std::vector<candidate::id_type> el = pl.elected(seats);
for (candidate::id_type cand_id : el)
{
std::cout << std::setw(5) << pl.name << " " << cand_id << std::endl;
}
}
}
}