Modifying object data in linked list

I'm having a problem trying to modify my patient's data. It seems to work, but once the block of code ends it does not save to the linked list.
Problem located in case M.

linked list template header: http://pastebin.com/a94wdeYB
patient header: http://pastebin.com/P2G9psze
patient implementation: http://pastebin.com/aDfpXQEe

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
#include <iostream>
#include "listTemplate.h"
#include "PatientRecord.h"

using namespace std;

char menu()
{
	char input;
	cout << "Please enter your one letter choice as follows:" << endl;
	cout << "  A:  Add patient to list\n";
	cout << "  R:  Retrieve a patient record\n";
	cout << "  D:  Delete a patient record\n";
	cout << "  M:  Modify a patient record\n";
	cout << "  P:  Print all patient information\n";
	cout << "  Q:  Quit this program\n";
	cin >> input;

	return input;
}
void print(List<PatientRecord> list)
{	

	list.goToStart();
	while (!list.isAtEnd())
	{
		cout << list.CurrentItem().getId() << ", " << list.CurrentItem().getFirstName() 
			<< ", " << list.CurrentItem().getLastName() << ", " << list.CurrentItem().getBirthday() << endl;
		list.goToNext();
	}
}
bool find(List<PatientRecord> list, int idNum)
{
	list.goToStart();
	while (!list.isAtEnd())
	{
		if (list.CurrentItem().getId() == idNum)
		{
			cout << list.CurrentItem().getId() << ", " << list.CurrentItem().getFirstName() 
				<< ", " << list.CurrentItem().getLastName() <<  ", " << list.CurrentItem().getBirthday() << endl;
			return true;
		}
		else
			list.goToNext();
	}
	return false;
}
bool findDelete(List<PatientRecord> & list, int idNum)
{
	char input = NULL;
	list.goToStart();
	while (!list.isAtEnd())
	{
		if (list.CurrentItem().getId() == idNum)
		{
			cout << list.CurrentItem().getId() << ", " << list.CurrentItem().getFirstName() 
				<< ", " << list.CurrentItem().getLastName() << ", " << list.CurrentItem().getBirthday() << endl;
			list.deleteCurrentItem();
			return true;
		}
		else
			list.goToNext();
	}
	return false;
}

int main()
{
	string first, last;
	int value = 0, id = 0, month = 0, day = 0, year = 0;
	char input = NULL;
	PatientRecord patient;
	List<PatientRecord> list1;

	do
	{
		input = menu();
		switch(input)
		{
		case 'A':
		case 'a':
			{
				cout <<"Enter ID number, first name, and last name." << endl;
				cin >> id >> first >> last;
				cout << "Enter birthday in the following format - mm dd yyyy: " << endl;
				cin >> month >> day >> year;
				Date bday(month, day, year);

				patient.setFirstName(first).setLastName(last).setId(id).setBirthday(bday);
				list1.insert(patient);
			}
			cout << endl;
			break;
		case 'R':
		case 'r':
			cout << "Enter ID number to retrieve: ";
			cin >> id;

			if (!find(list1, id))
			{
				cout << "Not found.";
			}
			cout << endl;
			cout << endl;
			break;
		case 'D':
		case 'd':
			cout << "Enter ID number to delete: ";
			cin >> id;
			
			if (!findDelete(list1, id))
			{
				cout << "Patient not found.";
			}
			cout << endl;
			break;
		case 'M':
		case 'm':
			cout << "Enter ID number to modify: ";
			cin >> id;

			list1.goToStart();
			while (!list1.isAtEnd())
			{
				if (patient.getId() == id)
				{
					cout << patient.getId() << ", " << patient.getFirstName() 
						<< ", " << patient.getLastName() << ", " << patient.getBirthday() << endl;
					cout << "Enter new name: ";
					cin >> first;
					patient.setFirstName(first);
					break;
				}
				else
					list1.goToNext();
			}
	
			cout << endl;
			break;
		case 'P':
		case 'p':
			if (!list1.isEmpty())
			{
				print(list1);
			}
			else
			{
				cout << "List is empty.";
			}
			cout << endl;
			break;
		case 'Q':
		case 'q':
			break;
		default:
			cout << "Invalid choice. Enter A, D, M, P, or Q." << endl;
		}
	} while (!((input == 'Q') || (input == 'q')));

	return 0;
}
The variable patient on line 72 is not related to list1, so if you modify patient it will not have an affect to list1. Use CurrentItem() (or similar) instead
Topic archived. No new replies allowed.