| | |
Please I need help formatting an output file and sorting the names!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
•
•
•
•
So, after sorting calculate average and letter grade?
Or, first calculate average and letter grades and then sort the names!
•
•
Join Date: Jul 2005
Posts: 23
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
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.
•
•
Join Date: Jul 2005
Posts: 23
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
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
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
![]() |
Other Threads in the C++ Forum
- Previous Thread: neef u help
- Next Thread: need help wit proj
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






