Introduction

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 task

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:

  • a valid cost must be a value of 0 or more. (A zero-cost flight will indicate a free flight earned by a frequent flyer. More on that shortly...). A PlaneFlight should store the value -1 to indicate when an invalid flight cost was attempted to be stored.
  • empty string values are not valid for either a FromCity or a ToCity value. Additionally, the specified FromCity and ToCity must be different. A PlaneFlight should ignore and not accept an invalid FromCity or ToCity value. Similarly, the empty string is not valid for a passenger's Name. A PlaneFlight should ignore and not accept an invalid Name value.
  • a valid mileage must be a value greater than 0. A PlaneFlight should store the value -1 to indicate when an invalid mileage amount was attempted to be stored.

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.