CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2011
    Posts
    10

    Post Inventory system

    Hi there. This is my first hovering here in this site and I knew I could lean on the members here. I just wanna share this burden of mine (lol) and hope you could actually help me out. I needed to create a simple inventory system that could add product, add supplier, and do the main inventory process. Actually, the program should include file handling but I do not have a good background for it. I presumed I needed to post my unfinished codes here, so here it goes...

  2. #2
    Join Date
    Apr 2008
    Posts
    725

    Re: Inventory system

    yes, you should post your code and ask specific questions

  3. #3
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    Talking Re: Inventory system

    Quote Originally Posted by Amleto View Post
    yes, you should post your code and ask specific questions
    ---Ditto

    but sounds like stuff i used to do, and would be glad to help

  4. #4
    Join Date
    Mar 2011
    Posts
    10

    Re: Inventory system

    #include<iostream.h>
    #include<string.h>
    #include<iomanip>
    #include<fstream>
    #include<sstream>
    #include<dos.h>
    #include<conio.h>
    #include<stdio.h>
    #define max 20
    using namespace std;


    void proManagement();

    struct product
    {
    long int stockNo;
    char product[20];
    char supply[20];
    long int quantity;
    int dateArrived;
    };
    int num;
    product pro[max], temppro[max], sortpro[max], sortpro1[max];

    struct supplier
    {
    char supplier2[20];
    long int ctrlNo;
    char address[20];
    long int noProducts;
    };
    supplier sup[max], tempsup[max], sortsup[max], sortsup1[max];

    struct inven
    {
    int in;
    int out;
    };
    inven temp[max], temp2[max], sort[max], sort2[max];

    main ()
    {
    system("cls");

    void supManagement();
    void inventory();
    void listsup();
    void addsup();
    void delsup();
    void editpro();
    void editsup();
    void searchpro();
    void searchsup();
    void sortpro();
    void sortsup();
    void menu();
    void promenu();
    void supmenu();
    void exit();

    char option;

    menu();

    while ((option = cin.get())!='x')
    {
    switch(option)
    {
    case 'a':
    promenu();
    break;
    case 'b':
    supmenu();
    break;
    case 'c':
    inventory();
    break;

    default:
    getch();
    }
    }
    menu();
    }

    void exit()
    {
    getch();
    }

    void menu()
    {
    system("cls");

    cout << "SELECT COMMAND:\n";
    cout << "\ta. PRODUCT MANAGEMENT\n";
    cout << "\tb. SUPPLIER MANAGEMENT\n";
    cout << "\tc. INVENTORY\n\n";
    cout << "\tx. EXIT PROGRAM\n\n\n";

    cout << "ENTER SELECTION [a/b/c/d]: ";
    }

    void promenu()
    {
    system("cls");

    void addpro();
    void delpro();
    void listpro();
    char optionpro;

    proManagement();

    while ((optionpro = cin.get())!='x')
    {
    switch(optionpro)
    {
    case 'a':
    addpro();
    break;
    case 'b':
    delpro();
    break;
    case 'c':
    listpro();
    break;
    case 'd':
    main();
    break;
    default:
    getch();
    }
    }
    }

    void proManagement()
    {
    system("cls");

    cout << "SELECT COMMAND:\n";
    cout << "\ta. ADD PRODUCT\n";
    cout << "\tb. DELETE PRODUCT\n";
    cout << "\tc. LIST OF PRODUCTS\n";
    cout << "\td. BACK FROM PREVIOUS MENU...\n\n";
    cout << "\tx. EXIT PROGRAM\n\n\n";

    cout << "ENTER SELECTION [a/b/c/d/x]: ";
    }


    void listpro()
    {
    system("cls");

    /*cout << "**************************************************\n";
    cout << "*-OOO-OO---O--OO--O-O-OOO-OOO------O---O-OOO-OOO-*\n";
    cout << "*-O-O-O-O-O-O-O-O-O-O-O----O-------O---O-OO---O--*\n";
    cout << "*-OOO-OO--O-O-O-O-O-O-O----O-------O---O--OO--O--*\n";
    cout << "*-O---O-O--O--OO--OOO-OOO--O-------OOO-O-OOO--O--*\n";
    cout << "**************************************************\n\n\n";

    cout << "**********************************************************************************\n";
    cout << "* STOCK NO. PRODUCT QUANTITY SUPPLIER DATE ARRIVED *\n";
    cout << "**********************************************************************************\n";
    cout << "* * * * * *\n";

    for (int i=0; i <= num-1; i++)
    {
    cout<<setw(1) << "*";
    cout<<setw(8) <<pro[i].stockNo << setw(2) << "*";
    cout<<setw(20)<<pro[i].product << setw(2) << "*";
    cout<<setw(10)<<pro[i].quantity << setw(2) << "*";
    cout<<setw(20)<<pro[i].supply << setw(2) << "*";
    cout<<setw(13)<<pro[i].dateArrived << setw(2) << "*";
    cout<<endl;
    }
    cout << "* * * * * *\n";
    cout << "**********************************************************************************\n";

    cout << endl;*/
    string line;
    ifstream x ("products.txt");

    if (x.is_open())
    {
    while(!x.eof())
    {

    cout<<endl;
    getline(x,line);
    cout<<line<<endl;

    }
    x.close();
    }
    else
    cout<<"can't open file."<<endl;

    system("pause");
    promenu();
    }

    void addpro()
    {
    system("cls");


    int i=num;
    num+=1;
    ofstream fout;
    fout.open("products.txt",ios::app);

    cout << "Enter the following items: \n";
    cout << "\t Stock No.\t\t: ";
    cin >> pro[i].stockNo;
    cout << "\t Product\t\t: ";
    cin >> pro[i].product;
    cout << "\t Quantity\t\t: ";
    cin >> pro[i].quantity;
    cout << "\t Supplier\t\t: ";
    cin >> pro[i].supply;
    cout << "\t Date Arrived (mmddyy)\t: ";
    cin >> pro[i].dateArrived;
    cout << endl<<endl;

    fout << endl <<setw(1) << "*"
    <<setw(8) <<pro[i].stockNo << setw(2) << "*"
    <<setw(20)<<pro[i].product << setw(2) << "*"
    <<setw(10)<<pro[i].quantity << setw(2) << "*"
    <<setw(20)<<pro[i].supply << setw(2) << "*"
    <<setw(13)<<pro[i].dateArrived << setw(2) << "*" << endl
    <<"**********************************************************************************" << endl;

    fout.close();
    ;
    promenu();
    }

    void delpro()
    {
    system("cls");

    int code;
    int check;

    cout<<endl;
    cout<<"Enter Stock No.: ";
    cin>>code;
    int i;
    for(i=0;i<=num-1;i++)
    {
    if(pro[i].stockNo==code)
    {
    check=i;
    }
    }

    for(i=0;i<=num-1;i++)
    {
    if(i==check)
    {
    continue;
    }
    else
    {
    if(i>check)
    {
    temppro[i-1]=pro[i];
    }
    else
    {
    temppro[i]=pro[i];
    }
    }
    }
    num--;

    for(i=0;i<=num-1;i++)
    {
    pro[i]=temppro[i];
    }

    promenu();
    }

    void supmenu()
    {
    system("cls");

    void supManagement();
    void addsup();
    void delsup();
    void listsup();
    char optionsup;

    supManagement();

    while ((optionsup = cin.get())!='x')
    {
    switch(optionsup)
    {
    case 'a':
    addsup();
    break;
    case 'b':
    delsup();
    break;
    case 'c':
    listsup();
    break;

    default:
    getch();
    }
    }
    supManagement();
    }

    void supManagement()
    {
    system("cls");

    cout << "SELECT COMMAND:\n";
    cout << "\ta. ADD SUPPLIER\n";
    cout << "\tb. DELETE SUPPLIER\n";
    cout << "\tc. LIST OF SUPPLIER\n\n";
    cout << "\tx. EXIT PROGRAM\n\n\n";

    cout << "ENTER SELECTION [a/b/c/d]: ";}



    void listsup()
    {
    system("cls");

    /*cout << "*****************************************************\n";
    cout << "*-OOO-O-O-OOO-OOO-O---OOO-OOO-OO------O---O-OOO-OOO-*\n";
    cout << "*-O---O-O-O-O-O-O-O----O--OO--O-O-----O---O-OO---O--*\n";
    cout << "*--OO-O-O-OOO-OOO-O----O--O---OO------O---O--OO--O--*\n";
    cout << "*-OOO-OOO-O---O---OOO-OOO-OOO-O-O-----OOO-O-OOO--O--*\n";
    cout << "*****************************************************\n\n\n";

    cout << "**********************************************************************************\n";
    cout << "* CRTL NO. SUPPLIER ADDRESS NO. of PRODUCTS *\n";
    cout << "**********************************************************************************\n";
    cout << "* * * * *\n";

    for (int i=0; i <= num-1; i++)
    {
    cout<<setw(1) << "*";
    cout<<setw(8) <<sup[i].ctrlNo << setw(2) << "*";
    cout<<setw(20)<<sup[i].supplier2 << setw(2) << "*";
    cout<<setw(29)<<sup[i].address << setw(2) << "*";
    cout<<setw(16)<<sup[i].noProducts << setw(2) << "*";
    cout<<endl;
    }
    cout << "* * * * *\n";
    cout << "**********************************************************************************\n";

    cout << endl;*/
    string line;
    ifstream x ("supplier.txt");

    if (x.is_open())
    {
    while(!x.eof())
    {

    cout<<endl;
    getline(x,line);
    cout<<line<<endl;

    }
    x.close();
    }
    else
    cout<<"can't open file."<<endl;

    system("pause");
    supmenu();
    }

    void addsup()
    {
    system("cls");


    int i=num;
    num+=1;
    ofstream fout;
    fout.open("supplier.txt",ios::app);

    cout << "Enter the following items: \n";
    cout << "\t Ctrl No.\t: ";
    cin >> sup[i].ctrlNo;
    cout << "\t Supplier\t: ";
    cin >> sup[i].supplier2;
    cout << "\t Address\t: ";
    cin >> sup[i].address;
    cout << "\t No. of Products\t: ";
    cin >> sup[i].noProducts;
    cout << endl<<endl;

    fout << endl << setw(1) << "*"
    <<setw(8) <<sup[i].ctrlNo << setw(2) << "*"
    <<setw(20)<<sup[i].supplier2 << setw(2) << "*"
    <<setw(29)<<sup[i].address << setw(2) << "*"
    <<setw(16)<<sup[i].noProducts << setw(2) << "*"
    <<endl;
    fout.close();
    ;
    system("pause");
    supmenu();
    }

    void delsup()
    {
    system("cls");

    int code;
    int check;


    cout<<endl;
    cout<<"Enter Stock No.: ";
    cin>>code;
    int i;
    for(i=0;i<=num-1;i++)
    {
    if(sup[i].ctrlNo==code)
    {
    check=i;
    }
    }

    for(i=0;i<=num-1;i++)
    {
    if(i==check)
    {
    continue;
    }
    else
    {
    if(i>check)
    {
    tempsup[i-1]=sup[i];
    }
    else
    {
    tempsup[i]=sup[i];
    }
    }
    }
    num--;

    for(i=0;i<=num-1;i++)
    {
    sup[i]=tempsup[i];
    }

    supmenu();
    }

    void inventory()
    {
    system("cls");

    void addinven();
    void delinven();
    void showinven();
    void invenmenu();
    char optioninven;

    invenmenu();

    while ((optioninven = cin.get())!='x')
    {
    switch(optioninven)
    {
    case 'a':
    addinven();
    break;
    case 'b':
    delinven();
    break;
    case 'c':
    showinven();
    break;
    case 'd':
    main();
    break;
    default:
    exit();
    }
    invenmenu();
    }
    }

    void invenmenu()
    {
    system("cls");

    cout << "SELECT COMMAND:\n";
    cout << "\ta. ADD INVENTORY\n";
    cout << "\tb. DELETE INVENTORY\n";
    cout << "\tc. SHOW INVENTORY\n\n";
    cout << "\td. BACK TO PREVIOUS MENU...\n\n";
    cout << "\tx. EXIT PROGRAM\n\n\n";

    cout << "ENTER SELECTION [a/b/c/d]: ";
    }

    void addinven()
    {
    system("cls");
    int stockcode;
    int tempquantity;


    cout << "Enter Stock No. of the Product: ";
    cin >> stockcode;

    for(int i=0;i<=num-1;i++)
    {
    if(pro[i].stockNo==stockcode)
    {
    cout << "PRODUCT FOUND!\n\n";
    cout << pro[i].product << endl;
    cout << "Enter quantity to add: ";
    cin >> tempquantity;

    if (temp[i].in != '\0')
    {
    temp[i].in = temp[i].in + tempquantity;
    }
    else
    {
    temp[i].in = tempquantity;
    }
    pro[i].quantity = pro[i].quantity + tempquantity;
    }

    else
    {
    cout << "PRODUCT NOT FOUND!";
    inventory();
    }
    }
    }

    void delinven()
    {
    system("cls");
    int stockcode;
    int tempquantity;


    cout << "Enter Stock No. of the Product: ";
    cin >> stockcode;

    for(int i=0;i<=num-1;i++)
    {
    if(pro[i].stockNo==stockcode)
    {
    cout << "PRODUCT FOUND!\n\n";
    cout << pro[i].product << endl;
    cout << "Enter quantity to delete: ";
    cin >> tempquantity;

    if (temp[i].out != '\0')
    {
    temp[i].out = temp[i].out + tempquantity;
    }
    else
    {
    temp[i].out = tempquantity;
    }

    pro[i].quantity = pro[i].quantity - tempquantity;
    }

    else
    {
    cout << "PRODUCT NOT FOUND!";
    inventory();
    }
    }
    }

    void showinven()
    {
    system("cls");


    cout << "*********************************************************************\n";
    cout << "* STOCK NO. PRODUCT QUANTITY IN OUT *\n";
    cout << "*********************************************************************\n";
    cout << "* * * * * *\n";

    for (int i=0; i <= num-1; i++)
    {
    cout<<setw(1) << "*";
    cout<<setw(8) <<pro[i].stockNo << setw(2) << "*";
    cout<<setw(20)<<pro[i].product << setw(2) << "*";
    cout<<setw(10)<<pro[i].quantity << setw(2) << "*";
    cout<<setw(10)<<temp[i].in << setw(2) << "*";
    cout<<setw(10)<<temp[i].out << setw(2) << "*";
    cout<<endl;
    }
    cout << "* * * * * *\n";
    cout << "*********************************************************************\n";

    system("pause");
    }

  5. #5
    Join Date
    Mar 2011
    Posts
    10

    Re: Inventory system

    thanks guys.. sorry i've had not posted it right away. i had a difficult time on getting online because of my connection. anyways, there it is. actually, i've already copy-pasted some file handling codes somewhere, and fortunately it worked without a hassle. only i really do not understand it much especially this lines...
    if (x.is_open())
    {
    while(!x.eof())
    {

    cout<<endl;
    getline(x,line);
    cout<<line<<endl;

    }
    x.close();
    ...what does that !x.eof() do??? and x.is_open()???

    i know there is so much to work about here. i still needed to delete, edit, search, and sort the whole thing. i really appreciate your help guys...

  6. #6
    Join Date
    Mar 2011
    Posts
    10

    Re: Inventory system

    btw, how do i embed code boxes here?? what code/s would i need??

  7. #7
    Join Date
    Apr 2008
    Posts
    725

    Re: Inventory system

    [code] some code[/code] - If you could edit your big post with code tags that would help readability a lot.

    Code:
    if (x.is_open())
    {
      while(!x.eof())
      {
    
        cout<<endl;
        getline(x,line);
        cout<<line<<endl;
      }
      x.close();
    }
    is_open() checks that the stream x is successfully opened - e.g. it is possible to try to open an fstream on a non-existant file, in which case it can't be opened.

    eof() checks for end of file, but I think this isn't the best method for reading the correct amount from a stream. Better is
    Code:
    while (x >> variable)
    {
    }
    
    // or
    while (getline(x, variable))
    {
    }
    Last edited by Amleto; March 6th, 2011 at 05:40 AM.

  8. #8
    Join Date
    Mar 2011
    Posts
    10

    Re: Inventory system

    thanks man.. okay so i did follow ur codes. the first doesn't seem to function well.
    Code:
    while (x >> variable)
    {
    }
    it omits or ignores the first character in every line in the .txt file so i've tried the 2nd one.
    Code:
    // or
    while (getline(x, variable))
    {
    }
    now, everything is displayed. and it is easier to understand. thanks to you. actually, i really would need to know and understand these codes because we have a defense-like event in the finals. and you helped a lot. now i needed to delete things from the txt file and i do not have any idea to begin with. can i again lend a hand for this?

  9. #9
    Join Date
    Apr 2008
    Posts
    725

    Re: Inventory system

    The first version does something different:
    Code:
    string words = "one two three four";
    string temp1, temp2;
    stringstream str(words);
    str >> temp1; // temp1 = "one"
    str >> temp2; // temp2 = "two"
    So choose which one depending on what suits your needs.

    Do you need to delete the whole contents of the file? Or just some parts of it?
    Last edited by Amleto; March 6th, 2011 at 07:51 AM.

  10. #10
    Join Date
    Mar 2011
    Posts
    10

    Re: Inventory system

    no, just parts of it. as you see in my delpro/delsup functions i already made it to delete a certain product or supplier but i know it would be different as it behaves in file handling.
    Code:
    cout<<"Enter Stock No.: ";
    cin>>code;
    int i;
    for(i=0;i<=num-1;i++)
    {
    if(pro[i].stockNo==code)
    {
    check=i;
    }
    }
    
    for(i=0;i<=num-1;i++)
    {
    if(i==check)
    {
    continue;
    }
    else
    {
    if(i>check)
    {
    temppro[i-1]=pro[i];
    }
    else
    {
    temppro[i]=pro[i];
    }
    }
    }
    num--;
    
    for(i=0;i<=num-1;i++)
    {
    pro[i]=temppro[i];
    }
    as for example. you would have to input the stock No/ctrl No of the item, and the whole array will be deleted.

  11. #11
    Join Date
    Apr 2008
    Posts
    725

    Re: Inventory system

    it is probably best to keep the software model (data in memory) seperate from the file model (data on disk) - dont try and modify both too often or make one reliant on the other keeping up to date with each operation/transaction.

    design and implement saving & loading routines.

    Decide when it is sensible to modify the model on file. When you want to make any changes to the data on disk, just call the save routine (you might want to consider backing up data).
    Last edited by Amleto; March 6th, 2011 at 11:19 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured