Home

MissouriRiver.Com - An e-Commerce Prototype

 

Introduction

    The main objective of this page is to provide a project prototype designed and implemented to a fictitious MissouriRiver Corporation to controll its e-commerce in the Internet.

    The project uses object-oriented techniques according to UML – Unified Modeling Language, and Microsoft C++ as object-oriented programming language.

    I sincerely appreciate your comments, criticisms, corrections, and suggestions for improving this prototype. Please address all correspondence to the following e-mail address:

    [email protected]

The Purpose of the Project

The goal of this project is to design and implement a system to MissouriRiver.com control its e-commerce web site that sells books, videos and CDs. The system is designed and implemented to provide to the MissouriRiver management and operation staff the following services:

There are four core classes in the system – Product, Customer, Order and OrderItem

Product (Abstract Class)

Each product (books, videos, and CDs) has a name, a description, a price, and an inventory count. Each of the specific product types has the following additional information:

  • Videos: movie web site address, length in minutes, and a list of cast members

  • Books: author name, number of pages

  • CDs: number of tracks, play time, artist

Every product is able to display information about itself so that this information can be displayed on a web page (demonstration of polymorphism). 

Products have their inventory increased by receiving a shipment (method called receivedInventory( int aNumberReceived)), and their inventory decreased by customers placing orders for the product (method called orderPlaced(int aNumberOrdered)).

The product class keeps track of all products in the system and prints a list of products along with their inventory. There can be up to 100 products in the system (example of business rule).

Customer (Abstract Class)

The system stores information about all the customers that have placed orders on MissouriRiver.com. Every Customer has a name, address, and email address. There are two types of users: commercial and normal. Commercial customers receive a 10% discount when placing an order that is over $1000, and normal customers receive a 15% discount if there are more than five products in an order (example of business rule).

The customer class keeps track of all customers in the system and prints a list of customers and the number of orders each customer has placed, along with the dollar amount of each order, and the total dollar amount the customer has spent on MissouriRiver.com. There can be up to 100 Customers in the system (example of business rule).

Order

Order is a "relationship object" that captures the event of customer ordering products. An order has exactly 1 customer and up to 100 Products in the order. An order supports the following functionality:

The order class keeps track of all orders in the system and prints the list of orders, which customer placed the order, which products were in the order, and the total amount of the order. There can be up to 100 Orders in the system (example of business rule).

.

Use Case Diagram

wpe2.jpg (34287 bytes)

Class Diagram

wpe1.jpg (85422 bytes)

Interfaces (.h files) and Implementations (.cpp files)                                   

Product.h & Product.cpp Customer.h & Customer.cpp Order.h & Order.cpp

OrderItem.h & OrderItem.cpp

 

Product.h

// File Name    Product.h
//
// Description  Declaration of class Product
//              Member functions defined in Product.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef PRODUCT_H
#define PRODUCT_H

class Product {

public:
    // constructor function
    Product(char * name = "", char * description = "",
            double price = 0.0, int inventoryCount=0);
   
    // destructor function
    virtual ~Product();
   
    // set functions
    void setProduct(char * name, char * description, double price, int inventoryCount );
    void setName(char * name);
    void setDescription(char * description);
    void setPrice(double price);
    void setInventoryCount(int i);
   
    // get functions
    char * getName() const;            
    char * getDescription() const;   
    double getPrice() const;       
    int    getInventoryCount() const;   

    static void printProductList();         // print product list
    static int    getProductCount();         // return number of products instantiated
    static void addProduct(Product *);    // add product into array

    void receivedInventory(int aNumberRecived); // increase inventory
    void orderPlaced(int aNumberOrdered);         // decrease inventory

    // pure virtual function makes Product abstract base class
    virtual void print() const = 0;    // print product information

private:
    char *    name;             // name of the product
    char *    description;    // description of the product
    double    price;             // price of the product
    int        inventoryCount;     // inventory count

    static int productCount;             // number of products instantiated
    static Product *productList[100];    // array to store products

};

#endif


Product.cpp

// File Name      Product.cpp
//
// Description    Member functions definition for Product class
//
// Author         Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include <string.h>
#include <assert.h>
#include <iomanip.h>
#include "Product.h"

// Initialize static data member countProduct and array of Products
int Product::productCount = 0;    // no object yet
Product * Product::productList[100] ={0};

// Constructor for class Product
Product::Product(char * iname,
                char * idescription,
                double iprice,
                int iinventoryCount) {
    setProduct(iname, idescription, iprice, iinventoryCount);
    addProduct(this);
}

