Hi everyone.
I hope all is well.
I am having trouble with my code below.
For my C++ class, my professor has just uploaded an assignment that requires us to read all records from a disc file to:
1. Arrays.
2. Structure of records: student number (2 bytes), student name (20 bytes), and grade (integer).
3. Sort the list according to test scores.
4. Display the average test score of the class.
5. Save sorted records to a new disc file.
The disc file mentioned above:
1 Sanna Saunders 89
2 Kelly Handley 95
3 Arif Crane 76 |
I feel like I have only part 1 complete, which was to rewrite the original disc files using a strut function, but I'm not sure how I can use an array to sort out these elements. Do I just input those numbers/scores: "89, 95,76" as elements (in square brackets []) or is there another way to do it?
I also need the code to be an average between all three numbers listed above. So there should be a formula that holds the averaged value, divided by the three scores: 89 + 95 + 76 = 260, 260/3 = 86.3
or
sum += scores
average = sum / scores |
Lastly, the code should also be sorted in ascending order, so it should look like:
3 Arif Crane 76
1 Sanna Saunders 89
2 Kelly Handley 95 |
I'm not sure what else I can add. I know there's still so much left to do to meet the criteria for this assignment, and I've also written a similar code for a similar assignment which also had to do with arrays and sorting, but those numbers came from user input. Now these numbers are given: 89, 95, and 76, so I'm not sure how I can modify that accordingly.
Please, if anyone can or has the time, take a look at my code and run it. Thanks in advance.
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
|
#include <iostream>
#include <string>
using namespace std;
struct students{
string studentName;
float testScore;
};
int main(){
struct students active[3] = {
{"Student 1: Sanna Saunders:\t", 89},
{"Student 2: Kelly Handley:\t", 95},
{"Student 3: Arif Crane: \t", 76}};
struct students *record = active;
cout << "\nThe records in the original file are: \n\n";
while (record <= &active[2]){
cout << " " << record -> studentName << " " << record -> testScore << " " << endl;
record ++;
}
cout << "\n The records in the new file are now sorted: \n\n";
return 0;
}
|