Assignment 3
Version 1.0


Bookstore Order Processor



In your third assignment, you create a new class that includes an object of another class as one of its data members. 


Learning Outcomes

Upon successful completion of this assignment, you will have demonstrated the abilities to

  • code a composition relationship between two classes
  • overload an operator as a helper function of a class

Specifications

In this assignment you update the EAN module and create the Order module. 

EAN Class

Add the following helper functions to your definition of the EAN class:

  • An overloaded operator that receives references to two unmodifiable EAN objects and compares the objects for equality
     bool operator==(const EAN& left, const EAN& right);
    

    This operator returns true if both objects hold the same EAN string; false otherwise.  The objects need not hold the same style for this comparison to succeed. 

  • An overloaded operator that receives a reference to an ostream object and a reference to an unmodifiable EAN object.  This operator inserts the object into output stream os 
     std::ostream& operator<<(std::ostream& os, const EAN& ean);
    

    This operator displays the EAN in the form created by the display() member function.

Add your prototypes to the header file named EAN.h and your function definitions to the implementation file named EAN.cpp.

Order Class

Store your class definition in a header file named Order.h and your function definitions in an implementation file named Order.cpp.

Class Definition

Your Order class defines the structure of an order for a single book.  The order refers to one specific edition; that is, to one EAN.  Survey the member functions listed below to determine the data members in your design.

Member Functions

Your design includes the following member functions:

  • A no-argument constructor that creates an Order object in a safe empty state
     Order();
    
  • A one-argument constructor that receives a reference to an EAN object and creates an Order object for that EAN
     Order(const EAN& ean);
    

    This function initializes the object to no copies ordered and none delivered. 

  • A modifier that returns a reference to the current object's EAN
     EAN& getEAN();
    
  • A query that returns the number of copies remaining on order
     int outstanding() const;
    
  • A modifier that receives a reference to an istream object and increases the number of copies ordered by the quantity received from input stream is
     bool add(std::istream& is);
    

    This function accepts from the input stream the number of copies to be added and adds that number to the number of copies already on order.  This number to be added must be positive-valued.  If the input is valid, this function updates the current object and returns true.  If the user quits for any reason, this function does not change the current object in any way and returns false

  • A modifier that receives the number of copies to be added to the current order
     bool add(int n);
    

    This function updates the order if n is positive-valued and the object is not empty.  This function returns true on success (n is positive-valued and the object is not empty); false otherwise. 

  • A modifier that receives a reference to an istream object and records the receipt of copies from the publisher as entered in the input stream is
     bool receive(std::istream& is);
    

    The number of copies received must be positive-valued, but not greater than the number still on order, in which case, this function updates the current object and returns true.  If the user quits for any reason, this function leaves the current object unchanged, as if there had been no delivery and returns false

  • A query that receives a reference to an ostream object and displays the current object on output stream os
     void display(std::ostream& os) const;
    

    This function displays the following information on a single line in the following format:

    • the EAN right-justified in a field of 17
    • the number of copies ordered in a field of 9
    • the number of copies delivered in a field of 11

    For example,

     978-0-00-319487-6       25         15
    

Design each function so that it yields a reasonable result even if the function receives an invalid value for any of its parameters. 

Helper Function

Your design includes the following helper function:

  • An overloaded operator that receives a reference to an ostream object and a reference to an unmodifiable Order object.  This function and inserts the object's information into output stream os 
     std::ostream& operator<<(std::ostream& os, const Order& order);
    

    This operator displays the object's information in the form created by its display() function.

Main Module

The client program posted here accepts up to 100 orders.  It displays a menu, accepts the user's selection, and completes the selected task. 

The options include:

  • Place an order with a publisher
  • Add one copy to an existing order
  • Record a delivery from a publisher
  • Change the output style
  • View status of books on order
  • Quit

Sample Run

To compile the client program with your three modules on Linux, use the following command:

 g++ a3main.cpp Prefix.cpp EAN.cpp Order.cpp