// Destructor
Product::~Product() {
    // cout << "destructor invoked";
    delete [] name;        // recapture memory
    delete [] description; // recapture memory
    --productCount;        // decrement static count of products
}

// Set the value of private data.
void Product::setProduct(char *n, char *d, double p, int i) {
    setName(n);
    setDescription(d);
    setPrice(p);
    setInventoryCount(i);
}

// Set product name
void Product::setName(char *n) {
    name = new char[strlen(n)+1];
    assert (name !=0);    // ensure memory allocated            
    strcpy(name, n);
}

// Set product description
void Product::setDescription(char *d) {
    description = new char[strlen(d)+1];
    assert (description !=0);    // ensure memory allocated
    strcpy(description, d);
}

// set product price
void Product::setPrice(double p) {
    price = p;
}

// set product inventory count
void Product::setInventoryCount(int i) {
    inventoryCount = i;
}

// get the name of the product
char *Product::getName() const {
    return name;
}

// get the description of the product
char *Product::getDescription() const {
    return description;
}

// get the price of the product
double Product::getPrice() const {
    return price;
}

// get the inventory count of the product
int Product::getInventoryCount() const {
    return inventoryCount;
}

// return the number of products instantiated
int Product::getProductCount() {
    return productCount;
}

// add product into array of products
void Product::addProduct(Product * aProduct) {
    if(productCount < 100)
    {
        productList[productCount] = aProduct;
        productCount++;
    }
    else
        cout << "Cannot add more products. Limit is 100 products.\n";
}

// increase products' inventory
void Product::receivedInventory (int aNumberReceived) {
    inventoryCount += aNumberReceived;
}

// decrease products' inventory
void Product::orderPlaced (int aNumberOrdered) {
    inventoryCount -= aNumberOrdered;
}

// print name/description/price/inventory of the product
void Product::print() const {
    cout <<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint|ios::left);
    cout << "Product : "     << getName()           << endl
         << "Description : " << getDescription()    << endl
         << "Price : "        << getPrice()          << " "
         << "Inventory : "    << getInventoryCount() << endl;
}

void Product::printProductList() {
    cout << endl << "--------------- Missouri.com - List of Products ---------------\n\n";
    for (int i=0; i < productCount; i++)
        productList[i]->print();
}


Book.h

// File Name    Book.h
//
// Description  Declaration of class Book
//              Member functions defined in Book.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef BOOK_H
#define BOOK_H
#include "Product.h"

class Book : public Product {

public:
    // contructor function
    Book(char * name = "", char * description = "", double price = 0.0,
        int inventoryCount = 0, char * author = "", int pages = 0);
   
    // destructor function
    virtual ~Book();
   
    // get functions
    char * getAuthor() const;
    int getPages() const;       
   
    // print function
    void print() const;    // print book information

private:
    char * author;    // book author
    int pages;        // number of pages

};

#endif


Book.cpp

// File Name    Book.cpp
//
// Description  Member functions definition for Book class
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include <string.h>
#include <assert.h>
#include "Book.h"

// constructor for class Book calling base-class constructor
Book::Book(char * iname,
    char * idescription,
        double iprice,
        int    iinventoryCount,
        char * iauthor,
        int    ipages)

    : Product(iname, idescription, iprice, iinventoryCount) {
   
    author = new char[strlen(iauthor)+1];
    assert(author!=0);
    strcpy(author, iauthor);
    pages = ipages;
}

// destructor
Book::~Book () {
    delete [] author;
}

// get the book author name
char *Book::getAuthor() const {
    return author;
}

// get the book number of pages
int Book::getPages() const {
    return pages;
}

// print book information calling base-class print function
void Book::print() const {
    Product::print();
    cout << "Author Name : " << getAuthor() << endl
         << "Pages Number: " << getPages()  << endl << endl;
}


Cd.h

// File Name    Cd.h
//
// Description  Declaration of class Cd
//              Member functions defined in Cd.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef CD_H
#define CD_H
#include "Product.h"

class Cd : public Product {

public:
    // constructor
    Cd(char * name = "", char * description = "", double price = 0.0,
    int inventoryCount = 0, char * artist = "", int tracks = 0, int playTime = 0);

    // destructor function
    virtual ~Cd();

    // get functions
    char * getArtist()    const;   
    int    getTracks()    const;    
    int    getPlayTime()  const;

