Question: CPSC-131 Project 3: Universal Product Code (UPC) Catalog This project is different from the previous two. In project 1, you were not allowed to use

CPSC-131 Project 3: Universal Product Code (UPC) Catalog

This project is different from the previous two. In project 1, you were not allowed to use the C++ Standard Library (SL); in project 2, you were allowed but not required to use the SL. In this project, you are required to use the SL map, std::map, to apply this binary search tree to a real problem.

The project files provide one class, Catalog, with member functions that you must complete and which is expected to include the map.

Universal Product Code (UPC)

A Universal Product Code (UPC) has four parts but this project deals with only two of them: category number and product number. Categories are groups of related products, such as books or toys. They have numbers, which must be unique, and names, which dont have to be unique but usually are. Each product in a category also has a number and a name. Product numbers must be unique within a category but may be reused in separate categories. Product names, like category names, dont have to be unique.

Application

The project requires the design and implementation of an application program that creates an catalog of UPCs for a store and provides access to that catalog. The catalog is loaded from a text file that contains Category and Product records. Here is a sample:

Category 78292 Books (Hard-cover)

5931 Gone With The Wind

15897 To Kill a Mockingbird

232 The Adventures of Tom Sawyer

Category 78162 Toys

9577 Sleepytime Gal Barbie Collector Doll

23890 Tonka Classic Mighty Dump Truck

573 Ambi Toys Chirpy Bird Whistle

Category 40506 Jewelry

48610 Ring

2389 Necklace

34901 Bracelet

Each category record has three fields: the Category tag, a number, and a name. They are separated by tab characters (in C++, the tab character is represented by \t); the format is Category-tab-number-tab-name.

Each product record has two fields: number and name. They are separated by tab characters; the format is number-tab-name.

Category and product names can have multiple words separated by spaces.

Category and product records may be in any order and may not be in a continuous sequence.

Classes and Functions

The program must have a Catalog class with the indicated functions:

AddCategory: Given a category number and name, add it to the catalog. It will have an empty product list. Return false if the category number already exists in the catalog, true otherwise.

AddProduct: Given a category number, a product number, and a product name, add the product to the catalog. Return false if the category number doesnt exist in the catalog or if the product number already exists within the category, true otherwise.

GetCategoryCount: Return the number of categories in the catalog.

GetProductCount: Given a category number, return the number of products in the category; return -1 if the category doesnt exist.

Load: Load the catalog from a file, given the files name. Return false if the catalog cant be loaded, either because the file doesnt exist or isnt in the correct format.

ShowAll: Show the entire catalog, category by category, in order by category number. Under each category, show its products in order by product number. Use the same format as the text file in Load.

ShowCategory: Given a category number, show only its products in order by product number. Return false if the category number doesnt exist in the catalog. Use the same format as the text file in Load.

ShowProduct: Given a category number and a product number, show the product number and name separated by a tab. Return false if the category number doesnt exist in the catalog or if the product number doesnt exist within the category.

The output format of the three Show... functions should be the same as the input file format. These functions are designed so that their caller specifies an output stream, which may be cout, a file, or a stringstream. The prolog comments for each function explains more about output streams.

Implementation

You are to use the Standard Library (SL) map class (std::map) to hold catalog information. You will find it necessary to use some SL container within the map to hold product information.

Remember that the nodes of a tree, which is the structure that the SL map implements, are key/value pairs. The maps insert function takes a key and an associated data element, which can be anything, including a class or structure. The class or structure can have anything as a member, including any SL containereven another map.

Resources

Program Files

These files will be posted on GitHub for you to download, use or modify, and submit:

Catalog.h: contains declarations of the Catalog class. You may add other declarations as needed for your implementation. Do not add definitions (code) to this file; definitions of functions belong in catalog.cpp. [TO BE COMPLETED]

Catalog.cpp: contains skeletons for the required member functions. You may add other functions, member and nonmember, as needed for your implementation. [TO BE COMPLETED]

Main.cpp: contains a set of test functions that will call Catalogs functions. You may modify this file for your own test purposes but use the original file to run your final test before you submit your project.

These files are used by main.cpp to read test files. You should not change these files function but you may use its functions in your code if you wish.

GetLine.cpp and GetLine.h: contain a function similar to the Standard Librarys getline(stream, string) function. This version handles the variety of line breaks that can appear in text files, depending on the application that created them.

Test Files

Two test files will be posted on GitHub for you to download: SmallCatalog.txt and LargeCatalog.txt. They contain lists of categories and products. SmallCatalog.txts list is the same as the one shown above in the Application section; LargeCatalog.txt contains over a dozen categories and hundreds of products. Your final submittal will be tested using different files.

References

Two files will be posted on Titanium for your use:

map.pdf, which describe SL classes of interest. It contains a brief description of the relevant map functionsinsert, find, eraseincluding how to insert a key/value pair.

stringparsing.pptx, which shows how to parse the fields of a string to extract them one at a time. It describes how to find the beginning and end of fields that are separated by characters such as tabs, and how to copy each field substring into another string.

A more extension description of the SL map class and its functions can be found at http://www.cplusplus.com/reference/map/map/.

To convert strings to numbers, you can use std::stoi()

To split an input stream using a delimiter (such as the tab character), you can use std::getline()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!