2011-03-21 4 views
0

클래스를 사용하여 C++ Generated Fantasy Football Draft를 만드는 데 어려움을 겪었습니다. 나는 수업을 잘 이해하고있는 것처럼 느껴지지만,이 경우에는 수업을 구현하는 데 어려움을 겪고 있습니다. 필자가 작성한 코드를 업로드하고 싶습니다. 주로 "팀"클래스와 "플레이어"클래스 구현에 대한 코드에 몇 가지 구체적인 설명이 있습니다.Fantasy Football - 구현 클래스 문제

감사합니다. 또한 올바르게 업로드하지 않은 경우 알려 주시기 바랍니다.

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

답변

0

이 잘되지 않습니다 :

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

나는 당신이 뭘 하려는지 모르겠어요.

team은 클래스이지만 배열로 참조합니다. 당신의 의도는 무엇입니까?

목록을 구현하는 것이 숙제가 아니라면 자체 링크 된 목록을 롤링하는 대신 표준 컨테이너 (벡터, 큐 등)를 사용하는 것이 좋습니다.

글로벌 변수의 버릇을 버리십시오.

system("pause");가 손실됩니다. system("pause"); - Why is it wrong?

+0

글쎄 거기서 나는 i = NumberofTeamsDrafting; i <5; i ++ - 초안을 작성하는 팀은 4 명이 될 것이기 때문에 어떻게 말할 수 있을지 모르겠습니다. – Mike

+0

@Mike : 팀 수를 계산해야합니다. 'i'를 0으로 초기화하고 그 숫자까지 세어보세요. 아마도'team '이 채워지는 한도를 적용하기를 원할 것입니다. –

+0

좋아요. 이제 팀과 함께하려고하는 것은 첫 번째 제도자인 Mike 's Team에 대해 말하고 있습니다. 그러면 그는 선수를 초안하여 팀에 보냅니다. 기본적으로 Mike의 팀은 다음과 같이 선택합니다. "player" , 마이크의 팀에 플레이어를 삽입하십시오. 다음은 이것이 최종 프로젝트에 대한 제 생각입니다. 표준이 주어지지 않았기 때문에 가장 쉬운 것은 무엇이든 사용할 수 있습니다.하지만 분명히 나는 ​​가장 숙련 된 프로그래머가 아닙니다. 전역 변수에 관해서는 혼란 스럽습니다. 지금까지 도움을 주셔서 감사합니다. – Mike