Storing data in a double-linked list

Hi, was wondering if any of you guys could please help me out! I'm fairly new to this and I need to write a program where basically the user inputs data about aircraft and there should be functionality where the user can read previously input data and also delete data if required - those are the two parts where I'm lost. The specification says the data should be stored internally in a double linked list but I can't find any help anywhere :-( If anyone could help, it'd be hugely appreciated. Currently my program can "Enter a new aircraft"£ but it's not actually entering it anywhere. I'll post what I have in the program so far (in two posts) Any help would be HUGELY appreciated Thanks :-)

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;


void newAircraft();
void delAircraft();
void nextAircraft();
void prevAircraft();
void help();


int main()
{

int choice=0;

while(choice!=1)
	{
		system("cls"); //To clear the screen before displaying menu

		cout <<"-------------------------------"<< endl;
		cout <<" MoD Aircraft Information System "<< endl << endl;
		cout <<" 1. Exit the program "<< endl;
		cout <<" 2. Enter new aircraft "<< endl;
		cout <<" 3. Delete Aircraft "<< endl;
		cout <<" 4. Show next aircraft "<< endl;
		cout <<" 5. Show previous aircraft "<< endl;
		cout <<" 6. Help "<<endl;
		cout <<"-------------------------------"<<endl << endl;
		cout <<"Type in a number of your choice: ";
		cin  >> choice;
		cout << endl << endl;


		switch(choice)
		{
			case 1: //Exit program
			system("cls");
			cout <<"Program exiting."<<endl;
			break;

			case 2: //Enter new aircraft
				newAircraft();
			break;

			case 3: //Delete aircraft
				delAircraft();
			break;

			case 4: //Show next aircraft
				nextAircraft();
			break;

			case 5: //Show previous aircraft
				prevAircraft();
			break;

			case 6: //Help file
				help();
			break;

			default:
			cout << "Invalid input." << endl;
			system("PAUSE"); //To allow user to press a key to continue, rather than clearing screen and going to the menu straight away
		}
	}

return 0;
}



