![]() |
help me please
good day
if I have name and gread in a file like this : telfer 67 jon 89 necales 78 . . . and I want to Sort the name according to their grade (increasing order) >>> how I can do this ? |
Re: help me please
hi, i don't know c++ syntax, but theoretically, you can explode the file into rows, then split them by space, and then use some sorting algorithm (for example insert sort) to sort them... fig c++ commands is 5 minute work with google...
|
Re: help me please
could explen more please
|
Re: help me please
Just read the file into whatever data structure seems easiest to you - a linked list of structures if you like, or a couple of static arrays if you're allowed to specify an upper limit of lines in the input file (no point complicating things unnecessarily).
Then run your favourite sort algorithm on the grade, remembering also to swap the entries in the name part of the data structure. How far have you got with the project? Can you at least read the file into a data structure of your own design? |
Re: help me please
I did 8 steps of the project and the other three steps not yet
this is one of them Unfortunately, I did not know how to respond to this step could you give me example or simple code |
Re: help me please
What data structure do you think would be most appropriate?
Do you need the size to be open ended or is it OK to have an upper limit? |
Re: help me please
This is the complete working code :
Code: C++
Brief explanation : (1) You create a struct StuRec to store the records. (2) You define your own func that compares two StuRecs. (3) You create a StuRec vector and fill it up from the file "C:\\TestData.txt". (Change it as per your need.) (4) You use STL sort to sort the vector according your comparison func. (5) You write the data to a new file "C:\\SortedData.txt". (Change it as per your need.) |
Re: help me please
SaswatPadhi
I am using turbo c++ with include<stdio.h> could you help me with turbo c++ |
Re: help me please
Quote:
thank you |
Re: help me please
Come on man, can't you convert ANSI C++ to Turbo C++ code yourself ?!
This should work in TurboC++. Code: c++
|
| All times are GMT +5.5. The time now is 02:50. |