Question: C + + code only need help with C + + code please I need help in fixing my code because I cannot get the
C code only
need help with C code please
I need help in fixing my code because I cannot get the right output for flight and arrival time
This is my code
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
Structure to hold time in hours and minutes
struct Time
int hour;
int minute;
;
Function to parse a time string and convert it to the Time structure
Time parseTimeconst string& timeString
Time t;
istringstream isstimeStringsubstr;
char discard;
iss thour discard tminute;
if timeStringsubstrPM && thour
thour ; Convert PM time to hour format
else if timeStringsubstrAM && thour
thour ; Midnight is in hour format
return t;
Function to format Time structure back into a humanreadable string
string formatTimeconst Time& time
int hour time.hour : time.hour ; Convert hour time to hour format
string amPm time.hour PM : AM;
ostringstream oss;
oss hour : setfill setw time.minute amPm;
return oss.str;
Function to add minutes to a time, adjusting hours and wrapping around if necessary
Time addMinutesconst Time& time, int mins
Time newTime time;
newTime.minute mins;
newTime.hour newTime.minute ;
newTime.minute ;
newTime.hour ;
return newTime;
Calculate the arrival time considering flight duration and time zone differences
Time calculateArrivalTimeconst Time& departureTime, int flightDurationMinutes, int timeZoneDifference
Time arrivalTime addMinutesdepartureTime flightDurationMinutes; Add flight duration to departure time
arrivalTime.hour timeZoneDifference; Adjust for the time zone difference
if arrivalTimehour
arrivalTime.hour ; Wrap around if hour exceeds
else if arrivalTimehour
arrivalTime.hour ; Adjust for negative hour values
return arrivalTime;
Helper function to split strings based on a given delimiter
vector splitconst string& s char delimiter
vector tokens;
string token;
istringstream tokenStreams;
while getlinetokenStream token, delimiter
tokens.pushbacktoken;
return tokens;
int main
map timeZoneOffsets
Charlotte
Orlando
Houston
Denver
San Diego",
;
map, int flightTimes
San Diego", "Denver"
San Diego", "Houston"
Denver "Houston"
Houston "Charlotte"
Houston "Orlando"
San Diego", "Charlotte"
Charlotte "Orlando"
;
string fileName;
cout "Enter file name: ;
getlinecin fileName;
ifstream filefileName;
if file.isopen
cout "File not found." endl;
return ;
int numFlights;
file numFlights;
file.ignorenumericlimits::max
; Skip to the next line after reading number of flights
for int i ; i numFlights; i
string line;
getlinefile line;
auto parts splitline;
string departureCity parts;
string timeString parts parts;
string destinationCity parts;
if partssize Check if city name consists of two parts like "San Diego"
destinationCity parts;
Time departureTime parseTimetimeString;
int flightTime flightTimesdepartureCity destinationCity;
int timeZoneDifference timeZoneOffsetsdestinationCity timeZoneOffsetsdepartureCity;
Time arrivalTime calculateArrivalTimedepartureTime flightTime, timeZoneDifference;
cout "Flight i : departureCity formatTimedepartureTime
destinationCity formatTimearrivalTime endl;
file.close;
return ;
This is the output that I got from my code
Enter file name: airtimes.txt
Flight : Houston : AM Orlando : AM
Flight : Orlando : AM Charlotte : AM need to get : PM here for flight arrival
Flight : Charlotte : AM San Diego : AM need to get : AM here for flight arrival
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
