Stuck with my functions and output...

This is a discussion on Stuck with my functions and output... within the C++ Programming forums, part of the General Programming Boards category; Hello, I need to write this code and am lost at how to call these functions to output what I ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    5

    Stuck with my functions and output...

    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

    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    using namespace std;
    
    enum airlineType {NONE=0, SP, NW, SW, AA}; 
    char* airlines[] = {"NONE", "Spirit Airlines", "Northwest Airlines", "Southwest Airlines", "American Airlines"}; 
    
    airlineType convertString(string str)
    {
      if (str == "SP") 
        return SP; 
      if (str == "NW")
        return NW;
      if (str == "SW")
        return SW;
      if (str == "AA")
        return AA;
    
      return NONE; // if you reach here, then nothing matched, so you default to 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;
    	}
    }
    
    int 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;
    	}
    	return city.length();
    }
    
    int getNumber(string line, float& number)
    
    char getAirline()
    
    char getTrip()
    
    int main()
    {
    	string line;
    	getline(fin, line);
    
    	int length;
    	float price;
    	length = getNumber(line, price);
    	line = line.substr(length);
    	float airportTax;
    	length = getNumber(line, airportTax);
    	line = line.substr(length);
    	float salesTax;
    	length = getNumber(line, salesTax);
    	line = line.substr(length);
    	airlineType airline;
    	length = getAirline(line, airline);
    	line = line.substr(length);
    
    	return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    18
    So, what is your question?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me please.
    By yann in forum C Programming
    Replies: 15
    Last Post: 09-29-2009, 10:04 PM
  2. Replies: 3
    Last Post: 10-23-2006, 07:37 PM
  3. counting and output, with arrays and functions
    By Wraithan in forum C++ Programming
    Replies: 7
    Last Post: 12-05-2005, 12:46 AM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. File output and functions
    By frigga in forum C Programming
    Replies: 3
    Last Post: 11-20-2002, 07:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21