Assignment 4
Version 1.0


Order Processor with Special Instructions



In your fourth assignment, you upgrade your Order processor to include special instructions. 


Learning Outcome

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

  1. derive one class from another class
  2. identify the most derived version of a member function in an inheritance hierarchy
  3. base a class hierarchy on an abstract base class
  4. implement dynamic memory allocation in a derived class

Specifications

In upgrading your order processor to include special instructions, you can make full use of your Order class.  You only need to add code that specializes your class for user instructions.

SpecialOrder Class

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

Class Definition

Derive a class named SpecialOrder from your Order class.  Initially, you may assume that any instruction entered by the user will contain no more than 60 characters. 

Member Functions

Your SpecialOrder class includes the following member functions:

  • A no-argument constructor that creates a SpecialOrder object in a safe empty state
     SpecialOrder();
    
  • A two-argument constructor that receives a reference to an EAN object and the address of a C-style null-terminated string containing the special instructions and creates a SpecialOrder object
     SpecialOrder(const EAN& isbn, const char* instr);
    
  • A modifier that receives a reference to an istream object and adds the quantity ordered and special instructions to the current object 
     bool add(std::istream& is);
    

    This function accepts from the input stream the increase in the quantity ordered and the instructions to be included with the order.  If the input is acceptable, this function updates the order, replaces any instructions with the newly entered instructions and returns true.  If the input is unacceptable or the user quits for any reason, this function leaves the original order unchanged and returns false

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

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

    • the order's 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
    • the special instruction

    For example,

     978-0-00-319487-6       25         15  10% Discount
    

Design each function so that it yields reasonable results even if it receives invalid data through any of its parameters.

iOrder Interface

Create an interface named iOrder that identifies the following functions as member functions that must be implemented by any concrete class in this hierarchy. 

  • EAN* getEAN()
  • bool add(int)
  • bool add(std::istream&)
  • bool receive(std::istream&)
  • int outstanding() const
  • void display(std::ostream&) const

Derive your Order class from this interface. 

Store your interface definition in the header file named Order.h

Order Class

Class Definition

Derive your Order class from this interface. 

Add an empty destructor to your Order class with the keyword virtual

Helper Definition

Change the type of the right operand for the insertion operator from Order to iOrder.

SpecialOrder with a Resource

This function accepts a string of any length.  For this upgrade, you will need to allocate memory dynamically. 

Add to your SpecialOrder class the following member functions:

  • a copy constructor that receives a reference to a SpecialObject object
     SpecialOrder(const SpecialOrder& source);
    

    This function constructs an identical copy of the source object and allocates separate memory for the special instruction. 

  • an assignment operator that receives a reference to an unmodifable SpecialOrder object and copies the information from the source object into the current object
     SpecialOrder& operator=(const SpecialOrder& source);
    
  • a destructor that deallocates memory before the current object goes out of scope 
     ~SpecialOrder();
    

Main Module

The client module posted here (a4main.cpp) displays a menu, accepts a task, and completes that task. 

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

 g++ a4main.cpp EANPrefix.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
  S - Place a special 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) : 25

 Please select from the following options :
  P - Place an order with a publisher
  S - Place a special 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 : s

 EAN (0 to quit) : 9789070002046
 Quantity (0 to quit) : 1
 Instructions : 10% Discount

 Please select from the following options :
  P - Place an order with a publisher
  S - Place a special 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
  S - Place a special 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) : 9789070002046
 Quantity (0 to quit) : 2
 2 not on order.  Only 1 is on order.  Try again.
 Quantity (0 to quit) : 1

 Please select from the following options :
  P - Place an order with a publisher
  S - Place a special 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  Instructions
 ---------------------------------------------------
 978-0-00-319487-6       25         20
 978-90-70002-04-3        1          1  10% Discount

 Please select from the following options :
  P - Place an order with a publisher
  S - Place a special 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 testing. 


Submission

A file containing functions to test your classes is posted here.  Copy this file to your assignment directory, re-compile your class 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 a4.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++ a4test.cpp GS1Prefix.cpp EAN.cpp Order.cpp
 + At the prompt, type: a.out
 + At the prompt, type: cat a4main.cpp
 + At the prompt, type: g++ a4main.cpp GS1Prefix.cpp EAN.cpp Order.cpp
 + At the prompt, type: a.out
 + At each input prompt, enter the data for the sample run.
 + At the prompt type: exit

These commands will produce a file named a4.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