Hi everyone,

I have a question about an inventory program that I need to do that reads data from a text file and does many different processes with it. Here is a description just so you know what is going on in the program:

Write a C++ program that will manage an inventory of a sports store. The program should be able to handle the fields - the product id, the product description, the manufacturer, the unit cost, the quantity in stock and the reorder level. You must use a C++ class to store the information and the data must be stored in private data members. Create accessor and mutator methods for each of the data members and a function to change the quantity in stock. The class must also contain a constructor function that will accept 6 parameters. The program can hold up to 100 records but no more than that.

The program must provide the user with a menu that allows the user to do the following operations:

* List the current inventory (sorted by product description).
* List the current inventory (sorted by product id).
* Add items to the stock of a product.
* Remove items from the stock of a product.
* Add a new product to the inventory.
* Remove a product from the inventory
* Calculate the total value of the inventory.
* List those products needing to be reordered.
* Quit.

I'm doing the first section right now and my question is for reading in a file which is what I need to do to list the inventory on the screen, sorted by product description. Here is my code that I currently have just for that first section (first menu option):

Code:
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <iomanip>

class Inventory {

   private:
      int ProdID, qty_stock, reord_lev;
      string ProdDesc, manu;
      float unitcost;
      
   public:
      Inventory(int, string, string, float, int, int);
      void listcurinv_1();
      void listcurinv_2();
      void add_stock();
      void rmv_stock();
      void add_prod();
      void rmv_prod();
      void calc_inv();
      void list_reord();
};

Inventory::Inventory(int id, string desc, string manufac, float cost, int qty, int r_level) {          // constructor
   ProdID = id;
   ProdDesc = desc;
   manu = manufac;
   unitcost = cost;
   qty_stock = qty;
   reord_lev = r_level;
}


void Inventory::listcurinv_1() {

   // read records from data file
   int i = 0;
   ifstream infile("a:\\CO856 Assignment 1\\sportsstore.txt");
   while (!infile.eof() || i < 100) {
      infile.getline(Product[i].ProdID, 10, ',');
      infile.getline(Product[i].ProdDesc, 30, ',');
      infile.getline(Product[i].manu, 15, ',');
      infile.getline(Product[i].unitcost, 10, ',');
      infile.getline(Product[i].qty_stock, 5, ',');
      infile.getline(Product[i].reord_lev, 5, '\n');
      i++;
   }
    
   // sorting by product description
   string spare;
   for (int j = 0; j < i-1; j++) {
      for (int k = 0; k < i; k++) {
         if (Product[j].ProdDesc > Product[k].ProdDesc) {
            spare = Product[j].ProdDesc;
            Product[j].ProdDesc = Product[k].ProdDesc;
            Product[k].ProdDesc = spare;
         }
      }
   }

   // reset i record counter to 0
   i = 0;

   // display data from the file
   while (!infile.eof() || i < 100) {
      cout << setw(10) << Product[i].ProdID;
      cout << setw(30) << Product[i].ProdDesc;
      cout << setw(15) << Product[i].manu;
      cout << setw(10) << Product[i].unitcost;
      cout << setw(5) << Product[i].qty_stock;
      cout << setw(5) << Product[i].reord_lev << endl;
   }
}
I have every field in the data text file instantiated as a product of the inventory class (I think that is the correct terminology).

Anyway, is that the correct way of reading in a file and assigning data from it? I would also like to know the correct way to declare "Product" in the program? As of right now, I don't have it defined yet because I'm not sure of where and how to declare it in the program.

Also, can someone confirm whether that sorting routine by product description (ascending order) is correct?

If anyone has any help, advice or comments on this question of mine, that would be greatly appreciated.

Thanks.