梦幻足球 - 实施课程麻烦

时间:2011-03-21 21:59:56

标签: c++ class list

我继续努力使用类来创建C ++ Generated Fantasy Football Draft。我觉得我对课程的理解很好,但在这种情况下我很难实现它们。我想上传我编写的代码,我在代码中有一些关于实现“团队”类和“播放器”类的具体注释。

任何和所有帮助表示赞赏 另外,如果我没有正确上传,请告诉我。

    // 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");
}

1 个答案:

答案 0 :(得分:0)

这是不对的:

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

我不确定你在这里要做什么。

team是一个类,但您将其作为数组引用。你的意图是什么?

我建议使用标准容器(vector,deque等),而不是滚动自己的链表(除非是实现列表的功课)。

放弃全局变量的习惯。

失去system("pause");system("pause"); - Why is it wrong?