Apr 22, 2010 at 3:59am UTC
Hi,
I have some text in this file. data.txt ( i need to make courseName run in ascending order)
maths abcd1244 A 3
english abcd1255 B 3
spanish abcd1222 D 3
physics abcd1111 C 3
how do i read it and cout them as:
physics abcd1111 C 3
spanish abcd1222 D 3
maths abcd1244 A 3
english abcd1255 B 3
This is all I am thinking,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
class course
{
string courseName, courseID;
int credits;
char grades;
}
void course::setCourse (string cName, string CID, int credit, char grade)
{
courseName = cName;
courseID = CID;
credits = credit;
grades = grade;
/*need to do some sort of formula to do ascending, im thinking abcd is default,
so just extract numbers out of courseName, and put numbers into array.*/
}
int main()
{
ifstream input;
string readFromFile;
cout << "enter a filename:" ;
cin >> readFromFile;
input.open(readFromFile.c_str());
if (!input.good())
{
cout << "File not found" << endl;
system("pause" );
return 0;
}
for (int j = 0; j < 5; j++)
{
string courseName, courseID;
int credits;
char grades;
input >> courseName >> courseID
>> credits >> grades;
cout << setCourse (courseName, courseID, credits, grades);
}
hope someone can get me thinking. Thanks. =D
Last edited on Apr 22, 2010 at 4:04am UTC
Apr 22, 2010 at 8:41am UTC
Read the file, placing each line into a record, then each recorcd into a container.
Sort the container by the course name field.
Print the container.
Apr 23, 2010 at 8:26am UTC
Thanks kbw for your reply. Very comforting as you're the only one around to render the help. :)
Apr 23, 2010 at 11:21am UTC
There's loads of help around.
Have you made any progress?
Apr 26, 2010 at 2:48am UTC
Man, forgot all about this thread as i was busy trying other methods and studying for quiz. Thanks for your help thou. :)