According to Wikipedia, a frequent flyer account is an airline loyalty program designed to encourage airline customers enrolled in the program to accumulate points which may then be redeemed for air travel or other rewards. Points earned may be based on the class of fare, distance flown on that airline or its partners, or the amount paid. Sometimes, there are other ways to earn points such as by using a co-branded credit card rather than by air travel. Points can be redeemed for air travel, other goods or services, or for increased benefits, such as travel class upgrades, airport lounge access, fast track access, or priority bookings.
Your assignment is to produce a two classes that work together to simulate PlaneFlights and a FrequentFlyerAccount. In an effort to help you, the design of these two classes will be discussed here. In addition, some sample code has been provided to assist you with this task. Various UML diagrams are shown below to communicate the code you need to create. Please follow the steps outlined below and don't jump ahead until you have finished the earlier step.
First, you will create the class PlaneFlight. This class represents plane trip. Each PlaneFlight object has a passenger name's, a cost, a from and to city as well as the mileage associated with this trip. All five of these parameters are provided to the PlaneFlight constructor. In addition to a constructor, each data member has a public accessor and mutator operation. The constructor and the mutator operations should enforce the following data validation rules:
Please review the class diagram shown here:
PlaneFlight |
- mCost: double - mFromCity: string - mToCity: string - mName: string - mMileage: double |
+ PlaneFlight(passengerName: string, fromCity: string, toCity: string, cost: double, mileage: double) + getCost(): double + setCost(cost: double): void + getMileage(): double + setMileage(mileage: double): void + getName(): string + setName(name: string): void + getFromCity(): string + setFromCity(from: string): void + getToCity(): string + setToCity(to: string): void |
Next, create the FrequentFlyerAccount class. Each FrequentFlyerAccount object has a name associated with the account and its mileage balance. Solely the name parameter is provided to the FrequentFlyerAccount constructor. In the beginning of time, the balance should start at zero. In addition to a constructor, each data member has a public accessor operation. The mileage balance gets increased by adding flights to the account via calls to .addFlightToAccount( ... ) when the passenger's name matches the frequent flyer account name. .addFlightToAccount( ... ) should return true when the names match and return false otherwise. Free flights can be redeemed from a FrequentFlyerAccount via calls to .freeFlight( ... ) which should use the passed parameters to create the desired PlaneFlight with a zero cost, adjusting the mileage balance accordingly. .freeFlight( ... ) should return true when enough of a mileage balance existed to create a free flight and return false otherwise. A FrequentFlyerAccount can also be used to determine if enough of a mileage balance is available for a desired flight via calls to .canEarnFreeFlight( ) which returns the appropriate boolean answer.
Please review the class diagram shown here:
FrequentFlyerAccount |
- mName: string - mBalance: double |
+ FrequentFlyerAccount(name: string) + getBalance(): double + getName(): string + addFlightToAccount(flight: PlaneFlight): bool + canEarnFreeFlight(mileage: double): bool + freeFlight(from: string, to: string, mileage: double, flight: PlaneFlight &): bool |
For this project, you will create both a .h and .cpp for this class. Write some sample driver code in your main( ) and create assertions to verify that your accessor methods are all working properly. Some sample code is shown below to further document how this class should work.
You are free to create additional public and private methods and data members as you see fit. However, the test cases will only be driving the public methods of the two classes diagrammed here.
The source files you turn in will be these classes and a main routine. You can have the main routine do whatever you want, because we will rename it to something harmless, never call it, and append our own main routine to your file. Our main routine will thoroughly test your functions. You'll probably want your main routine to do the same. If you wish, you may write additional class operation in addition to those required here. We will not directly call any such additional operations directly.
The program you turn in must build successfully, and during execution, no method may read anything from cin. If you want to print things out for debugging purposes, write to cerr instead of cout. When we test your program, we will cause everything written to cerr to be discarded instead we will never see that output, so you may leave those debugging output statements in your program if you wish.