|
| ryujin89 (26) | |||
| NO LONGER "major issues". I have completed the core part of the program and need assistance to figure the rest out. I'm at a complete loss due to teacher and book not really covering material in a way to prepare for the assignment. I have looked over the tutorials for I/O on this site as well as others and if I need to change things, I'm wide open for assistance. I did attempt to figure out as much as I could, but I'm stuck. Thanks in advance for anyone who takes time to assist me. I greatly appreciate it. To clear things up from the start, here are the instructions: The program is to take a text file, students.txt, containing information about the currently-enrolled students in a school. Each line represents a record for a different student and contains the student's identification number (eight digits), credit hours completed, and grade point average. A sample line follows: 10082352 66 3.04 Program is supposed to have the identification number and grade point average for each student in the file copied to one of four different text files based on the number of credit hours completed: Less than 32 freshmen.txt 32 to 63 sophomores.txt 64 to 95 juniors.txt 96 or more seniors.txt Next is to write the identification number and grade point average of each student on a single line (one line per student) in the appropriate file. For example, since the student mentioned above has completed 66 credit hours, the following would be added to the file juniors.txt: 10082352 3.04 The number of students in the original file is unknown, so the program will need to read these records in until you reach the end of the file. Also, no student should have a negative number of credit hours, and the maximum number of credit hours that a student can accumulate is 250. If the program encounters a student record with an erroneous number of credit hours, write the entire record for that student (identification number, credit hours, and grade point average) to the file hoursError.txt rather than any of the four aforementioned files. The lowest grade point average a student may have is 0.0, and the highest grade point average a student may have is 4.0. If the program encounters a student record with an erroneous grade point average, write the entire record for that student to the file averageError.txt rather than any of the four aforementioned files.As was previously stated, the student's identification number should be eight digits. If the program encounters a student record with an identification number of fewer or greater than eight digits, write the entire record for that student to the file identError.txt rather than any of the four aforementioned files.Assume that an identification number error has highest precedence, then the number of credit hours completed, then the grade point average. Don't write a student record to multiple error files: only the one that has the highest precedence should receive the record. I'm going in the direction that I believe it needs to have the input file made into a dynamic array, but not sure how to do that. Here is the code I have with compiler errors formatted within brackets after comment code. e.g. //[compiler error]
Thanks again for anyone who has patience to assist me. It's greatly appreciated. | |||
Last edited on | |||
| Bazzy (3181) | |||||||||||||
-from line 9-
-from line 17-
-line 62-
-line 74-
-line 81-
| |||||||||||||
Last edited on | |||||||||||||
| ryujin89 (26) | ||||||||
| I'm going to try and break things down and do them step by step. Here is the code I'm trying to use to open the input file, students.txt, and just a single output file, freshmen.txt. I also want ot count the number of lines in the students.txt file. Can someone tell me if I'm on the right track please? My book said that if the output file didn't exist, the program would create it, but it isn't doing that nor when I create a file does it print anything to the file. There isn't anything showing up on the compiler screen other than it saying that there wasn't any errors. As in my first post, I would like to be able to open the students.txt file and then sort its elements into different output files based on certain criteria is why I have the other open output file code, but I can't get just the one output file right now.
Also, someone on another site suggested :
However, after looking on the net, there are similar programs (very few) that use vectors instead of an array, but I don't know much about nor have experience with them. Any suggestions? | ||||||||
| Bazzy (3181) | |||
| |||
| ryujin89 (26) | |
| I have looked over that thread before and yes it does define vectors well and describes theory, but not very well on how to use them. Not anything where I can see how to apply it to my situation. | |
Last edited on | |
| Bazzy (3181) | |
| If you read the various sub-articles you will find some code examples. A vector is the same as a resizable array | |
| ryujin89 (26) | |||||
| after a more work (what I could get in between work and school), here is the updated post. All post before this can be pushed to the side / ignored b/c I have re-wrote my code and coming in again. lol. Thanks for input Bazzy. Will look into it more. Figure I might as well go ahead and clear up that this is obviously a school assignment. I have completed a somewhat decent amount of code (not saying I have a lot of faith in it's correctness tho) and need assistance to figure the rest out. I'm at a complete loss due to teacher and book not really covering material in a way to prepare for the assignment. I have looked over the tutorials for I/O on this site as well as others and if I need to change things, I'm wide open for assistance. I did attempt to figure out as much as I could, but I'm stuck. Thanks in advance for anyone who takes time to assist me. I greatly appreciate it. To clear things up from the start, here are the instructions: The program is to take a text file, students.txt, containing information about the currently-enrolled students in a school. Each line represents a record for a different student and contains the student's identification number (eight digits), credit hours completed, and grade point average. A sample line follows: 10082352 66 3.04 Program is supposed to have the identification number and grade point average for each student in the file copied to one of four different text files based on the number of credit hours completed: Less than 32 freshmen.txt 32 to 63 sophomores.txt 64 to 95 juniors.txt 96 or more seniors.txt Next is to write the identification number and grade point average of each student on a single line (one line per student) in the appropriate file. For example, since the student mentioned above has completed 66 credit hours, the following would be added to the file juniors.txt: 10082352 3.04 The number of students in the original file is unknown, so the program will need to read these records in until you reach the end of the file. Also, no student should have a negative number of credit hours, and the maximum number of credit hours that a student can accumulate is 250. If the program encounters a student record with an erroneous number of credit hours, write the entire record for that student (identification number, credit hours, and grade point average) to the file hoursError.txt rather than any of the four aforementioned files. The lowest grade point average a student may have is 0.0, and the highest grade point average a student may have is 4.0. If the program encounters a student record with an erroneous grade point average, write the entire record for that student to the file averageError.txt rather than any of the four aforementioned files.As was previously stated, the student's identification number should be eight digits. If the program encounters a student record with an identification number of fewer or greater than eight digits, write the entire record for that student to the file identError.txt rather than any of the four aforementioned files.Assume that an identification number error has highest precedence, then the number of credit hours completed, then the grade point average. Don't write a student record to multiple error files: only the one that has the highest precedence should receive the record. I'm going in the direction that I believe it needs to have the input file made into a dynamic array, but not sure how to do that. I am now at the point that I would need to create an array or vector that would read in the line from students.txt and then be able to sort it to different output files based on the 2nd column of numbers. ie. say the line is 10082352 66 3.04 Next is to write the identification number and grade point average of each student on a single line (one line per student) in the appropriate file. For example, since the student mentioned above has completed 66 credit hours, the following would be added to the file juniors.txt based on the criteria for sorting listed in the 1st post: 10082352 3.04 Here is my code thus far
To clear up where I'm at, I need assistance in figuring out how to get the input file data into either an array or vector and then sort it to its different respective output files. There is also possibility that the input file may have a student ID with more than 8 numbers as well as the other two columns having a varying number digits in each column (which will also affect which output file it will be sent to). //Edited to include not sure exactly how to use it, but could something like
work to create an array that will vary based on the number of lines in the file? //End of edit Thanks to all who have the patience to assist me. | |||||
Last edited on | |||||
| Bazzy (3181) | |||||
| I believe you should use a struct/class to represent the students eg:
You can read in a loop the various variables from the text and then insert a new student in the deque:
Then you can sort it with standard algorithms: http://www.cplusplus.com/reference/algorithm/sort/ | |||||
| ryujin89 (26) | |||
| So due to this being my 1st class and I don't fully understand all of this, I'm lost. It's due in roughly hours and as can be seen, I'm not even in the testing part to ensure it's working. I've worked on this for roughly 7.5 hrs per night every night for the past 4 days and I just can't wrap my mind around it. I greatly appreciate the assistance. I have worked with some stuff that was posted on another forum I have this on and placed it within my code where I thought it would go, but even after re-naming, and moving stuff around and other things I can't get it to work. My compiler (VS 2008) didn't want to accept the way they had things "formatted" for lack of better terms so I took out parts so it would remove those errors, but I still can't get them all to work down to where I can follow them through and figure them out. Here is my code as of now.
If anyone can assist further in a way that I might understand since we haven't covered a lot of things thoroughly as we probably should have. This is my 1st class and it's bogging me down (doesn't help that I'm taking Java at the same time tho). I still have roughly 31 hrs till its due from the time of this post, so I will work on it as much as I can. Thanks again for all the assistance. Edited to reformat indentation and to move the vector and struct declarations. Still working on the looping against !student. There are so many tutorials that say "use this method" that I can't seem to find one that works. Rather it's accepted by all programmers or not, I just need it to work. lol. I described in the 1st post exactly what I was trying to do and the code that is in this post is what was suggested on another thread but I apparently didn't understand how they wanted me to implement it into my code. | |||
Last edited on | |||
| firedraco (2048) | |
| Ugh, your indentation is kind of screwed up, so it's hard to see where scopes begin/end...VC++ 2008 has an "format" thing (Edit->Advanced->Format Selection), select your code and use that and it'll make it look nice. Lines 15/23, you want to loop against !students, not the eof() or fail(). On line 22, use an std::string, so you can use std::getline() on lines 25/26. 35 and on... I don't understand what you are trying to do...You are overwriting the data you just got, making a local (named) struct for some reason...maybe you need to re-think how you approaching this. | |
| Bazzy (3181) | |
| Both the vector and the struct declarations should be moved before line 34 | |
| ryujin89 (26) | |
| I have edited my post and put it in bold at the bottom. Thanks again for your assistance. | |
| Bazzy (3181) | |
| You are closing the main brace too early ( Line 43 ) Move it to line 72 - With better indentation, these problems are more visible - | |
| ryujin89 (26) | ||||
| It's due in 6 hours and I don't know if I'm going to be able to get it finished. I wish that he had covered the material better so that I could help myself with the help you are providing. Thanks a lot for all you have done. Here is the code
and these are the errors that I'm getting.
_ | ||||
Last edited on | ||||
| Bazzy (3181) | |||||
#include <vector>
Remove line 42, you'll need to push a student object after reading it from the file | |||||
| ryujin89 (26) | ||||
| I removed what was line 42 but don't know where I should put the pushback or otherwise how to use it. I'm looking that and the student object parts up now. Here is the code with the new #include and the deletion of that line
And now these are the remaining errors.
| ||||
| Bazzy (3181) | |||
| |||
Last edited on | |||
| ryujin89 (26) | |||
| Thanks a lot. That got it to compile and now to I'm going to work on trying to sort the input into the four output files. here is the code compiling.
| |||
| ryujin89 (26) | |
I have looked over the net and the main direction I'm getting to sort the data is to use sort(my_student.begin(), my_student.end());but I'm not sure to put it either after the if-else statements or after the getline while loop itself. I'm getting the error stating that " 'sort': identifier not found " no matter where I place it. Once i do get that to work, could I create a if-else loop to sort the data into their output files? As long as I can get it to sort into one of the four "classes" output files it will be acceptable (I emailed the prof) but he would prefer if I could also include the sort if one of the errors occurs such as the student ID being more than 8 numbers (I defined the errors in a previous post). Thanks for all the assistance. | |
| Bazzy (3181) | |||
while
I order to use sort, you'll need to define a sorting function. | |||
Registered users can post in this forum.
