      1  #include "invoice.h"
      2  #include "itemiterator.h"
      3  #include "invoiceprinter.h"
      4
      5  void Invoice::add(Item* it)
      6  {
      7     items.push_back(it);
      8  }
      9
     10  ItemIterator Invoice::create_iterator()
     11  {
     12     return ItemIterator(items);
     13  }
     14
     15  void Invoice::print(InvoicePrinter& printer)
     16  {
     17     printer.print_header("I N V O I C E");
     18     printer.print_string("Description", true);
     19     printer.print_string("Unit Price", false);
     20     printer.print_string("Qty", false);
     21     printer.print_string("Total Price", false);
     22
     23     double amount_due = 0;
     24     for (ItemIterator iter = create_iterator();
     25          !iter.is_done(); iter.next())
     26     {
     27        Item* it = iter.get();
     28        printer.print_string(it->get_description(), true);
     29        printer.print_number(it->get_unit_price(), 2);
     30        printer.print_number(it->get_quantity(), 0);
     31        printer.print_number(it->get_total_price(), 2);
     32        amount_due = amount_due + it->get_total_price();
     33     }
     34
     35     printer.print_footer("AMOUNT DUE:", amount_due);
     36  }