void newAircraft()
{

//////////newAircraft///////////////////////////////////////
const int AIRCRAFT_Registration_Number = 3;
typedef string database[AIRCRAFT_Registration_Number];
const int AIRCRAFT_Manufacturer = 3;
typedef string database[AIRCRAFT_Manufacturer];
const int AIRCRAFT_Serial = 3;
typedef string database[AIRCRAFT_Serial];
const int AIRCRAFT_Production_Date = 3;
typedef string database[AIRCRAFT_Production_Date];
const int AIRCRAFT_Owner = 3;
typedef string database[AIRCRAFT_Owner];
const int AIRCRAFT_Max_Speed = 3;
typedef string database[AIRCRAFT_Max_Speed];
const int AIRCRAFT_Min_Speed = 3;
typedef string database[AIRCRAFT_Min_Speed];
const int AIRCRAFT_Max_Climb_Rate = 3;
typedef string database[AIRCRAFT_Max_Climb_Rate];
const int AIRCRAFT_Type = 3;
typedef string database[AIRCRAFT_Type];
const int HELICOPTER_Max_Speed = 3;
typedef string database[HELICOPTER_Max_Speed];
const int HELICOPTER_Max_Height = 3;
typedef string database[HELICOPTER_Max_Height];
const int HELICOPTER_Climb = 3;
typedef string database[HELICOPTER_Climb];
int counter;
///////////////////////////////////////////////////////////

	//short database[8];
	database aircraftRegistration_Number;
	database aircraftManufacturer;
	database aircraftSerial;
	database aircraftProduction_Date;
	database aircraftOwner;
	database aircraftMax_Speed;
	database aircraftMin_Speed;
	database aircraftMax_Climb_Rate;
	database aircraftType;
	database helicopter_Max_Speed;
	database helicopter_Max_Height;
	database helicopter_Climb;


	{
	 counter = 0;


		system("cls");

		cout << "Choose which type of aircraft you want to enter. " << endl;
		cout << "Or press 3 to return to the main menu. " << endl << endl;
		cout << "1 - Fixed Wing" << endl;
		cout << "2 - Helicopter" << endl;
		cout << "3 - Return to Main Menu" << endl << endl;

       int startingchoice;


	   cout << "Choice: ";	
       cin  >> startingchoice;
	   cout << endl << endl;

		system("cls");

	   while (startingchoice != 3)
	   {
		
		

       int i;
       for (i = 0; i < 1; i++)
		
		switch (startingchoice){ //START
          
		default:
		cout << "Invalid input." << endl;
		system("PAUSE");
		return;

		system("PAUSE");

		case 1: // Fixed Wing Choice

		counter++;
		{
		cout << "Enter the Registration Number: ";
		cin  >> aircraftRegistration_Number[0];
		}

				
		{
		cout << "Enter the Manufacturers Name: ";
		cin  >> aircraftManufacturer[0];
		}

	
		{
		cout << "Enter the Serial Number: ";
		cin  >> aircraftSerial[0];
		}

		
		{
		cout << "Enter the Production Date: ";
		cin  >> aircraftProduction_Date[0];
		}

	
		{
		cout << "Enter the Owner: ";
		cin  >> aircraftOwner[0];
		}

		
		{
		cout << "Enter the Maximum Speed of the Aircraft: ";
		cin  >> aircraftMax_Speed[0];
		}

		
		{
		cout << "Enter the Minimum Speed of the Aircraft: ";
		cin  >> aircraftMin_Speed[0];
		}

		
		{
		cout << "Enter the Maximum Height the aircraft can climb: ";
		cin  >> aircraftMax_Climb_Rate[0];
		}

		
		{
		cout << "Enter the type of aircraft: ";
		cout << "Glider, Jet or Propelled: ";
		cin  >> aircraftType[0];
		}

		{

		system("cls");

		cout << "Record : " << counter << endl;
		cout << "Aircraft registration number: " << aircraftRegistration_Number[0] << endl;
		cout << "Manufacturers name: " << aircraftManufacturer[0] << endl;
		cout << "Aircraft serial number: " << aircraftSerial[0] << endl;
		cout << "Production date of the aircraft: " <<aircraftProduction_Date[0] << endl;
		cout << "Owner of the aircraft: " << aircraftOwner[0] << endl;
		cout << "Max speed: " << aircraftMax_Speed[0] << endl;
		cout << "Min speed: " << aircraftMin_Speed[0] << endl;
		cout << "Max climb rate: " << aircraftMax_Climb_Rate[0] << endl;
		cout << "Aircraft type: " << aircraftType[0] << endl;
		
		system("PAUSE");
		return;
		break;
					
              
	   
	   }
		
		{
			
				case 2: // Helicopter Choice

					counter++;
					
					{
						cout << "Enter the Registration Number: ";
						cin  >> aircraftRegistration_Number[1];
					}

					{
						cout << "Enter the Manufacturers Name: ";
						cin  >> aircraftManufacturer[1];
					}

		
					{
						cout << "Enter the Serial Number: ";
						cin  >> aircraftSerial[1];
					}

					
					{
						cout << "Enter the Production Date: ";
						cin  >> aircraftProduction_Date[1];
					}

				
					{
						cout << "Enter the Owner: ";
						cin  >> aircraftOwner[1];
					}

					{
						cout << "Enter the Maximum Speed of the Helicopter: ";
						cin  >> helicopter_Max_Speed[0];
					}

					{
						cout << "Enter the Maximum Vertical Height of the Helicopter: ";
						cin  >> helicopter_Max_Height[0];
					}
					
					{
						cout << "Enter the Maximum Climb Rate of the Helicopter: ";
						cin  >> helicopter_Climb[0];
					}

					{

					system("cls");


					cout << "Record : " << counter << endl;
					cout << "Aircraft registration number: " << aircraftRegistration_Number[1] << endl;
					cout << "Manufacturers name: " << aircraftManufacturer[1] << endl;
					cout << "Aircraft serial number: " << aircraftSerial[1] << endl;
					cout << "Production date of the aircraft: " <<aircraftProduction_Date[1] << endl;
					cout << "Owner of the aircraft: " << aircraftOwner[1] << endl;
					cout << "Max speed: " << helicopter_Max_Speed[0] << endl;
					cout << "Max height: " << helicopter_Max_Height[0] << endl;
					cout << "Max Climb: " << helicopter_Climb[0] << endl;

					
					system("PAUSE");
					return;
					break;
					}

					
		}

		
				

	

		}

	}
}
 }
Last edited on
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

void delAircraft()
{
	system("cls");

	cout << "Aircraft entry deleted" << endl;

	system("PAUSE");
}

