I am having trouble implement my first linked list

Specifically, I'm experiencing difficulties exploiting my node class to create a list of student objects that are described below. I understand that convention is to create a linked list class, although for this assignment I'm required to build a list using the following code plus an append and display function in my driver. I'm stuck on the driver file. I don't know how to implement the append function to add nodes. Anyway, thank you for your assistance!!!

here is my code hitherto:

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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
 * ---------------
 * Student Program
 * --------------
 * --------------
 *  Header File
 *****************
*/

#ifndef STUDENT_H
#define STUDENT_H

#include <iostream>
using namespace std;

class Student{

	friend istream &operator>>(istream &in, Student &x);
	friend ostream &operator<<(ostream &out, Student &x);

	private: 
		string fname,lname,ssn;
		char mi;
		int age;

	public:
		
		//
		//constructors	
		Student();
		Student(string fname, string lname, string ssn, char mi, int age);
		
		//
		//mutator methods
		void setFname(string fname);
		void setMi(char mi);
		void setLname(string lname);
		void setSSN(string ssn);
		void setAge(int age);
		
		//
		//accessor methods
		string getFname();
		char getMi();
		string getLname();
		string getSSN();
		int getAge();

		//
		//overloaded equal operator
		Student operator=(const Student &x);

		//
		//input and display functions
		void input(istream &in);
		void display(ostream &out);


};
#endif
/*
 * ---------------
 * Student Program
 * --------------
 * --------------
 *  Header File
 *****************
*/

#include "student.h"

	//////////////////
	//global methods//
	//////////////////
	
	istream &operator>>(istream &in, Student &x){

		x.input(in);

		return in;

	}
	
	ostream &operator<<(ostream &out, Student &x){

		x.display(out);
		
		return out;

	}

	/////////////////
	//class methods//
	/////////////////
	
	//
	//default constructor
	Student::Student(){

		fname = lname = ssn = "Not yet indicated";
		mi = 'Z';
		age = 00;

	}
	
	//
	//custom constructor
	Student::Student(string fname, string lname, string ssn, char mi, int age){
	
		Student::fname = fname;
		Student::lname = lname;
		Student::ssn = ssn;
		Student::mi = mi;
		Student::age = age;

	}

	//
	//mutator methods
	void Student::setFname(string fname){
		
		Student::fname = fname;

	}

	void Student::setLname(string lname){
		
		Student::lname = lname;	
	
	}

	void Student::setMi(char mi){
	
		Student::mi = mi;

	} 

	void Student::setSSN(string ssn){
	
		Student::ssn = ssn;
	
	}
	
	void Student::setAge(int age){
	
		Student::age = age;

	}

	//
	//accessor methods
	string Student::getFname(){
	
		return fname;

	}

	char Student::getMi(){
	
		return mi;

	}

	string Student::getLname(){

		return lname;

	}

	string Student::getSSN(){

		return ssn;

	}

	int Student::getAge(){
		
		return age;
		
	}

	//
	//overloaded equality method to set two student objects equal
	Student Student::operator=(const Student &x){

		fname = x.fname;
		mi = x.mi;
		lname = x.lname;
		ssn = x.ssn;
		age = x.age;
		
		return *this;

	}

	//
	//input and display methods
	void Student::input(istream &in){
	
		cout << endl;
		cout << "Please input your first name, your middle initial, and your last name: ";
		in >> fname >> mi >> lname;
		cout << "Please input your age: ";
		in >> age;
		cout << "Please input your social security number: ";
		cin >> ssn;
		cout << endl;

	}

	void Student::display(ostream &out){

		cout << "Name: " << fname << " " << mi << " " << lname;
		cout << endl << "Age: " << age << endl;
		cout << "SSN: " << ssn << endl << endl;

	}
/*
 * --------------
 * Node Program
 * --------------
 * --------------
 * Header File
 *****************
 */

#ifndef NODE_H
#define NODE_H

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

class Node{

	private:
		Student *sPtr;
		Node *next;

	public:
		//
		//constructors
		Node();
		Node(Student* s);
		Node(string fname,string lname,char mi,string ssn,int age);

		//
		//accessor and mutator methods
		Node *getNext();
		void setNext(Node *nPtr);

};
#endif
/*
 * --------------
 * Node Program
 * -------------
 * --------------
 * cpp File
 *****************
 */

#include "node.h"

	//
	//default constructor
	Node::Node(){
	
		sPtr = NULL;
		next = NULL;
	
	}

	//
	//copy constructor
	Node::Node(Student *s){

		sPtr = s;

	}

	//
	//copy constructor
	Node::Node(string fname,string lname,char mi,string ssn,int age){
	
		Student x;
	
		x.setFname(fname);
		x.setLname(lname);
		x.setMi(mi);
		x.setSSN(ssn);
		x.setAge(age);

		*sPtr = x;

	}

	//
	//mutator method to assign the next pointer
	void Node::setNext(Node *nPtr){
		
		next = nPtr;

	}

	//
	//accessor method to return the next pointer
	Node *Node::getNext(){
	
		return next;

	}
/*
 * ------------------------
 * Student and node Program
 * ------------------------
 * ------------------------
 *  driver file
 *************************
*/

#include "node.cpp"
#include "student.cpp"

	//
	//function prototypes
	Node append(Node *head, Node *nPtr);	
	void display();

int main(){


	//
	//list head and next pointer declarations and initialization
	Node *head = NULL;
	Node *nPtr = NULL;

	//
	//bool to return a true or false value according to the user's input
	bool input = true;	 

	cout << "Input \"add\" to save a student's information. If you wish to cease adding students, input 'q'" << endl;

	while(input == true){
		
		

	}


}

	Node append(Node *head, Node *nPtr){
	
		if(head == NULL){
			head = nPtr;
		}
	}
]0;--------@storm:~/CISC2200/node[-------@storm node]$ exit
exit
Last edited on
Is this thread special or am I wrong?
Keywords in code wrapped in [code] tags should be at least highlighted with a blue color.
Sorry, I'm not sure I follow. Did I do something incorrectly? I don't visit this site frequently.
Topic archived. No new replies allowed.