any suggestions for this piece of code as a database class?

This is a discussion on any suggestions for this piece of code as a database class? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <string> using namespace std; #define MAX_RACES 20 class Races { public: int raceID; string raceName; string ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    84

    any suggestions for this piece of code as a database class?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    #define MAX_RACES 20
    
    class Races
    {
    public:
    	int raceID;
    	string raceName;
    	string raceEner;
    	string raceEP;
    	string raceDesc;
    	float raceAttG[4];
    	float raceResE[3];
    	float raceResP[3];
    	float raceResM[3];
    
    	Races() {};
    
    	void raceInfo(int a, string b, string c, string d, string e, float f, float g, float aa, float ab, float ac, float ad, 
    		float ae, float af, float ag, float ba, float bb, float bc, float bd)
    	{
    		raceID = a;
    	    raceName = b;
    	    raceEner = c;
    	    raceEP = d;
    	    raceDesc = e;
    		raceAttG[0] = f;
    		raceAttG[1] = g;
    		raceAttG[2] = aa;
    		raceAttG[3] = ab;
    	    raceResE[0] = ac;
    		raceResE[1] = ad;
    		raceResE[2] = ae;
    	    raceResP[0] = af;
    		raceResP[1] = ag;
    		raceResP[2] = ba;
    	    raceResM[0] = bb;
    		raceResM[1] = bc;
    		raceResM[2] = bd;
    	}
    }DBraces[MAX_RACES], charRace;
    
    int main()
    {
    	DBraces[1].raceInfo(1, "a", "a", "a", "a", 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5);
    
    	return 0;
    }
    any suggestions for this piece of code as a database class?

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    84
    its error free, so don't worry about the technical part XD

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The constructor should set the object into a valid state (the empty constructor doesn't initialize the built-in numeric types, if I'm not mistaken).

    The raceInfo function has a bit too many parameters, made worse because the parameters are mostly of the same type and non-descriptively named. You could easily forget what each of the argument means and other won't bother to track that at all. Perhaps you could group the arguments into smaller structs of their own? Or provide a couple of more specific methods that don't have that many arguments.

    You don't need to make the array and the instance global, at least not for this example.

    There is use of magic values (4 and 3). Since it is not clear why the arrays should have that size, it is hard to tell whether one being 4 is an error?

    The class seems to be misnamed (it represents one race?) and there isn't much reasons to prepend all member variables with the word race.

    Some of the member variables might have more descriptive names too.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dialogue class code for RPG
    By ~Kyo~ in forum Game Programming
    Replies: 9
    Last Post: 07-03-2010, 07:10 AM
  2. Need a second opinion - code error and i cant see it
    By bigfootneedhelp in forum C Programming
    Replies: 19
    Last Post: 10-25-2007, 07:02 AM
  3. Help with a piece of code
    By Victor4015 in forum C++ Programming
    Replies: 1
    Last Post: 11-16-2005, 05:38 PM
  4. Replies: 8
    Last Post: 10-02-2005, 01:27 AM
  5. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21