I have an assignment ... but it's really unnecessary to post all the details up. Basically, I have a header file and an implementation file (and I'm supposed to include an application file, but I don't have the slightest clue by what the professor means by that?).
I have the program working using the following test data:
Airline: DL
Flight Number: 478
From: SF
To: DFW
Departure: Jul 2,2008 10:25 AM
Arrival: Jul 2,2008 2:45 PM
Except for one problem... After I enter all the information, the info is spit back out to the screen, but the departure line is skipped and instead it moves to the arrival line, and arrival info never shows. Please help... I know it has to be something simple that I'm just overlooking.
Here's the code I have so far:
File: assign_3_header.h
#include <string>
using namespace std;
// Creating Flight class - no pun intended.
class Flight
{
string air_;
int fli_;
string ori_;
string des_;
string dep_;
string arr_;
public:
string airline;
int flightNumber;
string origin;
string destination;
string departureTime;
string arrivalTime;
// Default constructor -- Assigns empty strings to all string data members
// and 0 to the numeric member variables
Flight()
{
airline = "";
flightNumber = 0;
origin = "";
destination = "";
departureTime = "";
arrivalTime = "";
}
void setAirline(string s) {air_ = s;};
void setFlightNumber(int y) {fli_ = y;};
void setOrigin(string o) {ori_ = o;};
void setDestination(string x) {des_ = x;};
void setDeparture(string p) {dep_ = p;};
void setArrivalTime(string z) {arr_ = z;};
string getAirline()
{ return air_; }
int getFlightNumber()
{ return fli_; }
string getOrigin()
{ return ori_; }
string getDestination()
{ return des_; }
string getDeparture()
{ return dep_; }
string getArrivalTime()
{ return arr_; }
// Constructor that accepts values as arguments and assigns them to the
// data member variables
Flight (string a, int b, string c, string d, string e, string f)
{
airline = a;
flightNumber = b;
origin = c;
destination = d;
departureTime = e;
arrivalTime = f;
}
};
and
File: assign_3_source.cpp
#include "assign_3_header.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
Flight flight1; // flight object 1
Flight flight2; // flight object 2
Flight flight3; // flight object 3
string a_n; // local variable for air_
int f_n; // local variable for fli_
string o_n; // local variable for ori_
string d_n; // local variable for des_
string d_t; // local variable for dep_
string a_t; // local variable for arr_
cout << "Please enter your airline name: ";
cin >> a_n;
flight1.setAirline(a_n);
cout << "Please enter your flight number: ";
cin >> f_n;
flight1.setFlightNumber(f_n);
cout << "Please enter your origin: ";
cin >> o_n;
flight1.setOrigin(o_n);
cout << "Please enter your destination: ";
cin >> d_n;
flight1.setDestination(d_n);
cout << "Please enter your departure information: ";
std::getline(std::cin, d_t ,'\n');
flight1.setDeparture(d_t);
cout << "Please enter your arrival information: ";
std::getline(std::cin, a_t, '\n');
flight1.setArrivalTime(a_t);
cout << endl;
cout << "Airline: " << flight1.getAirline() << endl;
cout << "Flight Number: " << flight1.getFlightNumber() << endl;
cout << "From: " << flight1.getOrigin() << endl;
cout << "To: " << flight1.getDestination() << endl;
cout << "Departure: " << flight1.getDeparture() << endl;
cout << "Arrival: " << flight1.getArrivalTime() << endl;
return 0;
}
Please excuse my lack of comments. I tend to add them after the fact, so if you have any questions about the code, don't hesitate to ask.