Completely lost on my big program about flights

I'm writing a very large program (compared to any of the work I've ever done or seen before). What my job is to do is just write 5 or 6 functions that I'm severely struggling with because the rest of the code is not my own.

The objective here is to write a program about booking/searching for/and checking for flights. All of the data is read in from a text file and I feel like I'm pretty close on the first function which is simply just reading in the information from the text file.

I feel I'm close on the function that reads in the data. I've never done anything like this before. It's an array of classes and classes are definitely a weakness of mine but I've been reading a lot in the reference section on here ever since my first CS class in the fall of 2011.

Anyway if someone could skim over my code I'd really appreciate it, this program has created a tremendous amount of stress.

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
.
// flightUtil.cpp
// handling an array of objects of class 'Flight'

#include <iostream>
#include <fstream>
#include "Flight.h"
#include "flightUtil.h"
using namespace std;

////////////////////////////////////////
// 'readFlights' reads flight info from file 'flightFile'
//     into array 'flights' of objects of class Flight
// SENTINEL in airline position terminates the info
// returns number of read flights
// exits program if 'flightFile' not opened

int readFlights(Flight flights[], ifstream & flightFile)
{
    //ifstream in;
    //ofstream out;

    string      airline, orig, dest;
    int         nFlights=0, flightNum, seats;
    float       price;
        
	 


flightFile.open("flights.txt", ifstream::in);
   if (flightFile.is_open())
  { 
    while (flightFile.good() )
    {
	flightFile >> airline; 
		flights[nFlights].set_airline(airline);
	flightFile >> flightNum; 	
		flights[nFlights].set_flightNum(flightNum);
	flightFile >> orig; 	
		flights[nFlights].set_orig(orig);
	flightFile >> dest; 	
		flights[nFlights].set_dest(dest);
	flightFile >> price; 	
		flights[nFlights].set_price(price);
	flightFile >> seats; 	
		flights[nFlights].set_seats(seats); 
      nFlights++;
      
    }
    flightFile.close();
  }

  else {
	cout << "Unable to open file"; 
	return 1; }
	
	return nFlights;
  
}  


////////////////////////////////////////
// 'printFlight' displays one flight information on one line

void printFlight(const Flight & flight)
{
    cout << flight.get_airline() << "   " << flight.get_flightNum() << "   " << flight.get_orig() << "   " << flight.get_dest() << "   " << flight.get_price() << "   " << flight.get_seats() << endl;
}



And the errors....
Undefined first referenced
symbol in file
main /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.1.1/crt1.o
Flight::set_orig(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)/var/tmp//cc9phGa5.o
Flight::get_dest() const /var/tmp//cc9phGa5.o
Flight::get_seats() const /var/tmp//cc9phGa5.o
Flight::get_orig() const /var/tmp//cc9phGa5.o
Flight::get_flightNum() const /var/tmp//cc9phGa5.o
Flight::get_airline() const /var/tmp//cc9phGa5.o
Flight::set_flightNum(int) /var/tmp//cc9phGa5.o
Flight::set_seats(int) /var/tmp//cc9phGa5.o
Flight::set_dest(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)/var/tmp//cc9phGa5.o
Flight::set_price(float) /var/tmp//cc9phGa5.o
Flight::get_price() const /var/tmp//cc9phGa5.o
Flight::set_airline(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)/var/tmp//cc9phGa5.o
swap(int&, int&) /var/tmp//cc9phGa5.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


Thanks. ANY information is helpful.
Hello, skatingrocker17.

By reading your errors, it appears as though your linker cannot find the definitions of the listed functions.

The .O (object file) files are the object files that're created when the source file is compiled. Object files contain a structure what's named a Symbol table. The symbol table is a table that basically translates identifiers (in this case, function identifiers) so that the linker can understand it. It also contains the variable and function type-specifiers along with definitions (functions only, and possibly static class data members). However, the definitions of your functions are not within any of the symbol tables.

have you defined your functions appropriately?
Last edited on
Whoever wrote the rest of the program did that. Would it be helpful to see the class.

Thanks though I didn't know most of that information.
Yes, could you please post the contents of both headers, if it's not too much trouble. Instead of creating a large post, could you use this link: http://pastebin.com/
Last edited on

http://pastebin.com/UHxH0SXq Class Header
http://pastebin.com/jmTLfd0U Class Definitions
http://pastebin.com/3Up6wUx2 Not sure what to call this, this calls the functions.

No trouble at all, thanks for your time.
All your definitions seem to be there. Is your Flight.cpp source file part of the project? If it isn't, it won't be compiled, thus, the definitions within it won't be included into the symbol table.
Last edited on
Wow now that you just said that suddenly reminded me that I'VE ONLY BEEN COMPILING THE ONE FILE THAT I'VE BEEN WORKING ON. I've been writing the same function for an entire week. Duh....

Thank you so much for reminding me.
Topic archived. No new replies allowed.