我正在为我的决赛项目制作一个数据库清单程序。我真的是C ++的新手,到目前为止,这是我的代码:
#include <iostream>
#include <fstream>
#include <string>
#define ss 30
using namespace std;
struct store
{
char brand[30];
char name[30];
char pc[30];
int x;
float price;
}s[ss];
void AddNewItem(int &num)
{
cout<<"\n \t\t\t NEW DATA FOR AN ITEM\n\n\n";
cout<<"Product Code: ";
cin>>s[num].pc;
cout<<endl;
cout<<"Company Name: ";
cin>>s[num].brand;
cout<<endl;
cout<<"Product Name: ";
cin>>s[num].name;
cout<<endl;
cout<<"Product Price ";
cin>>s[num].price;
cout<<endl;
cout<<"Quantity: ";
cin>>s[num].x;
num++;
cout<<endl;
}
void ShowInventoryList(int &num)
{
if (num==0)
{
cout<<"\nThere are no items in the record right now. Please add record.\n\n";
}
else{
cout<<"\n \t\t\t LIST OF ALL ITEMS"<<endl;
cout<<"Product Code \t Company Name \t Product Name \t Product Price \t Quantity'\t" <<endl;
for(int i=0;i<num;i++)
{
cout<<s[i].pc <<"\t\t"
<<s[i].brand <<"\t\t"
<<s[i].name <<"\t\t"
<<s[i].price <<"\t\t"
<<s[i].x <<"\t\t"
<<endl
<<endl;
}
}
}
int main()
{
ifstream openFile("Inventory.txt");
string line;
int menu,number=0;
do
{
cout<<"\n==================== MENU ====================";
cout<<"\n ";
cout<<"\n 1. Add New Item ";
cout<<"\n 2. Show Inventory List ";
cout<<"\n 3. Search An item From Record ";
cout<<"\n 4. Reduce The Quantity of An Item; ";
cout<<"\n 5. Save Item Stock to Text File ";
cout<<"\n 6. Show Item Stock from Text File ";
cout<<"\n 7. Exit ";
cout<<"\n ";
cout<<"\n=================================================="<<endl;
cout<<"\nEnter your choice: ";
cin>>menu;
switch(menu)
{
case 1:{AddNewItem(number);
break;}
case 2:{ShowInventoryList(number);
break;}
}
}
while(menu!=7);
cout<<"\nThank you for using our program. Have a good day!";
}
我将物料的数量设为int的原因是,我计划仅询问用户他们要从物料中减少的数量,并从物料的原始数量中减去该数量。我被困在这里,我将非常感谢您的帮助!