該程序從10個倉位中選擇具有相同數量零件的任何倉。當程序選擇一個時,它會詢問我們是要添加還是刪除特定倉中的零件。我如何從結構數組中獲取元素。
//結構 結構庫存 {獲取結構數組中的元素
char description[35];
int num;
};
//Function Prototypes.
void choiceMenu(Inventory[], int);
void AddParts(Inventory[], int);
void RemoveParts(Inventory[]);
int main()
{
char election;
int choice;
const int Number_Bins = 10;
Inventory parts[Number_Bins] = {
{"Valve", 10},
{"Bearing", 5},
{"Bushing", 15},
{"Coupling", 21},
{"Flange", 7},
{"Gear", 5},
{"Gear Housing", 5},
{"Vacuum Gripper", 25},
{"Cable", 18},
{"Rod", 12}
};
是否有其他辦法做到這一點不把從0數組的元素到9喜歡嘗試用蓄電池做。我如何從數組中獲取特定的元素。
void choiceMenu(Inventory bin[], int z)
{
cout << " Inventoy Bins\n";
cout << " = = = = = = = = \n";
cout << " *Choose the part of your preference.\n";
cout << " 1. Valve" << bin[0].num << endl;
cout << " 2. Bearing. Currently Number of Bearing = " << bin[1].num << endl;
cout << " 3. Bushing. Currently Number of Bushing = " << bin[2].num << endl;
cout << " 4. Coupling. Currently Number of Coupling = " << bin[3].num << endl;
cout << " 5. Flange. Currently Number of Flange = " << bin[4].num << endl;
cout << " 6. Gear. Currently Number of Gear = " << bin[5].num << endl;
cout << " 7. Gear_Housing" << bin[6].num << endl;
cout << " 8. Vacuum_Gripper" << bin[7].num << endl;
cout << " 9. Cable. Currently Number of Cable = " << bin[8].num << endl;
cout << " 10. Rod. Currently Number of Rod = " << bin[9].num << endl;
cout << " 11. Choose 11 to quit the Program" << endl;
}
'爲(INT I = 0; I
這將使所有的箱子改變它們中所有部件的數量。 – user3019164
我不明白你的問題,所以我猜。 –