Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ programming problem Frequent Flyer Miles Calculator Write a C++ program that

ID: 3679792 • Letter: C

Question

c++ programming problem

Frequent Flyer Miles Calculator Write a C++ program that calculates how many frequent flyer miles are needes for a free ticket on a new startup airline. Frequent flyer miles are charged for a free ticket depending on the class of service (more for first class, less for coach), depending on the day flying (more if flying on Friday, Saturday or Monday, less for other days of the week), depending on the distance traveled, and a surcharge if flying to Canada, Mexico or the Carribean. Tickets start with a cost of 10,000 frequent flyer miles. Then, you should calculate the distance charge which is 1,000 frequent flyer miles for each 250 miles flown. Then, you should charge an additional 40% charge of frequent flyer miles if the passenger wants to fly first class. If flying on a Friday, Saturday or Monday, the ticket will cost an additional 5,000 frequent flyer miles. Travel to Canada, Mexico or the Carribean needs to cost an additional 7500 frequent flyer miles. Be sure your program does not allow for negative miles flown or incorrect answers to the yes/no questions asked. The sample program dialogs below should help you to see how to perform this calculation. YOU NEED TO DECLARE AND USE A const DECLARATION FOR SOME CERTAIN VALUES IN YOUR PROGRAM.

Explanation / Answer

#include<iostream>

using namespace std;

int main(){
  
   const int BASE_COST = 10000;
   const int SPECIAL_DAY_CHARGE = 5000;
   const int SPECIAL_CITY_CHARGE = 7500;
  
   char ans, c='y';
   bool isFirstClass = false, isOnSpecialDay = false, isSpecialCity = false;
   float totalCost = 0, distance, distanceCharge;
  
   while(c=='y'){
      
       totalCost = totalCost + BASE_COST;
      
       cout<<"How far are our flying: ";
       cin>>distance;
       if(distance <= 0){
           cout<<"wrong answer"<<endl;
           cout<<"Continue(y/n)? ";
           cin>>c;
           totalCost = 0;
           continue;
           }
          
       distanceCharge = (distance/250.0)*1000;
       totalCost = totalCost + distanceCharge;
      
       cout<<"Want first class(y/n): ";
       cin>>ans;
       if(ans == 'y'){
           isFirstClass = true;
           }
       else if(ans != 'n'){
           cout<<"wrong answer"<<endl;
           cout<<"Continue(y/n)? ";
           cin>>c;
           totalCost = 0;
           continue;
           }
          
       cout<<"Flying on a Friday, Saturday or Monday(y/n): ";
       cin>>ans;
       if(ans == 'y'){
           isOnSpecialDay = true;
           }
       else if(ans != 'n'){
           cout<<"wrong answer"<<endl;
           cout<<"Continue(y/n)? ";
           cin>>c;
           totalCost = 0;
           continue;
           }
          
       cout<<"Flying to Canada, Maxico or the Carribean(y/n): ";
       cin>>ans;
       if(ans == 'y'){
           isOnSpecialDay = true;
           }
       else if(ans != 'n'){
           cout<<"wrong answer"<<endl;
           cout<<"Continue(y/n)? ";
           cin>>c;
           totalCost = 0;
           continue;
           }
          
       cout<<BASE_COST<<" base cost"<<endl;
       cout<<distanceCharge<<" distance charge"<<endl;
       if(isFirstClass){
           float firstClassCharge = totalCost*0.4;
           cout<<firstClassCharge<<" First class charge"<<endl;
           totalCost = totalCost + firstClassCharge;
           }
       if(isOnSpecialDay){
           cout<<SPECIAL_DAY_CHARGE<<" special day charge"<<endl;
           totalCost= totalCost+SPECIAL_DAY_CHARGE;
           }
       if(isSpecialCity){
           cout<<SPECIAL_CITY_CHARGE<<" special city charge"<<endl;
           totalCost = totalCost + SPECIAL_CITY_CHARGE;
           }
          
       cout<<"You will need "<<totalCost<<" frequent flyer miles for this ticket. Enjoy your trip!"<<endl;
      
       cout<<"Continue(y/n)? ";
       cin>>c;
      
       }
   return 0;
   }

/*

Output:

How far are our flying: 500
Want first class(y/n): y
Flying on a Friday, Saturday or Monday(y/n): n
Flying to Canada, Maxico or the Carribean(y/n): n
10000 base cost
2000 distance charge
4800 First class charge
You will need 16800 frequent flyer miles for this ticket. Enjoy your trip!
Continue(y/n)? n

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote