Docstoc

ppt Ticket Booth with Ticket Prices

Document Sample
ppt Ticket Booth with Ticket Prices Powered By Docstoc
					Ticket Booth with Ticket Prices




                                  1
                   Objectives

You will be able to use collaboration among
  objects of various classes to determine the
  price of a ticket.




                                                2
                       Getting Started
   Start with program from last class:
   http://www.cse.usf.edu/~turnerr/Object_Oriented_Design/
    Downloads/2010_12_01_Ticket_Booth_with_Tickets/
       File Ticket_Booth_with_Tickets.zip
       Expand and rename folder Ticket_Booth_with_Prices.




                                                              3
        Class Ticket_Booth

           Ticket_Booth




*             *               *
Venue         Show           Booking




                                       4
                                          Class Diagram

                                                                                          Booking


Address                 Venue
           1   1
Street                 Name
City                                                            *
                                              Price Spec
State
Zip Code                          1         Section Name
                                            Price Level
                                                                                    *                     1
                        *                                                  Performance                        Show
                   Seat Row
                                                                         Date                *      1    Name
                                                                    *
                       Name                                              Time
                       Nr Seats                                          price schedule
                                                                         name

                   1                                                                1

                           *                               Ticket Book                                          *
                   *
                         Seat                                                                           Price Schedule
                       Row Name                                                                         Name
                   Section Name                                                                         Price Level 1
                                                                    *              *                    Price Level 2
                                      1                     *
                                                                         Ticket                         Price Level 3




                                                                                                                         5
                  Computing a Ticket Price

   Ticket Price depends on:
       Seating Section of the Seat
       Price Level for that Seating Section
            How good are the seats in that seating section?
       Price Schedule for the Performance
            How good is the show?
            How desirable are the venue and time of the performance?

   Ticket knows its Seat.
       Can get Seating Section name from the Seat.

   Ticket knows its Performance.
       Performance knows Price Schedule Name.
       Performance knows its Show                                  6
                 Computing a Ticket Price

   Booking knows Price Level for each Seating
    Section of the Venue.
       Price_Spec
            Front = Level 1
            Center = Level 3
            etc.


   Show knows prices for all Price Levels for
    various Price Schedules.
       Normal, Premium, Economy, etc.



                                                 7
                                Computing a Ticket Price

Seat                  Ticket                  Performance                     Booking                   Show

       Get_Section_Name()



       Section_Name         Get_Price(Section_Name)

                                                       Get_Price_Level
                                                       (Section_Name)



                                                            Price_Level


                                                         Get_Price (Price_Schedule_Name, Price_Level)



                                                                              Price
                                   Price




                                                                                                               8
                       What is Missing?
   Only the Booking knows how to map the Venue's
    Seating Sections to the Show's Price Levels.
       Doesn't make that information available


   The Performance does not know its Booking.

   Class Show knows its Price schedules
       Doesn't make that information available.




                                                    9
                        Filling the Gaps
   Let the Performance know its Booking.
       Add Booking* parameter to constructor
       Will need to use an incomplete class declaration in order to
        avoid circular includes.

   Add method to Booking to map Seating Section name
    to a price level.
       Get_Price_Level (Seating_Section_Name)

   Add a method to class Show to return the ticket price
    for a specified Price_Schedule and Price_Level

   Add a method to Performance to determine the ticket
    price for a given seating section.

   Let class Ticket use this method to determine its price.
                                                                       10
                        Filling the Gaps
   Let the Performance know its Booking.
       Add Booking* parameter to constructor
       Will need to use an incomplete class declaration in order to
        avoid circular includes.

   Add method to Booking to map Seating Section name
    to a price level.
       Get_Price_Level (Seating_Section_Name)

   Add a method to class Show to return the ticket price
    for a specified Price_Schedule and Price_Level

   Add a method to Performance to determine the ticket
    price for a given seating section.

   Let class Ticket use this method to determine its price.
                                                                       11
                           Performance.h
   Also change price_schedule to price_schedule_name
        Avoid confusing the name with the actual thing.


   Current constructor:
     Performance(Show* show_,
                 Venue* venue_,
                 tm when_,
                 string price_schedule_);


   Revised constructor:
     Performance(const Booking* const booking_,
                 tm when_,
                 string price_schedule_name_);


   Don't need show and venue, because we can get them from the Booking.

                                                                       12
                     Performance.h
