Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

c++ - 如何在数据库程序中添加“减少项目数量”功能?(How can I possibly add a “reduce the quantity of an item” feature in my database program?)

I am making a database inventory program for my finals project.

(我正在为决赛项目制作数据库清单程序。)

I am really new to c++, here is my code so far:

(我真的是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<<"
    NEW DATA FOR AN ITEM


";
    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<<"
There are no items in the record right now. Please add record.

";
    }
    else{
        cout<<"
  LIST OF ALL ITEMS"<<endl;
        cout<<"Product Code  Company Name  Product Name  Product Price  Quantity'" <<endl;
        for(int i=0;i<num;i++)
        {
            cout<<s[i].pc <<""
            <<s[i].brand <<""
            <<s[i].name <<""
            <<s[i].price <<""
            <<s[i].x <<""
            <<endl
            <<endl;
        }
    }
}

int main()
{
    ifstream openFile("Inventory.txt");
    string line;
    int menu,number=0;
    do
    {
        cout<<"
====================   MENU   ====================";
        cout<<"
                                                ";
        cout<<"
            1. Add New Item                       ";
        cout<<"
            2. Show Inventory List                ";
        cout<<"
            3. Search An item From Record         ";
        cout<<"
            4. Reduce The Quantity of An Item;    ";
        cout<<"
            5. Save Item Stock to Text File       ";
        cout<<"
            6. Show Item Stock from Text File     ";
        cout<<"
            7. Exit                               ";
        cout<<"
                                                ";
        cout<<"
=================================================="<<endl;
        cout<<"
Enter your choice: ";
        cin>>menu;
        switch(menu)
        {
            case 1:{AddNewItem(number);
                break;}
            case 2:{ShowInventoryList(number);
                break;}

            }
        }
    while(menu!=7);
    cout<<"
Thank you for using our program. Have a good day!";
}

I made the quantity of the items as int because I plan to just ask the user the quantity amount they want to reduce from the item and just subtract it from the original quantity of an item.

(我将物料的数量设为int,因为我打算仅询问用户他们要从物料中减少的数量,并从物料的原始数量中减去该数量。)

I am stuck here and I would really appreciate the help!

(我被困在这里,我将非常感谢您的帮助!)

<3

(<3)

  ask by Spunky what are u doing dawg translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...