The output from a sample run might look something like:

 Bookstore Order Processor
 =========================

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : P

 EAN (0 to quit) : 9789070002046
 Quantity (0 to quit) : 25

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : p

 EAN (0 to quit) : 9780003194876
 Quantity (0 to quit) : 30

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : r
  Invalid input.  Try again.
  Your selection : d

 EAN (0 to quit) : 9789070002046
 Quantity (0 to quit) : 10

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : d

 EAN (0 to quit) : 9780003194875
 Invalid check digit. Try again.
 EAN (0 to quit) : 9780003194876
 Quantity (0 to quit) : -20
 Enter a positive number.  Try again.
 Quantity (0 to quit) : 0
 **No delivery recorded!

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : v

               EAN  Ordered  Delivered
 -------------------------------------
 978-90-70002-04-6       25         10
 978-0-00-319487-6       30          0

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : d

 EAN (0 to quit) : 9780003194876
 Quantity (0 to quit) : 20

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : p

 EAN (0 to quit) : 9789995500009
 Quantity (0 to quit) : 20

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : v

               EAN  Ordered  Delivered
 -------------------------------------
 978-90-70002-04-6       25         10
 978-0-00-319487-6       30         20
     9789995500009       20          0

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : a

 EAN (0 to quit) : 9780003194876

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : d

 EAN (0 to quit) : 9789995500009
 Quantity (0 to quit) : 25
 25 not on order.  Only 20 are on order.  Try again.
 Quantity (0 to quit) : 20

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : v

               EAN  Ordered  Delivered
 -------------------------------------
 978-90-70002-04-6       25         10
 978-0-00-319487-6       31         20
     9789995500009       20         20

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : f

 EAN Style ('-', ' ', '\n' or '0' to quit) :    // enter single blank space

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : v

               EAN  Ordered  Delivered
 -------------------------------------
 978 90 70002 04 6       25         10
 978 0 00 319487 6       31         20
     9789995500009       20         20

 Please select from the following options :
  P - Place an order with a publisher
  A - Add one copy to an existing order
  D - Record a delivery from a publisher
  F - Change output style
  V - View status of books on order
  Q - Quit
  Your selection : q


 Signing off ...

Once your program yields the results shown above, it is ready for final testing. 


Submission

A file containing functions to test your classes is posted here.  Copy this file to your assignment directory, re-compile your modules with this file and run the executable.

Once the executable indicates that you may submit your program, create a typescript using the following commands:

 + At the prompt, type: script a3.txt
 + At the prompt, type: whoami
 + At the prompt, type: cat GS1Prefix.h
 + At the prompt, type: cat GS1Prefix.cpp
 + At the prompt, type: cat EAN.h
 + At the prompt, type: cat EAN.cpp
 + At the prompt, type: cat Order.h
 + At the prompt, type: cat Order.cpp
 + At the prompt, type: g++ a3test.cpp GS1Prefix.cpp EAN.cpp Order.cpp
 + At the prompt, type: a.out
 + At the prompt, type: cat a3main.cpp
 + At the prompt, type: g++ a3main.cpp GS1Prefix.cpp EAN.cpp Order.cpp
 + At the prompt, type: a.out
 + At each input prompt, enter the data for the sample run shown above.
 + At the prompt type: exit

These commands will produce a file named a3.txt.  Submit this file according to your professor's instructions along with any other information your professor has requested.

Assignments that are submitted after the due date will attract a 10% late penalty per school day to a maximum deduction of 50%.

If you submit an assignment that does not pass all of the tests, you will be asked to fix your code and to resubmit, in which case you will receive an assignment mark no higher than 50% of the mark allocated for this assignment.

Regardless of how long it takes you to complete this assignment, you will need to submit a completed version in order to pass this course.







  Designed by Chris Szalwinski   Copying From This Site   
Logo
Creative Commons License