hmm... I'm not a real programmer (a lot of people can help you better than me) however I can give you a suggestion and underline a great error in the concept of your source code.
Suggestion:
You are trying to create a sort of Database of airplanes, anyone with this own places, name and structure, but all with similar structure.
In this case, instead of using a lot of parameters in main, it is better to use objects for example:
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 69 70 71
|
class DayTime {
int _hour;
int _min;
public:
void setTime(int, int);
int hour() const;
int min() const;
};
void DayTime::setTime(int a, int b) {
_hour = a;
_min = a;
}
int DayTime::hour() const {
return _hour;
}
int DayTime::min() const {
return _min;
}
//-------
class Places {
std::vector <int> _place;
int _rows;
int _columns;
public:
Places(int, int);
~Places();
int getPlace(int, int) const;
void setPlace(int, int, int);
};
Places::Places (int rows, int columns) {
_rows = rows; _colums = columns;
if(_rows <= 0) _rows = 1; //at least 1 row
if(_colums <=0) _colums = 1; //at least 1 column
for (int a = 0; a < (_rows * _columns); a++) _place.push_back(0); //set single place to 0
}
Places::~Places() {
_place.clear(); //delete std::vector at destruction
}
int getPlace(int row, int colum) const {
if(row > (_rows-1) || colum > (_colums -1) ) return -1; //return -1 if row or colums is out of size
int index = row + (colum * _rows);
return _place[index];
}
void setPlace(int row, int colum, int value) {
if(row < _rows && colum <_colums) { //only if row and column under limits
int index = row + (colum * _rows);
_place[index] = value;
}
}
//-------
class Fly {
DayTime _leaveAt;
DayTime _travelTime;
std::string _fNum;
std::string _aircraft;
Places *places;
...
}
etc
|
My example can contain errors or can be bad (not tested and I'm not a programmer, as I said) but however can show you some things.
First of all I use a class DayTime for time of fly (this can be useless) so you can have only a var for a time (duration and time of leaving). With objects you can add other features (like showing DayTime as "hh:mm" or other nice things).
The second class is most important: Places.
Now I explain your greatest error in your source code;
you declared an array int place [var] [var]; with an unitialized var. This is an error. This is not a way to decide the size of an array. I suggest you to read something about dinamic memory allocation.
In my example I created a class Place.
The class place use a std::vector (but seeing my example, I could simply use a pointer and the "new" kwyowrd in that case.... I used std::vector only to suggest you also to take a look at std::vector if you don't know it).
Place must be initialized with number of rows and colums. Once a Place object is created it cannot be resized (seeing the fact that an airplain model have always the same places). if you want to be allowed to resize object place you have to change compleately the code.
In my example place class contains an internal buffer (_place) that contains all places. Once created _place is called like a one-dimension array (I didn't use a bidimensional dinamic allocation becouse it is too complex for simply example). In this way the internal buffer has only one index. But, however, the user of the class can find the place setting the row and the colum where the place is located. With getPlace(int, int) you can obtain the int value of the place (x, y) [x and y are both from 0 to total-1]. with setPlace(int, int, int value) you can set place (x, y) to the value "value".
the class calculates internally the internal index using row and colum as parameters and returns (or modify) the relative value.
in the class fly, as you said, Place is defined as a pointer. Infact you have to inizialize it as a pointer.
Example
|
places = new Places (5,4); //create a new object Places with 5 rows and 4 colums
|
and you have to remember to delete it on destructor
--------
however take my code only as example to understand what I'm trying to explain to you. Probably my code can be not correct and surely can be written better. It is only a try to explain your error and how you can use objects in your project