    // print function
    void print() const;    // print cd information

private:
    char * artist;  // cd artist
    int tracks;     // number of tracks
    int playTime;   // cd play time

};

#endif


Cd.cpp

// File Name    Cd.cpp
//
// Description  Member functions definition for Cd class
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include <string.h>
#include <assert.h>
#include "Cd.h"

// constructor for class Cd calling base-class constructor
Cd::Cd(char    * iname,
    char * idescription,
    double iprice,
    int iinventoryCount,
    char * iartist,
    int itracks,
    int iplayTime)

    : Product(iname, idescription, iprice, iinventoryCount) {
   
    artist = new char[strlen(iartist)+1];
    assert(artist!=0);
    strcpy(artist, iartist);
    tracks    = itracks;
    playTime = iplayTime;
}

// destructor
Cd::~Cd () {
    delete [] artist;
}

// get the cd artist
char *Cd::getArtist() const {
    return artist;
}

// get the cd number of tracks
int Cd::getTracks() const {
    return tracks;
}

// get the cd play time
int Cd::getPlayTime() const {
    return playTime;
}

// print cd information calling base-class print function
void Cd::print() const {
    Product::print();
    cout << "Artist Name : " << getArtist()    << endl
         << "Track Number: " << getTracks()   << " "
         << "Play Time : "    << getPlayTime() << endl << endl;
}


Video.h

// File Name    Video.h
//
// Description  Declaration of class Video
//              Member functions defined in Video.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef VIDEO_H
#define VIDEO_H
#include "Product.h"

class Video : public Product {

public:
    // constructor function
    Video(char * name = "", char * description = "", double price = 0.0,
        int inventoryCount = 0, char * movieUrl = "", int lengh = 0,
        char * castMembers = "");
   
    // destructor function
    virtual ~Video();

    // get functions
    char * getMovieUrl()    const;
    int    getLength()         const;
    char * getCastMembers() const;

    // print function
    void print() const;    // print video information

private:
    char * movieUrl;    // movie url
    int    length;      // length in minutes
    char * castMembers; // list of cast membersie

};

#endif


Video.cpp

// File Name    Video.cpp
//
// Description    Member functions definition for Video class
//
// Author        Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include <string.h>
#include <assert.h>
#include "Video.h"

// constructor for class Video calling base-class constructor
Video::Video(char *iname,
            char *idescription,
            double iprice,
            int iinventoryCount,
            char *imovieUrl,
            int ilength,
            char *icastMembers)

    : Product(iname, idescription, iprice, iinventoryCount) {
   
    movieUrl = new char[strlen(imovieUrl)+1];
    assert(movieUrl!=0);
    strcpy(movieUrl, imovieUrl);
    length = ilength;
    castMembers = new char[strlen(icastMembers)+1];
    assert(castMembers!=0);
    strcpy(castMembers, icastMembers);
}

// destructor
Video::~Video () {
    delete [] movieUrl;
    delete [] castMembers;
}

// get the video movie url
char *Video::getMovieUrl() const {
    return movieUrl;
}

// get the video length
int Video::getLength() const {
    return length;
}

// get the cast members list of the video
char *Video::getCastMembers() const {
    return castMembers;
}

// print video information calling base-class print function
void Video::print() const {
    Product::print();
    cout << "Movie URL : "   << getMovieUrl()     << " "
         << "Min. Length : " << getLength()       << endl
         << "Cast Members: " << getCastMembers()  << endl << endl;
}


Customer.h

// File Name    Customer.h
//
// Description  Declaration of class Customer
//              Member functions defined in Customer.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef CUSTOMER_H
#define CUSTOMER_H

class Order;

class Customer {

public:
    // constructor function
    Customer(char * name = "", char * address = "", char * email = "");

    // destructor function
    virtual ~Customer();

    // set functions
    Customer &setCustomer(char * name, char * address, char * email);
    Customer &setName(char * name);
    Customer &setAddress(char * address);
    Customer &setEmail(char * email);

    // get functions
    char * getName()    const;
    char * getAddress() const;
    char * getEmail()   const;

    // print functions
    void print() const;    // print customer information
   
    static void printCustomerList();     // print customer list
    static int    getCustomerCount();    // return number of customers instantiated
    static void addCustomer(Customer *); // add customer into array

    Order * getOrder(int = 1);    // return a specific order for customer

    virtual double getDiscount(double amount, int qty ) = 0;

private:
    char * name;     // customer name
    char * address;  // customer address
    char * email;    // customer email
   
