私は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;
}
}
getPlayerInfo()
あなたの教授が教えてくれたはずのリャクチュアを聞いたことがありますか?あなたがそうしなかったように見えるので、今ではC++の本を読む必要があります。 – SergeyA
@ SergeyAおそらく、あなたはそれらの教授を過大評価するでしょう。それとも、それは私だけの悪い経験をすべて持っている... – DeiDei