assignment help

hi everyone. i am new here and here for help from some masterminds of the language.
i have been given a task to make a program on visual studio which is based on English premier league with 20 teams.data coming from two input files one with team names we have to store it and arrange in alphabetical order. and second data set containing all team matches scores in format (team_one score1 team_two score2.
for each game i have to read scores and put them to each team (they win get 3 points and loose 0 points and draw 2 points each team) all have to count games played for each team and goals against and goals done.

a brief help on how to start and finish will be appreciated.
i want to learn this language thanks :)
so basically you have to do the table containing the stats during one season. but sort them in alphabetic order and not by points, like tables usually do.

here is what you need
read and write from files: http://www.cplusplus.com/doc/tutorial/files/
strings: http://www.cplusplus.com/reference/string/string/
container to save the teams: http://www.cplusplus.com/reference/stl/ (would use vector or array)
sorting the teams: http://www.cplusplus.com/reference/algorithm/sort/
closed account (o3hC5Di1)
Hi there,

Welcome to the forums :)

Usually what we do is ask you to make a first attempt at the assignment.
That way we can spot where you're going wrong, where you're using flawed logic, etc.

Here's some pointers to get you started though:

* It seems like it would be best to create a struct that stands for a team and a struct that makes a league entry, this would look like this:

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
struct football_team
{
    std::string name;
};

struct league_entry
{
    football_team team;
    int points;
    int goals_against;
    int goals_done;
}

//Example use:
football_team chelsea;
chelsea.name = "Chelsea F.C.";

football_team westham;
chelsea.name = "Westham United F.C.";

//Create league entries, records
league_entry l1, l2;
l1.team = chelsea;
l2.team = westham;

//The actual league is an array of league entries, or records if you will
league_entry league[2];
league[0] = l1;
league[1] = l2;


Using this, whilst you read the first file with the team names, you should set up the basics:
- create a football_team object for every line in the file
- Create a league_entry for every team
- add it to the league array

The,n, reading the second file, for every entry you need to:
- read the score:

1
2
3
4
5
6
std::string team_a, team_b;
int score_a, score_b, league_points_a, league_points_b;

file >> team_a >> score_a >>team_b >> score_b;

//if score_a > score_b => league_points_a = 3, league_points_b = 0, etc. 


- Search the relevant entries in the league table:

1
2
3
//iterate (loop) the array,
if (league[i].team.name == team_a)
    league[i].points += league_points_a;



Some considerations:
- You may want to use a std::array or std::vector if you are allowed to
- The league[] array could also be implemented as a std::map, which would keep it automatically sorted for you, but if this is a beginners assignment that's probably not the intended case.

Please do let us know if you have any further questions.

All the best,
NwN
int read_scores(team_t *teams);
int main
void()
team_t teams[20];
int i;
for(i=0; i < 20; i++){
teams[i].played= 0;
teams[i].points= 0;
teams[i].goal_diff= 0;
teams[i].goals_scored= 0;
for(int j=0;j<20;j++){
teams[i].name[j] = ' ' ;
}
}

i tried to makeout this using a textbook with a similar program
please help me understanding whats happening in this part of code.
closed account (o3hC5Di1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//create an array with space for 20 teams
team_t teams[20];

//performthe following codeblock for every position in the array
for(int i=0; i < 20; i++){
    //set the beneath properties of each team to 0
    teams[i].played= 0;
    teams[i].points= 0;
    teams[i].goal_diff= 0;
    teams[i].goals_scored= 0;

    //this seems weird, why would team_t hold the names of every team?
    //anyway, it sets the name property to '' (empty)
    for(int j=0;j<20;j++){
        teams[i].name[j] = ' ' ;
    }
}


It basically initializes the array to empty team_t objects.

All the best,
NwN
here is what iam getting
#include "stdafx.h"
#include "math.h"
#include "string.h"
int scores
typedef struct {
int totalpoints;
int totalplayed;
int goalscored;
int goaldiff;
char teamname[20];
}
teams *team[20]

int
main(void)
{ teams[20];
int i;
for (i=0;i<20;i++){
teamname[i].totalpoints= 0;
teamname[i].totalplayed= 0;
teamname[i].goalscored= 0;
teamname[i].goaldiff= 0;
for9int j=0;j<20;j++){
teams[i].teamname[j]=' ';
}
}
/*reading the input1a file containing team names*/
FILE *File_Input1a = fopen("C:\\Users\\Kamal\\Desktop\\Assignmennt\\input1a.dat", "r");
while (fscanf(File_input1a, "%s" ,teams[i].name)!=EOF )
{printf("%s \n",teams[i].name);
i++;
}
fclose(File_Input1a);
return(0);
}

/*reading scores from second file*/
int scores
FILE *File_Input1b = fopen("C:\\Users\\Kamal\\Desktop\\Assignmennt\\input1b.dat", "r");
int i=0;
char team 1, team 2;
int score1, score2;

printf("Name\tPoints\tplayed\tgoals scored\tgoals against\n")
while (fcanf(File_input1b,%s %i %s %i",&team1 &score1 &team2 &score2)!=Eof)
{ for(team=0;team<20;team++)
please help. i need a helping hand. due date is in 24 hours.
please if some1 can edit the code and tell me thoroughly whats next
will be appreciated
thanks alot
closed account (o3hC5Di1)
The code you posted is C, not C++.
If you are taking a C++ class, that probably won't do.

I gave you a whole post offering the building blocks to a solution, off course there are other ways, but that's the one I'd go for off the top of my head. If you have any questions about that post, I'd be happy to answer them.

All the best,
NwN
Topic archived. No new replies allowed.