Coursework 1

IN3013/INM173 - Object-Oriented Programming in C++

This coursework simulates a simple database operation, and provides practice with strings, streams, vectors and user-defined classes. It is due on Wednesday 12th February, and counts for 8% of the module.

Consider a simple textual table describing the catalogues of retail stores, with a line for each product offered by a store, like

    Argos Barbie 6.99
    Argos PS2 159.99
    Hamleys Barbie 16.99
Each line consists of three words: a vendor code, a product code and the price of that product from that vendor (a floating point number). (You may assume that vendor and product codes do not contain spaces.) The records are not in any special order.

  1. Define a class to hold the catalogue record.

  2. Write a function to read a series of catalogue records from a file into a vector of catalogue objects. You will need to use the class ifstream, which is derived from istream, like so:
        #include <fstream>
        ...
            ifstream in("catalog");
            ... istream operations ...
    
    The constructor opens the file; you can then test in to see whether it succeeded.

  3. Write a main program that reads from standard input a series of lines describing orders, like
        Barbie 200
        PS2 1
        Barbie 2
    
    where each line consists of two words: a product code (as in the catalogue file) and a requested quantity (a whole number). Again the lines are in no special order.

    For each input line, your program should produce on the standard output a line for each store stocking that product, combining the information from both records. For example, the above inputs might result in

        Barbie 200 Argos 6.99
        Barbie 200 Hamleys 16.99
        PS2 1 Argos 159.99
        Barbie 2 Argos 6.99
        Barbie 2 Hamleys 16.99
    
    If there are no store records for a particular vendor, there will be no output for that line.
Your submissions will be tested automatically, so please don't add any additional output.

You may divide the program between additional functions if you wish.

Pair working

If you wish, you may work on and submit this coursework in pairs. Undeclared pairs will be referred to the academic misconduct procedure - ``We worked together'' will not be an excuse.

A pair should submit a single solution, with both names on it. A pair submission will obtain approximately 95% of the marks that an identical single submission would have obtained, so pairs are expected to do slightly more work than singles:

but even if you don't do this, you can expect a good mark if you do the basic task successfully and neatly.

Individuals should not do this extra task.

Submitting as a pair (or a single) for this coursework does not commit you for the remaining courseworks.