开发者

Fantasy Football - Implementing Classes Trouble

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 appreciate开发者_如何学运维d 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");
}


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