modification

I created this project for students to take a test and included file handling. The program works well but the problem is that when a student takes the test, the rest of the data in the file gets erased. code:
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
  Put 
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
#include<stdio.h>
int count=0,i,n=0;
class basic
{
public:
char name[30],fname[30],mname[30],ph[20],address[100];
int cid;
int score;
char dob[15];
basic()
{
score=0;
strcpy(name,"-");
cid=0;
strcpy(dob,"-");
}
};
class info:public basic
{
int ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10;
public:
void acc();
void eco();
void comp();
void input();
void display();
void test();
void scorer();
void scored();
}d,s[100];
void info::acc()
{
cout<<"PART A: ACCOUNTS:";
cout<<"\n1.In the absence of Partnership Deed, partners can claim for";
cout<<"\n1.Salary\n2.Interest on capital";
cout<<"\n3.Interest of loans and advances\n4.Distribution of profit in their capital ratio";
cout<<"\nAns:";
cin>>ch1;
cout<<"\n\n2.If the new partner is unable to bring his/her share of goodwill, then goodwill is adjusted by";
cout<<"\n1.Debiting Goodwill Account and crediting sacrificing Partner's Capital Account\n2.Debiting Goodwill Account and crediting all Partner's Capital Account in new ratio";
cout<<"\n3.Debiting sacrificing Partners Capital Account and crediting gaining Partners Capital Account\n4.Debiting gaining Partner's Capital Account and crediting sacrificing Partner's Capital Account";
cout<<"\nAns:";
cin>>ch2;
cout<<"\n\n3.Which of the following items is recorded on the debit side of Retiring Partner’s Capital Account?";
cout<<"\n1.Interest on Capital\n2.Interest on Drawings";
cout<<"\n3.Share of General Reserve\n4.Share of credit balance of Profit and Loss Account";
cout<<"\nAns:";
cin>>ch3;
cout<<"\n\n4.Which of the following accounts is credited to transfer profit on revaluation of assets and liabilities, if the Partner’s Capital Accounts is maintained by Fixed Method?";
cout<<"\n1.Revaluation Account\n2.Partner's Capital Account";
cout<<"\n3.Partner's Current Account\n4.Profit and Loss Appropriation Account";
cout<<"\nAns:";
}
void info::eco()
{
cout<<"\n\nPART B:ECONOMICS";
cout<<"\n5.Which of these statements is correct regarding the massive unemployment?";
cout<<"\n1.It is shown by a point inside the PPC.\n2.It leads to the leftward shift of the PPC.";
cout<<"\n3.It leads to the rightward shift of the PPC.\n4.It is represented by a point lying on the PPC.";
cout<<"\nAns:";
cin>>ch5;
cout<<"\n6.Which of the following degrees of price elasticity will be depicted by a vertical demand curve which is parallel to y-axis?";
cout<<"\n1.Elastic  \n2.Perfectly elastic";
cout<<"\n3.Inelastic  \n4.Perfectly inelastic";
cout<<"\nAns:";
cin>>ch6;
cout<<"\n7.Which of the following curves is an inverse S-shaped curve?";
cout<<"\n1.Average Cost \n2.Marginal Cost";
cout<<"\n3.Total Variable Cost\n4.Average Fixed Cost";
cout<<"\nAns:";
cin>>ch7;
cout<<"\n8.Which of the following characteristics is not correct for the demand curve faced by a firm under perfect competition?";
cout<<"\n1.Demand curve is elastic.\n2.Demand curve is downward sloping.";
cout<<"\n3.Demand curve coincides with MR curve.\n4.Demand curve depicts the price of product";
cout<<"\nAns:";
cin>>ch8;
}
void info::comp()
{
cout<<"\n\nPART C: COMPUTERS";
cout<<"\n9.In which visibility mode are data in structures, by default?";
cout<<"\n1.Private\n2.Protected\n3.Public\n4.None of the above";
cout<<"\nAns:";
cin>>ch9;
cout<<"\n10.Name the header file to which the function rand( ) belongs?";
cout<<"\n1.#include<stdlib.h>\n2.#include<iomanip.h>";
cout<<"\n3.#include<stdio.h>\n4.#include<fstream.h>";
cout<<"\nAns:";
cin>>ch10;
}
void info::scorer()
{
ofstream f;
f.open("pripoo.txt",ios::out);
if(ch1==3)
score=score+1;
if(ch2==4)
score+=1;
if(ch3==2)
score+=1;
if(ch4==3)
score+=1;
if(ch5==1)
score+=1;
if(ch6==4)
score+=1;
if(ch7==3)
score+=1;
if(ch8==2)
score+=1;
if(ch9==3)
score+=1;
if(ch10==1)
score+=1;
f<<score;
f.close();
}
void info::scored()
{
ifstream f;
f.open("pripoo.txt",ios::in);
f>>score;
cout<<"\n\tScore:"<<score;
}
void info::input()
{
clrscr();
cout<<"\n\n\t\tEntering a new student!";
ofstream f;
f.open("pripoo.txt",ios::app);
cout<<"\n\n\tEnter details of student!";
cout<<"\n\t-------------------------\n";
cout<<"\n\tEnter Name:";
gets(name);
cout<<"\n\tEnter the student ID:";
cin>>cid;
cout<<"\n\tDate Of Birth as DD/MM/YY:";
gets(dob);
cout<<"\n\tEnter Father's Name:";
gets(fname);
cout<<"\n\tEnter Mother's Name:";
gets(mname);
cout<<"\n\tEnter telephone number with the STD code:";
gets(ph);
cout<<"\n\tEnter address:";
gets(address);
getch();
}
void info::display()
{
cout<<"\n\n\tDisplay students: ";
cout<<"\n\t-------------------\n";
cout<<"\n\n\tStudent details are:";
cout<<"\n\n\tName:";
cout<<name;
cout<<"\n\tID:";
cout<<cid;
cout<<"\n\tDate of birth:";
cout<<dob;
cout<<"\n\tFather's Name:";
cout<<fname;
cout<<"\n\tMother's Name:";
cout<<mname;
cout<<"\n\tScore:";
cout<<score;
cout<<"\n\tPhone Number:";
cout<<ph;
cout<<"\n\tResidence:";
cout<<address;
}
void info::test()
{
acc();
eco();
comp();
scorer();
clrscr();
}
void main()
{
clrscr();
f:
cout<<"\nMain Menu";
cout<<"\n1.Enter student details";
cout<<"\n2.Take the test";
cout<<"\n3.View a single student's report";
cout<<"\n4.View the report of all students";
cout<<"\n5.Exit";
cout<<"\nEnter your choice:";
int ch;
cin>>ch;
switch(ch)
{
case 1:
{
ofstream file1("pripoo.txt",ios::app);
d.input();
file1.write((char*)&d,sizeof(d));
file1.close();
goto f;
}
case 2:
{
cout<<"\nEnter the id of the student taking the test:";
ifstream fout("pripoo.txt",ios::in);
int pos;
int tid;
cin>>tid;
while(!fout.eof())
{
pos=fout.tellg();
fout.read((char*)&d,sizeof(d));
if(d.cid==tid)
{
d.test();
fout.seekg(pos);
break;
}
}
fout.close();
goto f;
}
case 3:
{
cout<<"\nEnter the ID:";
int id;
cin>>id;
ifstream fout;
fout.seekg(0);
fout.open("pripoo.txt",ios::in);
while(!fout.eof())
{
fout.read((char*)&d,sizeof(d));
if(d.cid==id)
{
d.display();
break;
}
}
fout.close();
goto f;
}
case 4:
{
ifstream fin("pripoo.txt",ios::in);
fin.seekg(0);
while(fin.read((char*)&d,sizeof(d)))
{
d.display();
}
fin.close();
goto f;
}
case 5:
{
cout<<"\nPress any key to exit";
getch();
exit(0);
}
}
}
the code you need help with here.

It would be great if someone could help me with this. Thank you very much for taking time and reading this post.
Topic archived. No new replies allowed.