Name: First year cs student 2007-11-11 8:28
First, here is the question:
Option 4 will ask the user to enter the following details of leave records.
StudentID is the student’s identification.
StartDate is the start date of the leave. Eg 30-04-2001
EndDate is the end date of the leave eg. 02-05-2001
Reason is the reason for the leave, and has a maximum of 35 characters.
The leave of absence records will be accumulated in a separate file name LOA.DAT.
Each time Option 4 is selected, a new leave record will be appended to the file. One
student may have several leave records. ->The LOA record of a student is accepted only
when the StudentID exists in the student file STUDENT.DAT.<-(This is where my problem lies)
Part of the code:
void LOAADD(){
studinfo check[20];
int add = 0;
bool present;
char studid[7];
ifstream studcheck;
studcheck.open("STUDENT.dat");
present = false;
char studpre[7];
char dummy1[7];
int dummy2;
do{
Getstr("Enter your student id: ", studid, 6);
}while(studid==false);
studcheck.get(dummy1, 7);
studcheck>>dummy2; studcheck.get();
while(!studcheck.eof()){
studcheck.get(check[add].id, 7);
studcheck.get(check[add].name, 21);
studcheck.get(check[add].tel, 8); studcheck.get();
if(studcheck.eof()){break;}
add++;
}
for(int run =0; run<add; run++){
cout<<check[run].id <<endl <<studid;
system("pause");
if(studid==check[run].id){
present=true;
break;}
}
if(present==false){cout<<"You are an illegal immigrant.";}
else{cout<<"I bet your medical certificate is fake.";}
system("pause");
}
Output:
Enter your student id: S12345
D12345
A12345Please any key to continue...
A12345
A12345Please any key to continue...
C54321
A12345Please any key to continue...
You are an illegal immigrant. Press any key to continue.
Help please?
Option 4 will ask the user to enter the following details of leave records.
StudentID is the student’s identification.
StartDate is the start date of the leave. Eg 30-04-2001
EndDate is the end date of the leave eg. 02-05-2001
Reason is the reason for the leave, and has a maximum of 35 characters.
The leave of absence records will be accumulated in a separate file name LOA.DAT.
Each time Option 4 is selected, a new leave record will be appended to the file. One
student may have several leave records. ->The LOA record of a student is accepted only
when the StudentID exists in the student file STUDENT.DAT.<-(This is where my problem lies)
Part of the code:
void LOAADD(){
studinfo check[20];
int add = 0;
bool present;
char studid[7];
ifstream studcheck;
studcheck.open("STUDENT.dat");
present = false;
char studpre[7];
char dummy1[7];
int dummy2;
do{
Getstr("Enter your student id: ", studid, 6);
}while(studid==false);
studcheck.get(dummy1, 7);
studcheck>>dummy2; studcheck.get();
while(!studcheck.eof()){
studcheck.get(check[add].id, 7);
studcheck.get(check[add].name, 21);
studcheck.get(check[add].tel, 8); studcheck.get();
if(studcheck.eof()){break;}
add++;
}
for(int run =0; run<add; run++){
cout<<check[run].id <<endl <<studid;
system("pause");
if(studid==check[run].id){
present=true;
break;}
}
if(present==false){cout<<"You are an illegal immigrant.";}
else{cout<<"I bet your medical certificate is fake.";}
system("pause");
}
Output:
Enter your student id: S12345
D12345
A12345Please any key to continue...
A12345
A12345Please any key to continue...
C54321
A12345Please any key to continue...
You are an illegal immigrant. Press any key to continue.
Help please?