Please I need help formatting an output file and sorting the names!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Please I need help formatting an output file and sorting the names!

 
0
  #11
Aug 3rd, 2005
So, after sorting calculate average and letter grade?

Or, first calculate average and letter grades and then sort the names!
you could do it either way. Personally, I would sort first and then figure the grade and the average. If you do it the other way, just two extra things that have to be swapped when you do the sort
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 23
Reputation: angel22 is an unknown quantity at this point 
Solved Threads: 0
angel22 angel22 is offline Offline
Newbie Poster

Re: Please I need help formatting an output file and sorting the names!

 
0
  #12
Aug 3rd, 2005
But tell me something, to sort the names, is it possible to do it without arrays or not.

The thing is that I am not sure if I can use a string array that contains both the first, and last name, and then how to change them and include a comma in the middle!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Please I need help formatting an output file and sorting the names!

 
0
  #13
Aug 3rd, 2005
I guess you could find a way to do it without arrays, but I don't know why you would want to. What function are you using to compare the names to see which one should be first
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 23
Reputation: angel22 is an unknown quantity at this point 
Solved Threads: 0
angel22 angel22 is offline Offline
Newbie Poster

Re: Please I need help formatting an output file and sorting the names!

 
0
  #14
Aug 3rd, 2005
These are the specifications the teacher gave us to include in the project!
I hope you can see now what I am supposed to do so it is easier for me to start correctly!


Write a program to compute grades for a course. The records are in a file. Each line has ID, space, lastname, space, firstname, space, 10 scores.

the output has to be formatted, no ID, lastname, comma, firstname, 10 scores, average, letter Grade.

List has to be alphabetized in ascending order. Use at least one function that has file streams as all or some of its arguments.

Hints;

use an array for students name and other for test scores.
instead of sorting both arrays, sort index array instead.
keep track of number of students
total length of name with comma and space is less than 20 characters.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,681
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Please I need help formatting an output file and sorting the names!

 
0
  #15
Aug 3rd, 2005
If you are going to sort data you need to hold it in some sort of container and then spit it all back out once you have completed the work you need to do. If you read from file and spit stuff out to the screen for each student as the data is read from the file you can't sort the data. What container type you use depends a lot on what container you know. Since you don't know about struct/class, then you can't use that container. Since you don't know pointers, then you can't use lists. The only container left is arrays. Therefore you will need to put the data you read from file into arrays and sort it as you insert or sort everything at once after you've read everything in from file. Then, when everything is sorted you can print out the sorted data stored the array(s) to the screen. Whether you calculate the average and the assign the grade as you are reading from file, or after you sort the raw data and then analyze it before printing it out (you don't even have to sort the average/grade if you don't want to) is up to you. You can store the first and last name as a single string if you want, or as separate strings, up to you. If you store the entire name as a single string, and you want to sort on the last name, then the last name needs to be the first word in the string. It's better to separate the first name and last name if you are going to sort alphabetically, but you don't have to if you don't know how.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 23
Reputation: angel22 is an unknown quantity at this point 
Solved Threads: 0
angel22 angel22 is offline Offline
Newbie Poster

Re: Please I need help formatting an output file and sorting the names!

 
0
  #16
Aug 3rd, 2005
For the last name and first name is it possible to say?

string firstname, lastname;
int score[10];

then while readign the file:


while (infile>>ID)
{
infile>>firstname;
infile>>lasntame;
for (int n=0; n<10; n++)
{ infile>>score[n];
}
}

or should I use a for loop to enter the first and last name also?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,681
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Please I need help formatting an output file and sorting the names!

 
0
  #17
Aug 3rd, 2005
If you are going to store the first and last name separately, then you need to read them in separately. If you are going to store them in the same string, then you MIGHT be able to read them in together, though it would probably be easier to read them in separately, combine them, and store them as a single thread. To sort you need to declare a number of arrays.

string lastName[20]; //all students last names
string firstName[20];//all students first names
int exam1[20];//all students scores for first exam
int exam2[20];//all students scores for second exam
...
int exam10[20];

Then read data from file into each of the arrays:

while stuff to read in
read in lastname[i];
read in firstName[i];
read in exam1[i];
.
.
.

then sort the lastName array, moving all data around at the same time in all the arrays to keep the data associated with the same name across arrays.

or

1)declare arrays as above;
2)declare a string to hold current name(s) and ints to hold current scores
3)read in a given students name(s) and scores.
4)find place in array where current student belongs, sorting by last name as insertion occurs
5)if necessary, make room for current student data by shifting current data with same or higher index than the one the current student will have one place to the right.
6)assign current students data into the array in the place desired.
7)use another int to keep track of how many students are present in the array at any given loop through the read/insertion
8)repeat until entire file read in

Then once sorting has been accomplished
1)output the name(s) in whatever format you want
2)calculate the average and grade (if not done already)
3)display each exam score, average, and letter grade as appropriate
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 23
Reputation: angel22 is an unknown quantity at this point 
Solved Threads: 0
angel22 angel22 is offline Offline
Newbie Poster

Re: Please I need help formatting an output file and sorting the names!

 
0
  #18
Aug 3rd, 2005
Thank you, I will work this problem later at school!

Now, i have to leave!

i'll see how it goes, and if i'm able to do it! well i hope!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC