25 - LAB EXERCISE - STORE

 Background: This lab exercise will build a preliminary program to be used in Lesson 26 to study search algorithms.  We will use these nested structures to store and manipulate data stored in a text file, file50.txt.

struct item

{

      int id;

      int inv;

};

 

struct storeType

{

      apvector<item> list;

      int number;

};

 

The first line of file50.txt contains the number of id/inventory integer pairs listed on subsequent lines.  The idea behind the data type item is the simulation of an item in a store, nearly all of which use a bar code for identification purposes.  For every item in a store we keep track of an id value and an inventory amount.  So file50.txt looks like this:

 

50

3679       87

196        60

17914      12

18618      64

2370       65

etc. (for 45 more lines)

 

Each id value in file50.txt will be unique.

Assignment:

1.   Write a program which solves the following sequential events:

      loads the data file, file50.txt, into a data structure of type storeType

      sorts the data file using quickSort prints the data file, now in increasing order based on the id field      

 

2.   The printing should add a blank line after every 10 items in the output.  Include a line number in the output.  For example:

             Id       Inv

 

    1       196        60

    2       206        31

    3       584        85

    4       768        85

    5      2370        65

    6      3433         5

    7      3679        87

    8      4329        64

    9      5529        11

   10      6265        58

 

   11      6835        94

   12      6992        76

   13      7282        73

   14      8303        90

   15      9267        68

      etc.

3.   You are to overload the output operator (<<) for the item struct.

4.   Your program should use appropriate amounts of decomposition, as modeled in the ages.cpp program.

5.   Turn in your source code and a printout of sorted file50.txt as described under #2.