    static int customerCount;             // number of customers instantiated
    static Customer * customerList[100];  // array to store cuistomers
   
};


Customer.cpp

// File Name    Customer.cpp
//
// Description  Member functions definition for Customer class
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <assert.h>
#include "Order.h"
#include "Customer.h"

// Initialize static data member customerCount and array of Customers
int Customer::customerCount = 0;    // no object yet
Customer * Customer::customerList[100] ={0};

// Constructor to initialize customer private data
Customer::Customer(char * iname,
                    char * iaddress,
                    char * iemail) {
    setCustomer(iname, iaddress, iemail);
    addCustomer(this);
}

// Destructor
Customer::~Customer() {
    // cout << "destructor invoked";
    delete [] name;     // recapture memory
    delete [] address;  // recapture memory
    delete [] email;    // recapture memory
    --customerCount;    // decrement static count of products
}

// Set the value of private data.
Customer &Customer::setCustomer(char *n, char *a, char *e) {
    setName(n);
    setAddress(a);
    setEmail(e);
    return *this; // enables cascading
}

// Set customer name
Customer &Customer::setName(char *n) {
    name = new char[strlen(n)+1];
    assert (name !=0);        // ensure memory allocated
    strcpy(name, n);
    return *this;             // enables cascading
}

// Set customer address
Customer &Customer::setAddress(char *a) {
    address = new char[strlen(a)+1];
    assert (address !=0);     // ensure memory allocated
    strcpy(address, a);
    return *this;             // enables cascading
}

// Set customer email
Customer &Customer::setEmail(char *e) {
    email = new char[strlen(e)+1];
    assert (email !=0);       // ensure memory allocated
    strcpy(email, e);
    return *this;             // enables cascading
}

// Get customer name
char *Customer::getName() const {
    return name;
}

// Get customer address
char *Customer::getAddress() const {
    return address;
}

// Get customer email
char *Customer::getEmail() const {
    return email;
}

// Print customer
void Customer::print() const {
    cout << "Customer : " << getName()     << endl
         << "Address : "   << getAddress()  << endl
         << "E-mail : "    << getEmail()    << endl
         << endl;

}

void Customer::printCustomerList() {
    cout << endl << "--------------- Missouri.com - List of Customers ---------------\n\n";
    for (int i=0; i < customerCount; i++) {
        customerList[i]->print();

        int j=1;    // quantity of orders this customer placed

        // store total amount for this customer order
        double totalAmount=0.0;   
       
        // get and print all the orders this customer placed
        while (customerList[i]->getOrder(j)) {
            cout << "Order N. " << setw(3) << setiosflags(ios::left) << j;
            cout << "$" << setw(8) << setiosflags(ios::fixed|ios::showpoint|ios::left)
                << setprecision(2) << (((customerList[i])->getOrder(j))->getTotal())<<endl;
            totalAmount += customerList[i]->getOrder(j)->getTotal();
            j++;
        }

        cout << "Total Amount: $" << totalAmount << "\n\n";

    }
}

// Return the number of customers instantiated
int Customer::getCustomerCount() {
    return customerCount;
}

// Add customer into array of customers
void Customer::addCustomer(Customer * aCustomer) {
    if(customerCount<100)
    {
        customerList[customerCount]=aCustomer;
        customerCount++;    // increment static count of customers
    }
    else
        cout<<"Cannot add any more customer. Limit is 100 customers.\n";
}

// Return a specific order that customer placed
Order * Customer::getOrder (int index)
{
    return (Order::checkOrder(this, index));
}


Normal.h

// File Name    Normal.h
//
// Description  Declaration of class Normal (Normal Customer)
//              Member functions defined in Normal.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef NORMAL_H
#define NORMAL_H
#include "Customer.h"

class Normal: public Customer {

public:
    // constructor function
    Normal(char * name = "", char * address = "", char * email = "");
   
    // destructor function
    virtual ~Normal();
   
    // calculate the discount for normal customer
    virtual double getDiscount(double amount, int qty);

};

#endif


Normal.cpp

// File Name    Normal.cpp
//
// Description  Member functions definition for Normal (Customer) class
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include "Normal.h"

// constructor for class Normal calling base-class constructor
Normal::Normal(char * iname,
               char * iaddress,
               char * iemail)

    : Customer(iname, iaddress, iemail) {
}

// destructor
Normal::~Normal() {
}

// calculate discount
double Normal::getDiscount(double amount, int qty) {
    if (qty > 5)
        return amount * 0.15;
    else
        return 0.0;
}


