Hello,
I need to write this code and am lost at how to call these functions to output what I need. The task is to calculate and print the total cost of a round trip ticket for each line in the data file.
The input file (airline.txt) has the following layout:
Price (the cost of the ticket for that particular trip, it should be doubled if it is one way)
Airport tax (the tax for whole trip, both round trip and one way pay that tax)
Sales tax (the percentage tax on the total price of the ticket, including the airport tax, such as 6%, 10%, …etc.)
Airline name (SP, NW, SW, AA)
Origin City (can be one or two words)
One-way/roundtrip (1 means one way, 2 means round trip)
Destination City (can be one or two words)
These are examples of some trips:
99.99 10.00 0.06 SP Detroit 1 Palm Beach
143.95 13.00 0.06 NW Detroit 1 Palm Beach
99.00 10.00 0.10 SP Las Vegas 2 Detroit
You need to write a program to read the file one record at a time, then print the itinerary for that trip and calculate the ticket price as a round trip ticket (even if it was given as a one-way trip in the file.) The program will read the code letters for the name of the airline from the input and then expand them to the full name in the output. For example, NW, will become Northwest Airline, and SP will print Spirit Airline. The program also will read the name of the city from the input, then it will abbreviate it. If the city is one word, then the abbreviation will be the first and last letters of the word. Both letters should be capitalized. If the city is two words, then the abbreviation will be the first letter of each word.
A sample output for 99.99 10.00 0.06 SP Detroit 1 Palm Beach is:
The round trip price from DT to PB using Spirit Airline is $222.58
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
enum airlineType {SP, NW, SW, AA};
airlineType convertString(string str)
{
switch(toupper(str.at(0)))
{
case 'SP': return Spirit Airlines;
case 'NW': return Northwest Airlines;
case 'SW': return Southwest Airlines;
case 'AA': return American Airlines;
}
return NONE;
}
void display(airlineType air)
{
switch(air)
{
case SP: cout << "Spirit Airlines " << endl; break;
case NW: cout << "Northwest Airlines " << endl; break;
case SW: cout << "Southwest Airlines " << endl; break;
case AA: cout << "American Airlines " << endl; break;
default: cout << "Invalid Airline " << endl; break;
}
}
void getCity(string line, string& city)
{
string::size_type pos;
pos = line.find(" "); //find the first space
city = line.substr(0, pos); //will give me first part of the city name
if (line.at(pos + 1) >= '0' && line.at(pos + 1) <= '9') //will check the letter after the space...letter or number
cout << "My city is " << city << endl;
else
{
pos = line.find(" ", pos + 1); //find the second space in the city name
city = line.substr(0, pos); //gets both words
cout << "My city is " << city << endl;
}
}
tripType roundTrip()
{
int x;
cout << "Please enter [1] for one-way or [2] for round trip ";
cin >> x;
return static_cast<tripType>(x);
}
int main()
{
ifstream fin;
int price = 0;
int salesTax = 0;
string line = "", city = "";
bool upper = false;
fin.open("myinput.txt");
city = getCity(fin);
cout << "You have entered the city " << city;
return 0;
}
|