您好,我对如何在不使用指针的情况下正确地通过具有结构的函数传递数组感到非常困惑。我们只应该使用不包含指针的第 1-8 章。如果有人有任何建议或链接可以帮助您,这是我的代码,谢谢!
const int MAX_DATA = 10000;
struct Inventory
{
double sku;
double count;
double cost;
string title;
};
void addMovie(Inventory data[], double count);
void allInfo(Inventory data[], double count);
int main ()
{
Inventory data[MAX_DATA];
int choice;
int i = 0;
double count = 0;
return 0;
}
void addMovie(Inventory data[], double count)
{
int i = 0;
cout << "Please enter the name of the movie you wish to add " << endl;
cin >> data[i].title;
cin.ignore();
cout << "Please enter the SKU " << endl;
cin >> data[i].sku;
cout << "You have successfully added " << data[i].title << " : " << data[i].sku << endl;
i++;
count++;
}
void allInfo(Inventory all[], double count)
{
for (int i = 0; i < count; i++)
{
cout << "Title: " << all[i].title << endl;
cout << "SKU: " << all[i].sku << endl;
i++;
}
}