Comercial.h

// File Name    Comercial.h
//
// Description  Declaration of class Comercial (Comercial Customer)
//              Member functions defined in Comercial.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef COMERCIAL_H
#define COMERCIAL_H

#include "Customer.h"

class Comercial: public Customer {

public:
    // constructor function
    Comercial(char * name = "", char * address = "", char * email = "");
   
    // destructor function
    virtual ~Comercial();
   
    virtual double getDiscount(double amount, int qty);
   
};

#endif


Comercial.cpp

// File Name    Comercial.cpp
//
// Description  Member functions definition for Comercial (Customer) class
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include "Comercial.h"

// constructor for class Comercial calling base-class constructor
Comercial::Comercial(char *iname,
                     char *iaddress,
                      char *iemail)

    : Customer(iname, iaddress, iemail) {
}

// destructor
Comercial::~Comercial() {
}

// calculate discount
double Comercial::getDiscount(double amount, int qty) {
    if (amount > 1000.0)
        return amount * 0.10;
    else
        return 0.0;
}


Order.h

// File Name    Order.h
//
// Description  Declaration of class Order
//              Member functions defined in Order.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef ORDER_H
#define ORDER_H

#include "OrderItem.h"

class Customer;

class Order {

    friend ostream &operator<<(ostream &, Order &);

public:
    // constructor function
    Order(Customer* aCustomer);
   
    // destructor function
    ~Order();

    void addItem(int, Product *, int);    //add an item to order
   
    // total functions
    void calculateTotal();
    double getTotal() const;
   
    // ship functions
    void goShip();
    void printShipStatus();

    static void printOrderList();    // print order list
    static int    getOrderCount();   // return number of orders instantiated
    static void addOrder(Order *od); // add order into array

    static Order* checkOrder(Customer *, int = 1);    //get specific order for this customer

    Customer * getCustomer() const;        

private:
    int status;    // 0 = not shipped, 1 = shipped
    double total;
    bool totalComputed;
   
    int itemCount;                   // number of items instantiated in this order
    OrderItem *itemList[100];        // array to store items in an order
   
    static int orderCount;           // number of orders instantiated
    static Order* orderList[100];    // array to store orders
   
    Customer *customerOfOrder;       // customer who placed the order

};

#endif


Order.cpp

// File Name    Order.cpp
//
// Description  Member functions definition for Order class
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include<iostream.h>
#include<iomanip.h>
#include "Customer.h"
#include "Product.h"
#include "Order.h"
#include "OrderItem.h"


// initialize static data member orderCount and array of orders
int Order::orderCount =0;
Order * Order::orderList [100]={0};

// constructor
Order::Order(Customer *aCustomer) {
    customerOfOrder = aCustomer;
    status    = 0;
    itemCount = 0;
    total = 0.0;
    totalComputed = false;
    addOrder(this);
}

// destructor
Order::~Order () {
    --orderCount;
}

// add item into the order only if item is less than 100 and
// total price of this order has not been computed
void Order::addItem (int itemNumber, Product * itemProduct, int itemQuantity)
{
    if ( (itemCount < 100) && (!totalComputed) ) {
        OrderItem *itemOfOrder = new OrderItem(itemNumber, itemProduct, itemQuantity);
        itemList[itemCount] = itemOfOrder;
        itemCount++;
    }
    else
        cout<<"Cannot add more items to the order. Limit is 100 items.\n";
}

// calculate the total of an order with the appropiate discount if appropriate
void Order::calculateTotal() {
    int totalQuantity = 0;
    if (!totalComputed) { // avoid duplicate calculate
        for (int i=0; i < itemCount; i++) {
            total += itemList[i]->getSubTotal();
            totalQuantity += itemList[i]->getItemQuantity();
        }
        total = total - (customerOfOrder->getDiscount(total, totalQuantity));
        totalComputed = true;    // total computed
    }
}

// return the total of this order
double Order::getTotal() const {
    return total;
}

// ship this order
void Order::goShip() {
    if (!totalComputed) {
        calculateTotal();
    }
    status=1;
}

// return this order shipment status
void Order::printShipStatus() {
    if (status==1) {
        cout << "Shipped";
    }
    else {
        cout << "Not shipped";
    }
}

