将数组作为c+中的引用传递+;不使用指针 关于一个我必须完成的任务C++,我有一个很快的问题。老师要求我包括以下功能: void getPlayerInfo(Player &); void showInfo(Player); int getTotalPoints(Player [], int);

将数组作为c+中的引用传递+;不使用指针 关于一个我必须完成的任务C++,我有一个很快的问题。老师要求我包括以下功能: void getPlayerInfo(Player &); void showInfo(Player); int getTotalPoints(Player [], int);,c++,arrays,C++,Arrays,但是我在处理第一个函数时遇到了问题……我不确定是否正确调用了结构数组。有人能看看我做错了什么吗?我稍微摆弄了一下它,我能够调用数组并传递一个指向数组的指针,但是老师要求有“&”符号,所以一定有另一个我不知道的方法。请帮忙!谢谢 #include <iostream> #include <iomanip> #include <string> using namespace std; // Structure to hold information about

但是我在处理第一个函数时遇到了问题……我不确定是否正确调用了结构数组。有人能看看我做错了什么吗?我稍微摆弄了一下它,我能够调用数组并传递一个指向数组的指针,但是老师要求有“&”符号,所以一定有另一个我不知道的方法。请帮忙!谢谢

#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;
}
#包括
#包括
#包括
使用名称空间std;
//结构来保存有关玩家的信息
结构播放器
{
string name;//保存玩家名称
int number;//保存玩家编号
int points;//保留玩家的得分
};
//功能原型
无效getPlayerInfo(播放器&);//函数从用户处获取玩家信息
无效显示信息(玩家);//函数来显示表格
int main()
{
const int numPlayers=12;//用于保存玩家数量的常量
玩家团队[numPlayers];//阵列可容纳12个结构
//收集所有12名玩家的信息
getPlayerInfo(团队);
showInfo(团队);
返回0;
}
//函数获取玩家信息
无效getPlayerInfo(球员和球队)
{
对于(int count=0;count<12;count++)
{
cout
getPlayerInfo()
不接受数组,它接受对单个
Player
对象的引用

您需要为数组中的每个播放器调用
getPlayerInfo()
。将循环从
getPlayerInfo()
移动到
main()

getPlayerInfo()
不接受数组,它接受对单个
播放器的引用


您需要为阵列中的每个播放机调用
getPlayerInfo()
。将循环从
getPlayerInfo()
移动到
main()

您误解了这些函数的意图

根据您提供的信息猜测,
getPlayerInfo
用于获取单个玩家的信息,
showPlayerInfo
用于显示单个玩家的信息

您正试图使用这些函数来做一些它们不打算做的事情,因此您在弄清楚如何调用和如何实现它们时遇到困难,这是一件好事


将此经验视为需求收集中的对象课程。

您误解了这些功能的意图

根据您提供的信息猜测,
getPlayerInfo
用于获取单个玩家的信息,
showPlayerInfo
用于显示单个玩家的信息

您正试图使用这些函数来做一些它们不打算做的事情,因此您在弄清楚如何调用和如何实现它们时遇到困难,这是一件好事


把这段经历当作是需求收集的一个对象课。

你是否听过你的教授应该给你的学位?看起来你没有,所以现在你需要读一本C++的书。@ SergeyA,也许你高估了他们的教授。或者可能是我带着所有的坏经历…你听了吗?你的教授应该给你?看来你没有,所以现在你需要读一本关于C++的书。@ SergeyA,也许你高估了他们的教授。或者可能是我,所有的坏经历…