Can someone help me? after exiting the program.. the student record.txt becomes empty after i restart the program..
so far Im only after the name, last name, and student id because i dont want to confuse myself more but if someone could teach me here i might implement other datas..
here is the codes:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct studentRecordType
{
string fName;
string lName;
int studID;
};
int main()
{
studentRecordType students[3000];
ifstream infeil;
ofstream outfeil;
char yNnAnswer,transactionSelector;
int index=2000;
int primaryChoice;
outfeil.open("studentrecord.txt");
cout<<"******************************************************\n"
<<"******************* STUDENT RECORD *******************\n"
<<"******************************************************\n"
<<"\t\t 1.Add a student\n"
<<"\t\t 2.Search a student\n"
<<"\t\t 3.Delete a record\n"
<<"\t\t 4.quit\n"
<<"\t\t your choice: ";
cin>>primaryChoice;
cout<<endl;
switch(primaryChoice)
{
case 1:
{
system("CLS");
cout<<"****************************************\n"
<<"********Registering a student***********\n"
<<"****************************************\n";
cout<<endl<<endl;
cout<<"Please enter the students first name:";
cin>>students[index].fName;
outfeil<<students[index].fName<<" ";
cout<<endl;
cout<<"Please enter the students last name:";
cin>>students[index].lName;
outfeil<<students[index].lName<<" ";
cout<<endl;
students[index].studID = index;
outfeil<<students[index].studID<<endl;
cout<<"Your student number would be: "<<students[index].studID<<endl;
cout<<"do you want to register another student?(y/n):";
cin>>yNnAnswer;
if(yNnAnswer == 'y')
{
do
{
index++;
system("CLS");
cout<<"****************************************\n"
<<"********Registering a student***********\n"
<<"****************************************\n";
cout<<endl<<endl;
cout<<"Please enter the students first name:";
cin>>students[index].fName;
outfeil<<students[index].fName<<" ";
cout<<endl;
cout<<"Please enter the students last name:";
cin>>students[index].lName;
outfeil<<students[index].lName<<" ";
cout<<endl;
students[index].studID = index;
outfeil<<students[index].studID<<endl;
cout<<"Your student number would be: "<<students[index].studID<<endl;
cout<<"do you want to register another student?(y/n):";
cin>>yNnAnswer;
}
while(yNnAnswer == 'y' );
}
outfeil.close();
break;
};
case 2:
{
cout<<students[index].fName<<endl;
break;
};
case 3:
{
break;
};
case 4:
{
exit(0);
}
}
return main();
system("pause");
}