Hello again,
I will go straight to the point. I have two files one that is called student.dat and the other is called grades.dat .
Student.dat has the following items in it :
20092112 Anthony Haykal
20084564 John Doe
20075640 James Bond
20045678 Cynthia Smith
20092134 Jennifer Hajj
grades.dat has these :
20045678 75 80 85
20092134 64 51 84
20075640 57 65 90
20092112 80 90 85
20084564 85 46 68
The question asks me to read the data from “grades.dat” file and print on the screen the Student’s ID and Students’s Name (first name, last name) and the total grade.
You will find the firstname and the lastname in the “student.dat” file. (Note that
the files “student.dat” and “grades.dat” are NOT in the same order.)
I just have a problem with the order. I mean how do i make like id number 20092112 to print the name and final name in this case Anthony Haykal
while showing the grades also. If i read them in sequential order i cant like point to this specific id. I arrived here and got stuck :s
#include <iostream>
#include <fstream>
using namespace std;
int main()
{//start main
int id;
int id2;
char FirstName[30];
char LastName[30];
int AssignmentGrade;
int MidTermGrade;
int FinalGrade;
int student[5];
ifstream infile("grades.dat" , ios::in);
ifstream infile2("student.dat", ios::in);
if (!infile||!infile2)
{
cout<<"Could not open the file(s)";
return 1;
}
while (infile>>id>>AssignmentGrade>>MidTermGrade>>FinalGrade)
{//first while
while(infile2>>id2>>FirstName>>LastName)
{//second while
if (id == id2)
{
cout<<FirstName<<endl;
}
else if (id != id2)
cout<<"Not same id"<<endl;
}//second while
}//first while
cout<<endl<<endl;
infile.close();
infile2.close();
}//end main
Could you aid me with this issue please!
Thank you