我正在尝试编写一个接受 3 个不同数组的函数。这些数组的类型分别是字符串、双精度和双精度。该函数将用数据填充这些数组,然后将它们返回给 main。但是,我不确定要声明什么作为函数的返回类型,因为所有数组都不包含相同的数据类型。下面列出了将接受数组作为参数的函数
void additems(string arry1[], double arry2[], double arry3[], int index)
{
/************************* additems **************************
NAME: additems
PURPOSE: Prompt user for airport id, elevation, runway length. Validate input and add to 3 seperate parallel arrays
CALLED BY: main
INPUT: airportID[], elevation[], runlength[], SIZE
OUTPUT: airporID[], elevation[], runlength[]
****************************************************************************/
//This function will prompt the user for airport id, elevation, and runway length and add them to
//separate parallel arrays
for (int i=0; i<index; i++)
{
cout << "Enter the airport code for airport " << i+1 << ". ";
cin >> arry1[i];
cout << "Enter the maximum elevation airport " << i+1 << " flys at (in ft). ";
cin >> arry2[i];
while (arry2[i] <= 0)
{
cout << "\t\t-----ERROR-----";
cout << "\n\t\tElevation must be greater than 0";
cout << "\n\t\tPlease re enter the max elevation (ft). ";
cin >> arry2[i];
}
cout << "Enter the longest runway at the airport " << i+1 << " (in ft). ";
cin >> arry3[i];
while (arry3[i] <= 0)
{
cout << "\t\t-----ERROR-----";
cout << "\n\t\tRunway length must be greater than 0";
cout << "\n\t\tPlease re enter the longest runway length (ft). ";
cin >> arry3[i];
}
cout << endl;
}
return arry1, arry2, arry3;
}
提前感谢您考虑我的问题