dear people
recently i have been given with this assignment where i have to read from a txt file and then print out the following.
the full class list.
the class list sorted by gpa
the class list sorted by name initial the user enters
the class average gpa.
i am stuck on the second part of it.
i know that we have to store in in a array but when i store it each array consists of a single charecter.please can ne1 guide me as to how i need to store ithe file in a array.
that is so that i can sort it out according to the GPA
here is the txt file
Lastname(initial) ID# Age GPA
-----------------------------
F 2221 24 3.2
B 1236 19 1.0
H 3476 22 4.0
H 1122 23 2.2
R 5412 21 3.9
B 0071 26 0.9
here is what i have done till now
#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
const int ARRAYSIZE = 1000;
const int ROW = 6;
const int COLUMN = 10;
void telluser();
int askuser();
void displayclasslist();
void sortandprint();
int main()
{
int ans;
telluser();
ans=askuser();
if (ans==1)
{
displayclasslist();
}
if (ans==2)
{
sortandprint();
}
system("PAUSE");
return 0;
}
void telluser()
{
cout<<"This programe handles the student records of tough university and "
<<"displays data according to user specification\n\n\n\n";
}
int askuser()
{
int ans;
cout<<"What do you wish to do? (please enter the coresponding number)\n\n";
cout<<"\t1: Print the entire class list.\n";
cout<<"\t2: Print class list sorted by GPA.(Lowest to Highest)\n";
cout<<"\t3: Print class list of students which match a given"
<<"lastname initial.\n";
cout<<"\t4: Print the mean and standard deviation of the GPA values.\n";
cout<<"\t5: Exit program.\n\n";
cout<<"Enter Your Choice:\t";
cin>>ans;
cout<<endl<<endl;
return ans;
}
void displayclasslist()
{
ifstream inFile;
inFile.open("F:\\StudentRec.txt",ios::in);
char ch[ARRAYSIZE];
cout<<"LastName(initials)\tID#\t\t\tAGE\t\t\tGPA\n";
cout<<"-----------------------------------------";
cout<<"--------------------------------------\n";
inFile.getline(ch,ARRAYSIZE,'\n');
inFile.getline(ch,ARRAYSIZE);
while (!inFile.eof())
{
inFile.getline(ch,ARRAYSIZE,' ');
cout<<ch<<"\t\t\t";
}
cout << endl;
}
void sortandprint()
{
ifstream inFile;
inFile.open("F:\\StudentRec.txt",ios::in);
cout<<"LastName(initials)\tID#\t\t\tAGE\t\t\tGPA\n";
cout<<"-----------------------------------------";
cout<<"--------------------------------------\n";
char ch[50];
char file[ROW][COLUMN];
inFile.getline(ch,ARRAYSIZE,'\n');
inFile.getline(ch,ARRAYSIZE);
while (!inFile.eof())
{
for(int i=0;i<ROW;i++)
{
for(int j=0;j<COLUMN;j++)
{
inFile>>file[i][j];
}
}
}
}