// print order list with details of customers and purchased products
void Order::printOrderList() {
    cout << endl << "--------------- Missouri.com - List of Orders ---------------\n\n";
    for (int i=0; i < orderCount; i++) {
        cout << "Customer: " << orderList[i]->getCustomer()->getName() << endl;
        cout <<"Products Purchased:\n";
        for (int j=0; j < (orderList[i]->itemCount) ; j++) {
            cout << (j+1) << ". " << setw(50) << setiosflags(ios::left)
                << orderList[i]->itemList[j]->getItemProduct()->getName();
            cout << setiosflags(ios::right) << setw(2)
            << orderList[i]->itemList[j]->getItemQuantity() << " * ";
            cout << setw(8) << setiosflags(ios::right|ios::showpoint|ios::fixed)
                << setprecision(2) << orderList[i]->itemList[j]->getItemProduct()->getPrice();
            cout << " $" << setw(8) << setiosflags (ios::right|ios::showpoint|ios::fixed)
                << setprecision(2) << orderList[i]->itemList[j]->getSubTotal()<<endl;
        }
        cout << "Total Price: $" << setw(8) << setprecision(2)
            << setiosflags(ios::fixed|ios::showpoint|ios::left)
            << orderList[i]->getTotal() << endl;
        cout << "Order Status: " << setw(15) << setiosflags(ios::left);
        orderList[i]->printShipStatus();
        cout << "\n\n" ;
    }
}

// return the number of orders instantiated
int Order::getOrderCount() {
    return orderCount;
}

// add order into array of orders
void Order::addOrder(Order *aOrder) {
    if(orderCount<100) {
        orderList[orderCount]=aOrder;
        orderCount++;
    }
    else
        cout << "Cannot add more order. Limit is 100 orders.\n";
}

// find the specific order this customer has placed
Order * Order::checkOrder( Customer *aCustomer, int index) {
    int count=0;
    for(int i=0; i < orderCount; i++) {
        if(orderList[i]->getCustomer() == aCustomer) {
            count++;
        }
        if(count==index)
            return orderList[i];
    }
    return NULL;
}

// return customer of this order
Customer * Order::getCustomer() const {
    return customerOfOrder;
}

ostream & operator<<(ostream & output, Order & aOrder) {
    aOrder.getCustomer()->print();
    for (int i=0; i < aOrder.itemCount; i++) {
        output << *(aOrder.itemList[i]);
    }
    output << aOrder.getTotal() << endl;
    return output;
}


OrderItem.h

// File Name    OrderItem.h
//
// Description  Declaration of class OrderItem
//              Member functions defined in OrderItem.cpp
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#ifndef ORDERITEM_H
#define ORDERITEM_H

class Product;

class OrderItem {

    friend ostream &operator<<( ostream &, OrderItem &);

public:
    // constructor function
    OrderItem(int, Product * , int = 1);
   
    // destructor function
    ~OrderItem();
   
    // get functions
    int getItemNumber() const;
    int getItemQuantity() const;
    Product * getItemProduct() const;
   
    // calculates and return price * quantity
    double getSubTotal();

private:
    int itemNumber;          // sequencial number of order item
    int itemQuantity;        // quantity of product purchased

    Product *itemProduct;    // product of order item

};

#endif


OrderItem.cpp

// File Name    OrderItem.cpp
//
// Description  Member functions definition for OrderItem class
//
// Author       Siomara Cintia Pantarotto
//
// --------------------------------------------------------------

#include <iostream.h>
#include <iomanip.h>
#include "Product.h"
#include "OrderItem.h"

// constructor
OrderItem::OrderItem(int iitemNumber,
                    Product *iitemProduct,
                    int iitemQuantity) {
    itemNumber = iitemNumber;
    itemProduct = iitemProduct;
    itemQuantity = iitemQuantity;
   
    // decrease inventory of the product
    itemProduct->orderPlaced(itemQuantity);
}

// destructor
OrderItem::~OrderItem(){}

// return the item number
int OrderItem::getItemNumber() const {
    return itemNumber;
}

// return the item quantity
int OrderItem::getItemQuantity() const {
    return itemQuantity;
}

// return the item product
Product * OrderItem::getItemProduct() const {
    return itemProduct;
}

double OrderItem::getSubTotal() {
    return (itemProduct->getPrice()) * itemQuantity;
}


ostream &operator<<( ostream & output,OrderItem & item) {
    output << setw(3) << item.getItemNumber();
    output << setw(15) << ((item.getItemProduct())->getName());
    output << setw(3) << item.getItemQuantity();
    output << setw(8) << setiosflags(ios::fixed|ios::showpoint)
    << setprecision(2) << item.getSubTotal();
   
    return output;
}

1