it's required to design a system that takes all the data relevant to the student such as, name,ID,no.of subjects ,and their marks. it's required that when i search for a specific student to show all the data about him and to calculate his gpa and print the result. i tried but the output wasn't as expected and here's my code: //how the data is read in the txt file`
void enter()
{
ofstream file1("cairo.txt", ios::app);
cout << "Enter the student's name : ";
getline(cin, name);
file1 << name << "\t";
cout << "Enter the student's ID : ";
cin >> std_num;
file1 << std_num << "\t";
cout << "Enter your department : ";
cin.ignore();
getline(cin, department);
file1 << department << "\t";
cout << "Enter the student's number for subjects : ";
cin >> num_sub;
file1 << num_sub << "\t";
for (int i = 0; i < num_sub; i++) {
cout << "please enter the student's " << i + 1 << " " << "mark \n";
cin >> grades[i];
file1 << grades[i] << "\t";
}
file1 << "\n";
file1.close();}
void get_grades()
{
char name[30], id[10], dep[25], city[15], resd[15], zip[15];
int nsub,nmarks[10];
float sum = 0;
ifstream gfile("students.txt");
char rq[30];
cout << "Enter the name of the required student to get his grades : ";
cin.getline(rq, 25);
while (!gfile.eof())
{
if (strcmp(name, rq) == 0)
{
gfile.getline(name, 30, '|');
gfile.getline(id, 10, '|');
gfile.getline(dep, 25, '|');
gfile >> num_sub;
for (int i=0; i < nsub; i++)
{
gfile1>>nmarks[i];
sum += nmarks[i];
}
psum = (sum/(nsub*100));
if (psum < 0.5)) cout<<" Your Grade is F "<<endl;
else if (psum >= 0.5 && psum < 0.65) cout<<" Your Grade is D "<<endl;
else if (psum >= 0.65 && psum < 0.75) cout<<" Your Grade is C "<<endl;
else if (psum >= 0.75 && psum < 0.85) cout<<" Your Grade is B "<<endl;
else cout<<" Your Grade is A "<<endl;
}
}
}