FILE HANDLING (patient file system)

Please help!! The program doesn't run and i've tried to compare it to some forums i've searched here but still doesn't seem to fix the problem...

here is the complete code of the program:

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
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

struct file{
	int fnum;
	char fname[50], lname[50];
	char cnum[50];
	int balance, total;
};

file f;
//int i, list,ans, searchnum, delnum, x, y;
int ans, list, i, searchnum;
int cons, es, minsur, majsur;
char others[50], name[50], yon, noy;
int pay, oprice, balpaid;

void newLine();
void line(char, int);
void procedure2();
void procedure();
void addfile();



int main()
{
	ofstream fout;
	fout.open("d:\\hayamieyecenter.txt");
	int choice, list=1;
	f.total=0;
	while(1){
		system("cls");
	cout << endl;
	cout << "Welcome to Hayami Eye Specialist Center";
	cout << "\n" << endl;
	line('=',40);
	cout << "            1. Add New File            \n";
	cout << "            2. Edit File              \n";
	cout << "            3. Search File             \n";
	cout << "            4. Delete File             \n";
	cout << "            5. View Files              \n";
	cout << "            6. Exit                \n";
	line('=',40);
	cout << endl;
	cout << "What would you like to do? ";
	cin >> choice;
	switch (choice)
	{
		case 1: //file cannot be saved
			system("cls");
			addfile();
			cout << "ADD NEW FILE\n";
			line ('-', 26);
			cout << "Enter Patient Information:\n";
			cout << "File Number " << setprecision(3) << list;
			cout << "\nFirst Name: ";
			cin.getline(f.fname,50);
			newLine();
			cout << "Last Name: ";
			cin.getline(f.lname,50);
			cout << "Contact Number: ";
			cin >> f.cnum;
			cout << endl;
			procedure();
			//addfile();
			break;
		case 2:
			system("cls");
			cout << "EDIT FILE\n";
			line ('-', 25);
			cout << "Enter File # to Edit: ";
			cin >> i;
			//ofstream fout;
			//fout.open("d:\\hayamieyecenter.txt");
			newLine();
			if (i=list)
			{
			cout << "Edit First Name: ";
			cin.getline(f.fname,50);
			cout << "Edit Last Name: ";
			cin.getline(f.lname,50);
			cout << "Edit Contact Number: ";
			cin >> f.cnum;
			cout << "Balance: " << f.balance << "\nEnter amount to be paid: ";
			cin >> balpaid;
			f.balance-=balpaid;
			cout << "are there more transactions made (Y/N) ? " << endl;
			cin >> yon;
			if (yon =='y'||yon =='Y')
				procedure2();
			if (yon == 'n'||yon == 'N')
				break; 
			}
		        break;
	        case 3:
			/*ofstream fout;
			fout.open("d:\\hayamieyecenter.txt");*/
			system("cls");
			cout << "SEARCH FILE\n";
			line ('-', 25);
			cout << "1.First Name\n";
			cout << "2.Last Name\n";
			cout << "3.Contact Number\n";
			cout << "Select a number to search: ";
			cin >> searchnum;
				switch (searchnum){
						case 1:
						cout << "Enter First Name to be searched: ";
								cin.getline(name,50);
								/*for (int a=0;a<=list;a++)
								{*/
									if (name == f.fname)
									{
									cout << endl;
									cout << "  " << list << setw(15);
									cout << f.fname << setw(25);
									cout << f.lname << setw(25);
							cout << f.cnum;
				/*}*/
			}
			break;
													
				case 2:
				cout << "Enter Last Name to be searched: ";
				cin.getline(name,50);
				/*for (int a=0;a<=list;a++)
				{*/
				if (name == f.lname)
				{
					cout << endl;
					cout << "  " << i + 1 << setw(15);
					cout << f.fname << setw(25);
					cout << f.lname << setw(25);
					cout << f.cnum;
					}
					//}
				break;
											
				case 3:
				cout << "Enter Contact Number to be searched: ";
				cin.getline(name,50);
				/*for (int a=0;a<=list;a++)
				{*/
				if (name == f.cnum)
				{
					cout << endl;
					cout << "  " << i + 1 << setw(15);
					cout << f.fname << setw(25);
					cout << f.lname << setw(25);
					cout << f.cnum;
				}
				//}
				break;
			default:
			cout << "Invalid choice";
			system("pause>0");
			}
			break;
		ofstream fout;
		fout.open("d:\\hayamieyecenter.txt");
		system("cls");
			cout << "DELETE FILE\n";
			line ('-', 25);
	bool is_ok = false;
	while(! is_ok)
	{
	cout << "\nSelect a file number to delete: ";
	cin >> delnum;

	if (delnum > list)
		cout << "The file number does not yet exist";
	else
		break;
	}
		y = delnum -1;
		
			cin.clear();
			cin.ignore();
			cout << endl;
			cout << "  " << y + 1 << setw(15);
			cout << f[y].fname << setw(25);
			cout << f[y].lname << setw(25);
			cout << f[y].cnum;
			cout << "Are you sure (Y/N)? ";
			cin >> noy;
			if (noy == 'y' || noy == 'Y')
			{
				for (int x=y; x<list; x++)
				{
					f[x].fname = f[x+1].fname;
				f[x].lname = f[x+1].lname;
					f[x].cnum = f[x+1].cnum;
					f[x].balance = f[x+1].balance;
					f[x].total =  f[x+1].total;
				}
				--list;
				ofstream fout;
				fout.open("d:\\hayamieyecenter.txt");
				/*for (int x = 0; x <list; x++)
				{
					fout << f[x].fname << "," <<f[x].lname << "," << 
				}*/
			}

		system("pause>0");
		break;
	case 5:
		ofstream fout;
		fout.open("d:\\hayamieyecenter.txt");
		system("cls");
			cout << "FILE DIRECTORY\n";
			line ('-', 80);
			system("COLOR 5");
			cout << "File No." << setw(15)
			<< "First Name" << setw(25)
			<< "Last Name" << setw(25)
			<< "Contact No."
			<<endl;
			line('-', 80);

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	for (int x=0; x < list; x++){
		cout << endl;
		cout << "  " << i + 1 << setw(15);
		cout << f[x].fname << setw(25);
		cout << f[x].lname << setw(25);
		cout << f[x].cnum << endl;
		cout << "Transaction: " << setw(40);
		cout << f[x].total << setw(15);
		cout << "Balance: " << f[x].balance;
	}
	system("pause>0");

		break;
		case 6:
			exit(1);
		default:
			cout << "Invalid choice, please try again: ";
			system("pause>0");
	} //choice
	} //while(1)
} //int main()

