/*

  main program

  Componants: InventoryRecord.h, FuncList.h, InventoryRecord.cpp, FuncList.cpp, Try-1.cpp

 

  This is redesign / upgrade of Project-1 by adding/using STL, Exception handling, Write & Read

  to/from disk file.

 

  Author: Ahmad Mobasseri

*/

 

#include <iostream>

#include <fstream>

#include <string>

#include <vector>

#include "InventoryRecord.h"

#include "FuncList.h"

using namespace std;

 

void Menu         ();

 

int main()

{

      string Cmd;

      vector<InventoryRecord> List;

      FuncList FList;               // NOTE: by setting functions in a class, then can create several

                                    // object, and use them to access each func., as:

                                    // FuncList X, Y;  X.AddList(List); Y.RemoveList(List);

 

      while(true)

      { 

            Menu();

            cout<<"Enter command: ";

            getline(cin, Cmd);

            if(Cmd == "Stop")

                  break;

            else if(Cmd == "Add")                  // NOTE: following 'Add's, does NOT clear previous records

                  FList.AddList(List);              

            else if(Cmd == "Remove")

                  FList.RemoveList(List);

            else if(Cmd == "Find")

                  FList.FindList(List);

            else if(Cmd == "View")                // NOTE: if List (in_parm) omitted, it compiles but since no data

                  FList.ViewList(List);             // passed to ViewList func., then doesn't display anything

            else if(Cmd == "Write")

                  FList.WriteList(List);

            else if(Cmd == "Read")

                  FList.ReadList(List);

      }

} 

 

void Menu()

{

      cout<<"=========================="<<endl;

      cout<<"Enter one of the following commands"<<endl;

      cout<<"Add     to the list"<<endl;

      cout<<"Remove  from the list"<<endl;

      cout<<"Find    in the list"<<endl;

      cout<<"View    the list"<<endl;

      cout<<"Write   to the list"<<endl;

      cout<<"Read    Read from the list"<<endl;

      cout<<"Stop    to quit"<<endl;

      cout<<"=========================="<<endl;

}