C++에서 완료해야하는 과제와 관련하여 빠른 질문이 있습니다. 선생님은 내가 다음과 같은 기능을 포함 할 것을 요구했습니다포인터를 사용하지 않고 C++에서 배열을 참조로 전달하지 않습니다.
void getPlayerInfo(Player &);
void showInfo(Player);
int getTotalPoints(Player [], int);
하지만 첫 번째 함수 작업하는 데 문제가 .... 나는 구조의 배열을 올바르게 전화 드렸습니다 있는지 확실하지 않습니다. 누군가가 그것을 살펴보고 제가 잘못하고있는 것을 볼 수 있습니까? 나는 그것을 조금만 들여다 보았고 배열을 호출하고 배열에 대한 포인터를 전달할 수 있지만 선생님은 "&"기호가 있어야하므로 내가 알지 못하는 다른 방법이 있어야합니다. 도와주세요! 감사합니다
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Structure to hold information about a player
struct Player
{
string name; // to hold the players name
int number; // to hold players number
int points; // to hold the points scored by the player
};
// Function prototypes
void getPlayerInfo(Player &); // function to get the players information from the user
void showInfo(Player); // function to show the table
int main()
{
const int numPlayers = 12; // Constant to hold the number of players
Player team[numPlayers]; // array to hold 12 structures
// Gather information about all 12 players
getPlayerInfo(team);
showInfo(team);
return 0;
}
// Function to get the players info
void getPlayerInfo(Player& team)
{
for (int count = 0; count < 12; count++)
{
cout << "PLAYER #" << (count + 1) << endl;
cout << "----------" << endl;
cout << "Player name: ";
cin.ignore();
getline(cin, team[count].name);
cout << "Player's number: ";
cin >> team[count].number;
cout << "Points scored: ";
cin >> team[count].points;
cout << endl;
}
}
교수님이 가르쳐 주셨어야 할 교훈을 들어 보셨습니까? 보지 않았던 것처럼 보입니다. 이제는 C++에 대한 책을 읽어야합니다. – SergeyA
@ SergeyA 아마도 교수님을 과대 평가했을 것입니다. 아니면 모든 나쁜 경험을 가진 나 일 뿐이에요 ... – DeiDei