#pragma once
#include <ctime>
#include <string>
#include "Venue.h"
#include "Show.h"
#include "Ticket_Book.h"

class Booking;

class Performance
{
private:
    const Booking* const booking;
    const Show* show;
    const Venue* venue;
    tm when;
    std::string price_schedule_name;
    Ticket_Book* ticket_book;
                                       13
                Performance.h (continued)

public:
    //Performance() {};

     Performance(const Booking* booking_,
                 tm when_,
                 string price_schedule_name_);

     const Venue* Get_Venue() const {return venue;};
     const Show* Get_Show() const {return show;};
     tm Get_When() const {return when;};
     string Get_When_String() const;
     string Get_Price_Schedule_Name() const {return price_schedule_name;};
     void Display() const;
};




                                                                         14
                    Performance.cpp
#include "Booking.h"
...
Performance::Performance(const Booking* booking_,
                         tm when_,
                         string price_schedule_name_) :
    booking(booking_),
    show(booking->Get_Show()),
    venue(booking->Get_Venue()),
    when(when_),
    price_schedule_name(price_schedule_name_)
{
    ticket_book = new Ticket_Book(this);
}
...
void Performance::Display() const
{
     ...
     cout << "Price schedule: " << price_schedule_name << endl;
}                                                             15
                       Booking_from_Xml

   Update Booking_from_Xml to use revised
    constructor for Performance.

   In Booking_from_Xml.h
private:
    Booking_from_Xml(void) {};

    static Booking::Price_Spec Get_Price_Spec(TiXmlNode* price_spec_node);

    static Performance* Get_Performance(Booking* booking,
                                        TiXmlNode* performance_node);




                                                                        16
                     Booking_from_Xml.cpp
Booking*
Booking_from_Xml::Get_Booking(TiXmlNode* booking_node)
{
    ...
   Performance* p = Get_Performance(booking, performance_node);
   ...
}

Performance*
Booking_from_Xml::Get_Performance(Booking* booking,
                                  TiXmlNode* performance_node)
{
    ...
    Performance* p = new Performance(booking, when, price_schedule);

    return p;
}




                  Build
                                                                       17
                                          Class Diagram

                                                                                             Booking


Address                 Venue
           1   1
Street                 Name
City                                                            *
                                              Price Spec
State
Zip Code                          1                                                               1
                                            Section Name
                                            Price Level
                                                                                      *       *              1
                                                                1       1
                        *                                                     Performance                        Show
                   Seat Row
                                                                            Date                  *    1    Name
                                                                    *
                       Name                                                 Time
                       Nr Seats                                             price schedule
                                                                            name

                   1                                                                   1

                           *                               Ticket Book                                             *
                   *
                         Seat                                                                              Price Schedule
                       Row Name                                                                            Name
                   Section Name                                                                            Price Level 1
                                                                    *                 *                    Price Level 2
                                      1                     *
                                                                            Ticket                         Price Level 3




                                                                                                                            18
                        Filling the Gaps
   Let the Performance know its Booking.
       Add Booking* parameter to constructor
       Will need to use an incomplete class declaration in order to
        avoid circular includes.

   Add method to Booking to map Seating Section name
    to a price level.
       Get_Price_Level (Seating_Section_Name)

   Add a method to class Show to return the ticket price
    for a specified Price_Schedule and Price_Level

   Add a method to Performance to determine the ticket
    price for a given seating section.

   Let class Ticket use this method to determine its price.
                                                                       19
                        Booking.h

   Add new public method to map a Seating
    Section name in the Venue to a Price Level.

   int Get_Price_Level(const string& Section_Name) const




                                                            20
                            Booking.cpp