void procedure()
{
	cons = 3000;
	es = 4000;
	minsur = 60000;
	majsur = 800000;
	cout << "1. Consultation\n";
			cout << "2. Eye Screening\n";
			cout << "3. Minor Surgery\n";
			cout << "4. Major Surgery\n";
			cout << "5. Others\n";
			cout << "Select a Procedure: ";
			cin >> ans;
			switch (ans){
			case 1:
				cout << "Price: " << cons;
				f.total+=cons;
				break;
			case 2:
				cout << "Price" << es;
				f.total+=es;
				break;
			case 3:
				f.total+=minsur;
				cout << "Price" << minsur;		
				break;
			case 4:
				f.total+=majsur;
				cout << "Price" << majsur;
				break;
			case 5:
				cout << "Please Enter the desired procedure: ";
				cin.getline(others,50);
				cout << "Price: ";
				cin >> oprice;
				f.total+=oprice;
			default:
				cout << "Invalid choice";
				system("pause>0");
			}
			
			cout << "\nTotal Price:" << f.total << endl;
			cout << "Payment: ";
			cin >> pay;
			if (pay < f.total) {
				f.balance+=f.total-pay;
			}
} //procedure()

void addfile()
{
	ofstream fout;
	fout.open("d:\\hayamieyecenter.txt");
	list++;
} //addfile


void line(char ch, int ctr)
{
	for (int i = 0; i < ctr; i++) {
		cout << ch;
	}
	cout << endl;
}

void newLine()
{
	char s; do{
		cin.get(s);
	} while (s != '\n');
}


Last edited on
You are attempting to change an unmodifiable l-value.

It's an l-value, but you cannot assign anything to it.

"==" would not work for this either. "==" is an equivalency statement. It checks whether the values it's equating are equal or not, it does not set values.
Topic archived. No new replies allowed.