Nov 22, 2017 at 9:29pm UTC
Hello people! I need help with an exam task that I can not handle ... I'm new to programming and I have no idea how to do it. I'll be grateful for your help! Here's her task:
Console application (without input from the console - possibly with arrays with fixed application data). At a shooting competition that takes place once a year, there are up to 30 contestants. For each individual competition, a stand-alone list of participants information is made. Each athlete is described with the name, PIN and points he receives (eg Ivan Ivanov - 1234567890 - 60). Competition data was entered in 2015, 2016, and 2017. Provide information - for the competition with the highest total number of points and the competition with the lowest total number of points. - the competitor (s) with the highest total points for all years.
Last edited on Nov 23, 2017 at 2:59am UTC
Nov 23, 2017 at 2:13am UTC
> the race with the highest total number of points
¿race?
> the competitor (s) with the highest total points for all years.
¿for each year or you make a weighted average?
Nov 23, 2017 at 2:58am UTC
Sorry! Broken English... The same competitors for all years. For example, John Dow with maximum points for 2015 + 2016 + 2017.
Nov 24, 2017 at 2:55am UTC
#include <iostream>
#include <string>
#include <conio.h>
#include <map>
#include <list>
using namespace std;
struct person
{
string name;
double egn;
int points;
};
int main()
{
map<int, list<person>> competitions;
map<double, int> persons;
map<double, string> nameByEgn;
competitions[2015] = { { "John", 8505234344, 20 }, { "Mark", 8505234345, 20 } };
competitions[2016] = { { "John", 8505234344, 19 }, { "Mark", 8505234345, 17 }, { "Mery", 8505234346, 17 } };
competitions[2017] = { { "John", 8505234344, 25 }, { "Mark", 8505234345, 30 } };
int min = INT32_MAX;
int max = INT32_MIN;
string min_year;
string max_year;
for (map<int, list<person>>::iterator competitionIt = competitions.begin(); competitionIt != competitions.end(); ++competitionIt)
{
int sum = 0;
for (list<person>::iterator personIt = competitionIt->second.begin(); personIt != competitionIt->second.end(); ++personIt)
{
sum += personIt->points;
if (persons.find(personIt->egn) == persons.end())
{
persons[personIt->egn] = 0;
}
persons[personIt->egn] += personIt->points;
if (nameByEgn.find(personIt->egn) == nameByEgn.end())
{
nameByEgn[personIt->egn] = personIt->name;
}
else if (nameByEgn[personIt->egn] != personIt->name)
{
cout.precision(0);
cout << "Error: " << nameByEgn[personIt->egn] << " and " << personIt->name << " are with same id=" << fixed << personIt->egn << endl;
_getch();
return 1;
}
}
if (sum < min)
{
min = sum;
min_year = to_string(competitionIt->first);
}
else if (sum == min)
{
min_year += ", ";
min_year += to_string(competitionIt->first);
}
if (sum > max)
{
max = sum;
max_year = to_string(competitionIt->first);
}
else if (sum == max)
{
max_year += ", ";
max_year += to_string(competitionIt->first);
}
}
cout << "Max points: " << max << " year " << max_year << endl;
cout << "Min points: " << min << " year " << min_year << endl;
int max_points = INT32_MIN;
double max_egn;
for (map<double, int>::iterator it = persons.begin(); it != persons.end(); ++it)
{
if (max_points < it->second)
{
max_points = it->second;
max_egn = it->first;
}
}
cout.precision(0);
cout << nameByEgn[max_egn] << " with id=" << fixed << max_egn << " has max points: " << max_points;
_getch();
return 0;
}
What is wrong in this code???
Last edited on Nov 25, 2017 at 10:12pm UTC
Nov 25, 2017 at 11:52pm UTC
> What is wrong in this code?
¿why are you asking? ¿does it solve your problem?
the code is quite convoluted and doesn't have a single comment, not going to analyse it.
Nov 26, 2017 at 10:12am UTC
so I thought it would make a decision on my assignment, but I'm mistaken... I would not want help here if I knew how to solve my problem myself...
Nov 30, 2017 at 6:20am UTC
I understood what is wrong - just my IDE is not ok...