// Get the price level for a specified section in the Venue
// for this Booking
int Booking::Get_Price_Level (const string& section_name) const
{
    for (size_t i = 0; i < price_specs.size(); ++i)
    {
        if (price_specs[i].section_name == section_name)
        {
            return price_specs[i].price_level;
        }
    }
    string err_msg =
       "Invalid section name passsed to Booking::Get_Price_Level";
    throw (err_msg);
}




                Build
                                                                     21
                                          Class Diagram

                                                                                             Booking


Address                 Venue
           1   1
Street                 Name
City                                                            *                    Get_Price_Level()
                                              Price Spec
State
Zip Code                          1                                                               1
                                            Section Name
                                            Price Level
                                                                                       *      *              1
                                                                1       1
                        *                                                     Performance                        Show
                   Seat Row
                                                                            Date                  *    1    Name
                                                                    *
                       Name                                                 Time
                       Nr Seats                                             price schedule
                                                                            name

                   1                                                                    1

                           *                               Ticket Book                                             *
                   *
                         Seat                                                                              Price Schedule
                       Row Name                                                                            Name
                   Section Name                                                                            Price Level 1
                                                                    *                  *                   Price Level 2
                                      1                     *
                                                                            Ticket                         Price Level 3




                                                                                                                            22
                        Filling the Gaps
   Let the Performance know its Booking.
       Add Booking* parameter to constructor
       Will need to use an incomplete class declaration in order to
        avoid circular includes.

   Add method to Booking to map Seating Section name
    to a price level.
       Get_Price_Level (Seating_Section_Name)

   Add a method to class Show to return the ticket price
    for a specified Price_Schedule and Price_Level

   Add a method to Performance to determine the ticket
    price for a given seating section.

   Let class Ticket use this method to determine its price.
                                                                       23
                            Show.h

   Add new public method:

int Get_Price(const std::string& price_schedule_name,
              int price_level) const;




                                                        24
                           show.cpp
int Show::Get_Price(const string& price_schedule_name,
                    int price_level) const
{
    assert(price_level >= 1);
    assert(price_level <= 3);
    for (int i = 0; i < number_of_price_schedules; ++i)
    {
        if (price_schedules[i].name == price_schedule_name)
        {
            switch(price_level)
            {
            case 1: return price_schedules[i].price_level_1;
            case 2: return price_schedules[i].price_level_2;
            case 3: return price_schedules[i].price_level_3;
            }
        }
    }
    return -1; // Never reach this point.
}                                                              25
                          Build
                                          Class Diagram

                                                                                             Booking


Address                 Venue
           1   1
Street                 Name
City                                                            *                    Get_Price_Level()
                                              Price Spec
State
Zip Code                          1                                                               1
                                            Section Name
                                            Price Level
                                                                                       *      *              1
                                                                1       1
                        *                                                     Performance                        Show
                   Seat Row
                                                                            Date                  *    1    Name
                                                                    *
                       Name                                                 Time
                       Nr Seats                                             price schedule
                                                                            name                           Get_Price( )

                   1                                                                    1

                           *                               Ticket Book                                             *
                   *
                         Seat                                                                              Price Schedule
                       Row Name                                                                            Name
                   Section Name                                                                            Price Level 1
                                                                    *                  *                   Price Level 2
                                      1                     *
                                                                            Ticket                         Price Level 3




                                                                                                                            26
                        Filling the Gaps
   Let the Performance know its Booking.
       Add Booking* parameter to constructor
       Will need to use an incomplete class declaration in order to
        avoid circular includes.

   Add method to Booking to map Seating Section name
    to a price level.
       Get_Price_Level (Seating_Section_Name)

   Add a method to class Show to return the ticket price
    for a specified Price_Schedule and Price_Level

   Add a method to Performance to determine the ticket
    price for a given seating section.

   Let class Ticket use this method to determine its price.
                                                                       27
                   Performance.h

   Now class Performance has the information
    available to compute the price of a ticket for a
    seat in a specified seating section.

   New public method:
