Any ideas what this compile error is?
Code:
In file included from Application.cpp:5:
Airport.h:12: syntax error before `*' token
Application.cpp:8: semicolon missing after declaration of `Application'
Application.cpp:8: parse error before `using'
Application.cpp:8: `string' specified as declarator-id
Application.cpp:8: two or more data types in declaration of `string'
Application.cpp:8: `int std::string' redeclared as different kind of symbol
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/../../../include/g++-v3/bits/stringfwd.h:63: previous
declaration of `typedef struct std::basic_string<char,
std::char_traits<char>, std::allocator<char> > std::string'
Application.cpp: In function `int main()':
Application.cpp:41: no match for `std::istream& << int&' operator
Application.cpp:64:2: warning: no newline at end of file
Flight.cpp:20: parse error before `public'
Flight.cpp:11: warning: all member functions in class `Flight::Flight' are
private
Flight.cpp:82: parse error at end of input
OK, my files....
Airport.h
Code:
// Airport.h
#include <string>
using std::string;
class Airport {
private:
// Class Variables
static const int MAXFLIGHTS = 100;
Flight * flights[MAXFLIGHTS];
string airportName;
string airportID;
int numFlights;
public:
// Class Methods
int addFlight(string, string, string, string, string);
string getFlightDetails(string);
string getAirportID();
string getAirportName();
// Constructor for airport
Airport(string, string);
}; // class Airport
Airport.cpp
Code:
// Airport.cpp
#include <iostream>
#include <string>
#include "Flight.h"
#include "Airport.h"
using std::string;
using std::cout;
using std::cin;
using std::getline;
using std::endl;
Airport :: Airport(string inID, string inName) {
airportID = inID; // set airport id
airportName = inName; // set airport name
numFlights = 0; // Number of flight objects in array
// Initialise the array of flight objects
for (int i = 0; i < MAXFLIGHTS; i++) {
flights[i] = 0;
}
} // Airport
// Function to add a flight to the aiport.
int Airport :: addFlight(string inFlightID,
string inOrigin,
string inDestination,
string inDeparture,
string inArrival) {
// Check there is enough free space in the array to add new flight.
if (numFlights < MAXFLIGHTS) {
// add the flight object to the array of flights.
flights[numFlights] = new Flight(inFlightID,
airportID,
inDestination,
inDeparture,
inArrival);
numFlights++; // increment flight counter.
return 0; // flight added, return no error.
}
else {
return -1; // no space to add flight. return error.
}
} // addFlight
// Function to get the aiport id
string Airport :: getAirportID() {
return airportID;
}
string Airport :: getAirportName() {
return airportName;
}
// Function to return a formatted string containing flight details
string Airport :: getFlightDetails(string inFlight) {
string retval; // string to store formatted return value
for (int i = 0; i < MAXFLIGHTS; i++) {
// Is the object blank?
if (flights[i] == 0) {
break; // Flight not found
}
// Is the current flight the one being searched for?
else if (flights[i]->getFlightID() == inFlight) {
retval = flights[i]->getFlightID() + '\n'
+ flights[i]->getFlightOrigin() + '\n'
+ flights[i]->getFlightDestination() + '\n'
+ flights[i]->getFlightDeparture() + '\n'
+ flights[i]->getFlightArrival() + '\n';
// found the flight, so return the formatted string.
return retval;
}
}
// ERROR! If reach here, no such flight was found. return error msg
return "ERROR! No such flight exists!\n";
}
Flight.h
Code:
// Flight.h
#include <string>
using std::string;
class Flight {
private:
// Class Variables
string id;
string origin;
string destination;
string departure;
string arrival;
public:
// Class Methods
string getFlightID();
string getFlightOrigin();
string getFlightDestination();
string getFlightDeparture();
string getFlightArrival();
void setDeparture(string);
void setArrival(string);
// Constructor Prototype
Flight(string, string, string, string, string);
};
Flight.cpp
Code:
// Flight.cpp
#include <string>
using std::string;
class Flight {
private:
class Flight {
private:
// Class Variables
string id;
string origin;
string destination;
string departure;
string arrival
public:
// Class Methods
string getFlightID();
string getFlightOrigin();
string getFlightDestination();
string getFlightDeparture();
string getFlightArrival();
void setFlightDeparture(string);
void setFlightArrival(string);
// Constructor Prototype
Flight(string, string, string, string, string);
}; // class Flight
Flight :: Flight(string inID, string inOrigin, string inDestination, string inDe
parture, string inArrival){
id = inID;
origin = inOrigin;
destination = inDestination;
departure = inDeparture;
arrival = inArrival;
} // Flight constructor
// function to get the flight id number
string Flight :: getFlightID() {
return id;
}
// function to get the flight origin
string Flight :: getFlightOrigin() {
return origin;
}
// function to get the flight destination
string Flight :: getFlightDestination() {
return destination;
}
// function to get the flight departure time
string Flight :: getFlightDeparture() {
return departure;
}
// Function to get the flight arrival time
string Flight :: getFlightArrival() {
return arrival;
}
// Function to set the flight depature time - maybe delay
void setFlightDeparture(string inData) {
depature = inData;
}
// Function to set the flight arrival time - maybe delay
void setFlightArrival(string inData) {
arrival = inData;
}
Application.h
Code:
class Application {
private:
static const int MAXAIRPORTS = 100;
Airport * airports[MAXAIRPORTS];
int numAirports;
public:
// Class methods
void addAirport();
void selectAirport();
// constructor for application
Application();
} // class Application
Application.cpp
Code:
// Application.cpp
#include <iostream>
#include <string>
#include "Airport.h"
#include "Application.h"
using std::string;
using std::cout;
using std::cin;
using std::getline;
using std::endl;
Application :: Application() {
} // Constructor
// Function to add an airport object to the application
void Application :: addAirport() {
cout << "add airport" << endl;
}
// Function to select an existing airport in the application
void Application :: selectAirport() {
cout << "select airport" << endl;
}
int main() {
int input;
bool active = true, isError = true;
Application myApplication; // create a user Application class
while (active) { // loop whilst user does not want to quit
while (isError) { // Loop whilst an invalid choice
cout << " - AIRPORT SYSTEM - " << endl;
cout << " 1. Add Airport" << endl;
cout << " 2. Select Airport" << endl;
cout << " 3. Quit Application" << endl;
cin << input;
switch(input) {
case 1: // Add airport
myApplication.addAirport();
isError = false;
break;
case 2: // Select airport
myApplication.selectAirport();
isError = false;
break;
case 3: // quit
isError = false;
break;
default:
cout << "ERROR! Invalid Input! Try Again!" << endl;
} // switch
} // while(isError)
} // while(active)
return 0; // finished program
}
Well... The deadline for this coursework has passed, I have handed in the above, looks like a resit for me! ...not bothered cause spend all my time doing the device driver coursework for a ported linux installation and it was pretty sweet! ...Well; any help much appriciated cause i don't have a clue what im doin ni C++ and it will help for my resit coursework in July! Cheers!