void nextAircraft()
{

//////////newAircraft///////////////////////////////////////
const int AIRCRAFT_Registration_Number = 3;
typedef string database[AIRCRAFT_Registration_Number];
const int AIRCRAFT_Manufacturer = 3;
typedef string database[AIRCRAFT_Manufacturer];
const int AIRCRAFT_Serial = 3;
typedef string database[AIRCRAFT_Serial];
const int AIRCRAFT_Production_Date = 3;
typedef string database[AIRCRAFT_Production_Date];
const int AIRCRAFT_Owner = 3;
typedef string database[AIRCRAFT_Owner];
const int AIRCRAFT_Max_Speed = 3;
typedef string database[AIRCRAFT_Max_Speed];
const int AIRCRAFT_Min_Speed = 3;
typedef string database[AIRCRAFT_Min_Speed];
const int AIRCRAFT_Max_Climb_Rate = 3;
typedef string database[AIRCRAFT_Max_Climb_Rate];
const int AIRCRAFT_Type = 3;
typedef string database[AIRCRAFT_Type];
const int HELICOPTER_Max_Speed = 3;
typedef string database[HELICOPTER_Max_Speed];
const int HELICOPTER_Max_Height = 3;
typedef string database[HELICOPTER_Max_Height];
const int HELICOPTER_Climb = 3;
typedef string database[HELICOPTER_Climb];

///////////////////////////////////////////////////////////


	database aircraftRegistration_Number;
	database aircraftManufacturer;
	database aircraftSerial;
	database aircraftProduction_Date;
	database aircraftOwner;
	database aircraftMax_Speed;
	database aircraftMin_Speed;
	database aircraftMax_Climb_Rate;
	database aircraftType;
	database helicopter_Max_Speed;
	database helicopter_Max_Height;
	database helicopter_Climb;

int counter;
counter = 1;

	if (counter == 1)
		{

		system("cls");


		cout << "Record : " << counter << endl;
		cout << "Aircraft registration number: " << aircraftRegistration_Number[0] << endl;
		cout << "Manufacturers name: " << aircraftManufacturer[0] << endl;
		cout << "Aircraft serial number: " << aircraftSerial[0] << endl;
		cout << "Production date of the aircraft: " <<aircraftProduction_Date[0] << endl;
		cout << "Owner of the aircraft: " << aircraftOwner[0] << endl;
		cout << "Max speed: " << aircraftMax_Speed[0] << endl;
		cout << "Min speed: " << aircraftMin_Speed[0] << endl;
		cout << "Max climb rate: " << aircraftMax_Climb_Rate[0] << endl;
		cout << "Aircraft type: " << aircraftType[0] << endl;
		cout << "Max speed: " << helicopter_Max_Speed[0] << endl;
		cout << "Max height: " << helicopter_Max_Height[0] << endl;
		cout << "Max Climb: " << helicopter_Climb[0] << endl;
		

	

		system("PAUSE");
              
	   }

	

	
}

void prevAircraft()
{
	system("cls");

	cout << "Show previous aircraft would occur here" << endl;

	system("PAUSE");
}

void help()
{

		system("cls");	

		cout << " ---------------------------------Help File------------------------------ " << endl;
		cout << endl;
		cout << " Welcome to the Ministry of Defence database. " << endl << endl;
		cout << " Here you can choose to perform a number of different options from the " << endl;
		cout << " main menu that appears at the start. " << endl;
		cout << endl;
		cout << " 1 - Exit the program " << endl;
		//cout << endl;
		cout << " Exits the Ministry of Defence Database. " << endl;
		//cout << endl;
		cout << " 2 - Enter new aircraft " << endl;
		//cout << endl;
		cout << " Gives you a number of different options, aiding you to create a new entry " << endl;
		cout << " into the Database. " << endl;
		//cout << endl;
		cout << " 3 - Delete aircraft " << endl;
		//cout << endl;
		cout << " Allows you to select a record, and then delete it from the database. " << endl;
		//cout << endl;
		cout << " 4 - Show next aircraft " << endl;
		//cout << endl;
		cout << " From here you can scroll to the next available record and view the entry. " << endl;
		//cout << endl;
		cout << " 5 - Show previous aircraft " << endl;
		//cout << endl;
		cout << " From here you can scroll to the previous record and view the entry. " << endl;
		//cout << endl;
		cout << " 6 - Help " << endl;
		//cout << endl;
		cout << " Displays this help file. " << endl;
		cout << endl;
		cout << " ------------------------------------------------------------------------ " << endl << endl;

	system("PAUSE");
}
Oh, what is this mess?
This requires the use of classes. You can't have your data just floating around!
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
template <class T>
struct Node{
	Node<T> *prev;
	T data;
	Node<T> *next;
	Node();
	Node(const Node<T> &a);
	Node(T a);
};

template <class T>
class List{
	Node<T> *beg;
	Node<T> *end;
	ulong size;
	//These two members are optional. They store the index and memory address of
	//the last referenced element to speed up successive seeks.
	ulong last;
	Node<T> *pLast;
public:
	List();
	~List();
	//Add a new element at the end of the list.
	void add(T a);
	//Get memory location (used mostly by other methods. Optional).
	Node<T> *gml(ulong a);
	//Insert a new element before index 'b'.
	void insert(T &a,ulong b);
	//Remove an element.
	void remove(ulong a);
	//Returns a reference to an element.
	T &at(ulong offset);
	//Return the size of the list.
	ulong len();
	//True if the list contains the parameter (optional).
	bool contains(T &a);
};
Thanks for this...as I said previously I'm pretty new to C++ so would this mean I have to completely re-write my code? I'm a bit lost :-s
Without looking really hard at your code, I'd say yes.
Yeah, your code is reallly messy and hard to read in that form Oo. Like helios said, use classes, maybe something like this:

1
2
3
4
5
6
7
8
9
10
11
class Plane {
   //plane data members
public:
   //functions to edit data members
}

class Helicopter {
   //Helicopter data members
public:
   //functions to edit data members
}


You can also just make all the members public and edit them directly, which is simpler, but more prone to errors (or bad data input).
Topic archived. No new replies allowed.