int Ticket_Price(const string& section_name) const;




                                                   28
                       Performance.cpp

int Performance::Ticket_Price(const string& section_name) const
{
    int price_level = booking->Get_Price_Level(section_name);
    int price = show->Get_Price(price_schedule_name, price_level);
    return price;
}




                                                                     29
                                          Class Diagram

                                                                                              Booking


Address                 Venue
           1   1
Street                 Name
City                                                            *                      Get_Price_Level()
                                              Price Spec
State
Zip Code                          1                                                               1
                                            Section Name
                                            Price Level
                                                                                         *        *           1
                                                                1   1
                        *                                                       Performance                       Show
                   Seat Row                                                 Date
                                                                                                      * 1    Name
                       Name                                                 Time
                                                                    *
                       Nr Seats                                             price schedule name
                                                                            Ticket_Price( )                 Get_Price( )

                   1                                                                      1

                           *                               Ticket Book                                              *
                   *
                         Seat                                                                               Price Schedule
                       Row Name                                                                             Name
                   Section Name                                                                             Price Level 1
                                                                        *                *                  Price Level 2
                                      1                     *
                   Row_Name( )                                                Ticket                        Price Level 3




                                                                                                                             30
                        Filling the Gaps
   Let the Performance know its Booking.
       Add Booking* parameter to constructor
       Will need to use an incomplete class declaration in order to
        avoid circular includes.

   Add method to Booking to map Seating Section name
    to a price level.
       Get_Price_Level (Seating_Section_Name)

   Add a method to class Show to return the ticket price
    for a specified Price_Schedule and Price_Level

   Add a method to Performance to determine the ticket
    price for a given seating section.

   Let class Ticket use this method to determine its price.
                                                                       31
                     Ticket.h

   Add new public method to public section:

int Price() const;




                                               32
                            Ticket.cpp
#include <iostream>
#include "Ticket.h"
#include "Performance.h"
#include "Seat.h"
using namespace std;

Ticket::Ticket(const Performance* perf, const Seat* s) :
    performance(perf), seat(s), sold(false)
{}

void Ticket::Display() const
{
    performance->Display();
    seat->Display();
    cout << "$" << Price() << ".00" << endl;
}

int Ticket::Price() const
{
    return performance->Ticket_Price(seat->Section_Name());
}
                                                              33
                                            Class Diagram

                                                                                                  Booking


Address                   Venue
           1     1
Street                   Name
City                                                              *                        Get_Price_Level()
                                                Price Spec
State
Zip Code                            1                                                                 1
                                              Section Name
                                              Price Level
                                                                                             *        *           1
                                                                  1     1
                          *                                                         Performance                       Show
                     Seat Row                                                   Date
                                                                                                          * 1    Name
                         Name                                                   Time
                                                                       *
                         Nr Seats                                               price schedule name
                                                                                Ticket_Price( )                 Get_Price( )

                     1                                                                        1

                             *                               Ticket Book                                                *
                   *
                 Seat                                                                                           Price Schedule
           Row Name                                                                                             Name
                                                                                                                Price Level 1
           Section Name                                                     *                *
                                        1                     *                                                 Price Level 2
           Get_Section_Name( )                                                    Ticket                        Price Level 3


                                                                      Price( )
                                                                      Display( )



                                                                                                                                 34
                                Computing a Ticket Price

Seat                  Ticket                  Performance                     Booking                   Show

       Get_Section_Name()



       Section_Name         Get_Price(Section_Name)

                                                       Get_Price_Level
                                                       (Section_Name)



                                                            Price_Level


                                                         Get_Price (Price_Schedule_Name, Price_Level)



                                                                              Price
                                   Price




                                                                                                               35
Program in Action




                    36
                      Program in Action




                                          37
End of Presentation

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:6
posted:12/19/2010
language:English
pages:37
Description: ppt Ticket Booth with Ticket Prices