0

I have continued my struggles in using classes to create a C++ Generated Fantasy Football Draft. I feel like I have an okay understanding of classes, but am having trouble implementing them in this case. I would like to upload the code I have written, and I have some specific comments in the code about implementing the "team" class and "player" class mainly.

Any and all help appreciated Also, if I did not upload this correctly, please let me know.

    // main.cpp - Where the winners are crowned
// Written by Mike Green

#include <iostream>
#include <string>

using namespace std;

void add_name_at_end();
void traverse();


// Declaration of name, and the -> next pointer
struct Names
{
    string name;
    string name2;
    struct Names *next;

};
Names *start_ptr = NULL;
int option = 0;


// ---------------------------Adding of players to Draft-----------------------------
void add_name_at_end()
{
    // Temporary pointers
    Names *temp, *temp2;

    // Reserve space for a new node
    temp = new Names;
    cout << "Please enter YOUR chosen team name:";
    cin >> temp->name;


    temp->next = NULL;


    // Sets the pointer from this node to the next NULL
    // If list empty at beginning just set start pointer to this node
    if (start_ptr == NULL)
        start_ptr = temp;
    else
    {
        temp2 = start_ptr;
        while (temp2->next != NULL)
        {
            temp2 = temp2->next;
        }

            temp2->next = temp;
    }

}

// --------------------------Traversing the List------------------------------
void traverse()
{
Names *temp;
temp = start_ptr;

do
{
if(temp == NULL)
cout << "These are the teams: " << endl;
else
{
    cout << "Team Name: " << temp->name << endl;
    temp = temp->next;

    }
}while (temp != NULL);
}

// -------------------------Team Class----------------------------
class team
{
    // -------------String "Name" or "Names" here?----------------
    //---------------How to recall what they enter as their team name? Or how does this work?----------------
    //---------------Really stuck here..------------------
    string Name;
    int points;
    team *myPlayers;
    int insert;

};


//------------------------Players Class-------------------------
class players
{
    // ------------Used to store the list of players that are draftable---------------
    //----------------Read in a file, Or create an array?
    string Name;
    int points;
    bool taken;

};



//-----------------Main---------------------------
int main()
{
    start_ptr = NULL;
    cout << "Welcome to Fantasy Football" << endl;


    //int numberofPlayers;
    //cout << "How many players will be playing today? (1-8)";
    //cin >> numberofPlayers;
    //cout << "There will be " << numberofPlayers << " players playing today." << endl;

    //if (numberofPlayers < 0 || numberofPlayers > 8)
    //  cout << "You did not enter a number between 1 and 8" << endl;

    do
    {
        cout << endl;
        cout << "What would you like to do? " << endl;
        cout << "1 - Insert Another Player For The Draft" << endl;
        cout << "2 - Finished Adding Players " << endl;
        cout << endl << " >> ";
        cin >> option;

        switch(option)
        {
        case 1: add_name_at_end();
            break;
        case 2: break;
        }

    }while (option != 2);

    if (option == 2)
    {
        cout << "These are the teams that will be drafting " << endl;
        traverse();
    }


    // ------------------This Loop does not work--------------
    // - Can't use team because it is a class?
    // - Name is unidentified?
    // - Still need to write the insert function.. But Where??
    for (int i = 1 || 2 || 3 || 4; i < 5; i++)
    {
        cout << team[i] << "chooses: " << endl;
        cin >> Name;
        team[i].insert(Name);
    }

    system ("pause");
}
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Mike
  • 51
  • 1
  • 2
  • 7

1 Answers1

0

This isn't right:

for (int i = 1 || 2 || 3 || 4; i < 5; i++)

I'm not sure what you're trying to do here.

team is a class, but you reference it as an array. What is your intent?

I'd recommend using standard containers (vector, deque, etc.) instead of rolling your own linked list (unless it's homework where implementing the list is the point).

Drop the habit of global variables.

Lose the system("pause");. system("pause"); - Why is it wrong?

Community
  • 1
  • 1
Fred Larson
  • 60,987
  • 18
  • 112
  • 174
  • Well there I am trying to say for i = NumberofTeamsDrafting; i < 5; i++ - Because the max teams drafting will be 4.. Not sure how else to say it. – Mike Mar 21 '11 at 22:20
  • @Mike: You will need to have a count of the number of teams, then. Initialize `i` to zero and count up to that number. You probably want to enforce the limit where `team` is populated. – Fred Larson Mar 21 '11 at 22:23
  • Okay so what I am trying to do with team now is saying for the first drafter i.e. Mike's Team, then he drafts a player and I want to send it to his team[i], basically saying, Mike's team chooses: "player", then insert the player to Mike's Team. Next, this is my idea for a final project, no standards were given so I can use whatever is easiest, but obviously, I'm not the most skilled programmer. As for global variables, I am confused. Thanks for the help so far. – Mike Mar 21 '11 at 22:32
  • Replace `system("pause")` with `std::cin.ignore(100000,'\n');`. – Thomas Matthews Mar 21 '11 at 23:02