GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Jan-2005, 11:44
swayp swayp is offline
New Member
 
Join Date: Jan 2005
Posts: 25
swayp is on a distinguished road
Question

help please.. linkedlists/classes


hi, ive never posted here before so im hoping i can get some help with this question i got:

im reading in a database, and its from a file which is nfl stats.. i cant figure out how to organize the data. its a list of a bunch of players and for each person it gives basic stats (height,weight,college,position,etc.)

but then it breaks down there stats depending on what positoin they play. so quarterback could have stats for rushing and passing or rushing and fumbles, and a wide reciever would have rushing and recieving. or recieving and fumbles. or someone might have punt returns and defensive stats.. heres an example of one of them:

# 20 Ed Reed
Position: SS
Height: 5-11
Weight: 200
Born: 09/11/1978
College: Miami (Fla.)
NFL Experience: 3
Baltimore Ravens
DEFENSIVE STATS
Year Team G Total Tckl Ast Sacks Int Yds Avg Lg TD Pass Def
2002 Baltimore Ravens 16 85 71.0 14 1 5 167 33.4 59 0 7
2003 Baltimore Ravens 16 71 59.0 12 1 7 132 18.9 54 1 9
2004 Baltimore Ravens 13 61 54.0 7 2 8 317 39.6 106 1 7
TOTAL 45 217 184.0 33 4 20 616 30.8 106 2 23
PUNT RETURNS
Year Team G No FC Yards Avg Lg TD 20+
2002 Baltimore Ravens 16 0 0 0 --- 0 0 0
2003 Baltimore Ravens 16 5 3 33 6.6 19 0 0
2004 Baltimore Ravens 13 0 0 0 --- 0 0 0
TOTAL 45 5 3 33 6.6 19 0 0
FUMBLES
Year Team G Fum Lost Fum Forced Own Rec Opp Rec Yards Tot Rec TD
2002 Baltimore Ravens 16 1 1 0 0 0 0 0 0
2003 Baltimore Ravens 16 1 1 1 0 0 0 0 0
2004 Baltimore Ravens 13 1 0 2 0 2 44 2 1
TOTAL


i know thats kinda hard to read.. but u can see that theres fumbles defensive stats and punt returns. and terell owns has recieving and rushing.. so how do i make classes to store all these things as im reading them in. do i have to make a different class for each stat title (i.e. rushing, recieving, fumbles, defensive stats, etc.) because they each have different stats that would need dif variables. or do i just make allllll the different kinds of stats private members of just a player class.. i dont get it if someone could help me or if u need me to explain better let me know
  #2  
Old 17-Jan-2005, 13:40
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hello swayp and welcome to GIDForums™.

I think the problem with your program is that you are using a Baltimore Raven in your example!!!!! Look under Steelers, Pittsburgh for *real* football players

Seriously though, this seems like a great place to use some inheritance in a class.

Your base class can consist of anything that all players share:

CPP / C++ / C Code:
class player{
  public:
    char name[100];
    char team[100];
    char position[100];
    int weight;
};

and so on.

Then you can make an inherited class for specialized players:
CPP / C++ / C Code:
class def_player : player{
  public:
   long sacks;
   int interceptions;
   long tackles;
};

CPP / C++ / C Code:
class quarterback : player{
  public:
    int attempts;
    int completions;
    long rating;
};

Obviously there is a ton more to it than this, but this is a start. It is a perfect example of where to use inheritance.

One more example of multiple inheritance:
CPP / C++ / C Code:
class receiver : player{
   ...
};

class hines_ward : receiver{
  ... 
};
//Because Hines Ward is in a class by himself!!
Sorry, but if it is not obvious I am somewhat of a Steelers fan.

Good luck with this. What are you doing with this anyway if I may ask?
  #3  
Old 17-Jan-2005, 14:05
swayp swayp is offline
New Member
 
Join Date: Jan 2005
Posts: 25
swayp is on a distinguished road
Ok first of all...
I'm a Jet fan, so you have no idea how much I hate you (and Dougie Brien)
heh.. but thanks for your help.


Ok the inheritance stuff makes sense, and I'm going to try that. So i understand having the base class of a player, and then using the inheritance for the different positions, and then having there private variables based on the stats according to the position.

but at the end, do you think I should make a class for each player (because their are a bunch, I just only listed one) or should they just be objects of the particular class

i.e. if i read santana moss in.. should he be an object of the class reciever : player. like u listed below. or do u think each person should be his own class like u listed with hines

thanks for ur help
j e t s
  #4  
Old 17-Jan-2005, 15:19
swayp swayp is offline
New Member
 
Join Date: Jan 2005
Posts: 25
swayp is on a distinguished road
i have another question..

which members should be public private or protected?
for the player class should it be like this:

CPP / C++ / C Code:
class player {
public:
  player();
protected:
  char number[100];
  char name[100];
  char position[100];
  char height[100];
  int weight;
  char dob[100];
  char college[100];
  int experience;
  char team[100];
}

and then for the inherited class should the stats like "completitions, attempts, etc" should those be public like u listed or should they be private or protected.. and why?

also, should all the inherited classes have constructors? i would assume it should look like this, but i may be wrong:

CPP / C++ / C Code:
class reciever : public player {
 public:
   reciever();
 private:
   int year;
   char team[100];
   ...
}

or am i attacking this all wrong

please help, thanks
Last edited by LuciWiz : 26-Mar-2006 at 07:38. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #5  
Old 17-Jan-2005, 17:07
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi swayp.

First of all, the Jets have my utmost respect and admiration. To play a game like that and loose has got to be heart breaking.

Anyway, the Hines Ward thing was just a joke, but it does show multiple inheritance. Once you have a "reciever" class then you would simply add a new reciever for Santana Moss or Hines Ward, etc.

Here is my understanding of public, private & protected:

public is fully accessible from outside the class.
private is fully inaccessible from outside the class (even if it is inherited)
protected is fully accesible to the inherited class and acts like private within that inherited class.

The correct way to use OOP would be that all of your data fields are private (or protected). This is the cleanest and safest way to do it, but it is not an absolute necesity.

As for constructors - destructors yes each inherited class would have its own - but they can also call the parent constructor. So if you want to initialize all of the general variables, you only need to do that coding once in the base class.

Sometimes in programming there is the elegant or nice way to do things (ie inheritance) or the straight forward brute force method (ie completely seperate classes). You need to decide what is best for you and if you need help let us know.

Oh one more thing on the Jets, I just found this: ebay bid item for Doug Brien

You aren't the only one that is bitter today...
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:54.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.