Recently been asked to be a part of a C++ group project in Uni. The aim of our group is to be able to generate a football league table from a set number of fixtures.
My section of the work decides who has WON/LOSS/DREW the fixture and pass the number of points to another member of the group.
below is a small summary of the initial logic I am trying to achieve
Each team needs a variable storing its number of points. You need to update that, not some arbitrary variable that is reset to zero everytime you call the function. Also, it would be neat to do this with a struct or class. Do you know either or both of those? That way, you can have a string name (do you know how to use string?) and points total, as well as W/L/D record for each team easily.
I know what they all are in terms of a definition but putting them to good use it still what i am developing in class.
As far as the team names go, that is not really within my hands, as that is with another member of the group i will have to have a talk with him about how he feels he will be handing me the data.
I still have a few weeks left in the module so hopefully when im revising these topics they will become a little more clear to me of how to use them properly.
I will look into detail about trying to implement the class and passing the points variable to the actual team name(string). Hopefully this wont be too difficult. :)
Thanks, this has pointed me in the correct direction. I will upload my changes later for your attention.
/*
* Identifies the Win Loss Draw for each team
*
* This function takes a score, and identifies the outcome
* of fixture and delegates the points to that team
*
* @param a string containing the name of the team
* @param the number of points to add to the score
* @return true on success, false on failure
*/
void PointsAllocation::CalculateOutcome(Fixture f)
{
if(f.GetScore1() > f.GetScore2()) //GetScore1 comes from nialls variable
{
UpdatePoints(f.GetTeamName1(), 3);
UpdatePoints(f.GetTeamName2(), 0);
}
if(f.GetScore1() < f.GetScore2())
{
UpdatePoints(f.GetTeamName1(), 0);
UpdatePoints(f.GetTeamName2(), 3);
}
if(f.GetScore1() == f.GetScore2())
{
UpdatePoints(f.GetTeamName1(), 1);
UpdatePoints(f.GetTeamName2(), 1);
}
}
/*
* Updates the score for a given team
*
* This function takes a team name, and a score, and updates the table accordingly
*
* @param a string containing the name of the team
* @param the number of points to add to the score
* @return true on success, false on failure
*/
int PointsAllocation::UpdatePoints(char * TeamName, int Points)
{
// Search for the record TeamName...
// Oh, I couldn't find that team name
return(0); // false
// Update their points
// I did it...
return(1); // true
}
I can only see a little snippet of your code here, but I guess it looks fine.
You could add those W/L/D stats at the same time as you do the points allocations (if you want those stats in of course, but they are usually present in a league table).
Have you any more points, tips or even some sample code to help get me over the finish line??
How close to the finish line are you? I mean, are you reading in results and getting the table now? Or where are you at?