|
i have to complete a C++ program that reads a specific file with data about students who have completed 3 assignments and the final exam in a unit, and displays the information of top students
i have to create a program where the user Input A text file containing students' information. The information of each student is given in a line with the following format, which includes the student ID and 4 scores of assignment 1, assignment 2, assignment 3 and the final exam in order.
<student ID> <score of assignment 1> <score of assignment 2> <score of assignment 3> <score of final exam>
The score of each assignment is between 0 and 15 (inclusive). The sum of the marks of the three assignments is reduced to a maximum of 40. For example, if the sum of the three assignments is 42 (say 15+12+15), then it is reduced to 40. If the sum is 25 (i.e. no more than 40), then it would not be changed.
The score of the final exam is between 0 and 100 (inclusive). To calculate the final score for the unit (which is between 0 and 100 (inclusive)), the exam score should be scaled down to 60%. E.g., an exam score of 100 is scaled down to 60, and an exam score of 50 is scaled down to 30. Therefore, if a student got 45 marks from the assignments, and 90 marks from the final exam, then the total score is 40 + 90 * 0.6 = 94. The program should open once a file with entered filename and read data from it. The program should process the data and diplay the result.
1. In the output, 8 places are used to diplay an id. 2. The displayed total score of a student has the following format requirements: 7 places for the total score fixed decimal format with 2 decimal places 3. Top students are listed in the non-ascending order of the total score, one student per line. 4. For the regular requirement, we assume the total scores are distinct. 5. We assume that in the input file, there is data about at least 1 student and up to 30 students. 6. You should use studentType of type struct declared in the template. You cannot modify it. 7. You should implement and use the functions declared in the template. 8. You should call your program "studentSelection.cpp". You can download the template and implement it. 9. Here we assume that the source file and the data file are in the same directory. When typing the filename, you do not need to enter the full path of the file.
Here are some sample inputs and the corresponding outputs of the program
Example 1 (input file: in1.txt)
Enter the filename of the student data file: in1.txt
There is 1 student in total.
Top Student List s0000001 85.00
Press any key to continue . . .
Example 2 (input file: in2.txt)
Enter the filename of the student data file: in2.txt
There are 9 students in total.
Top Student List s0000001 85.00 s7000001 77.00 s8000002 65.00
Press any key to continue . . .
hopefully someone can help me in writing the functions
1st function should read the file 2nd function should print the top three students 3rd function should sort array in decending order i have to add a new function which uses buble sorting order to order the student ID's if there are more than 1 student with the top 3 marks
Here we assume in the extra part of the program that the total scores may NOT be distinct. Top students are listed in the non-ascending order of the total score, one student per line. Top students with the same total score are listed in the ascending order of student ID.
Here are some sample inputs and corresponding outputs of the program
Example 1 (input file: in1_b.txt)
Enter the filename of the student data file: in1.txt
There is 1 student in total.
Top Student List s0000001 85.00
Press any key to continue . . .
Example 2 (input file: in2_b.txt)
Enter the filename of the student data file: in2_b.txt
There are 12 students in total.
Top Student List s0000001 85.00 s8000001 85.00 s9000001 85.00 s7000001 77.00 s9000002 77.00 s8000002 65.00
Press any key to continue . . .
Example 3 (input file: in3_b.txt)
Enter the filename of the student data file: in3_b.txt
There are 24 students in total.
Top Student List s1100001 81.00 s7400004 81.00 s9001001 81.00 s8000001 77.40 s9990001 77.40 s7900001 75.00 s8000004 75.00 s9200001 75.00
Press any key to continue . . .
So far ive written part of the code
#include <iostream> #include <fstream> #include <iomanip> #include <string>
using namespace std;
const int TOP_NUM = 3;
struct studentType { string id; // unique id float assignments[3]; // scores for 3 assignments - in the scope of [0,15] float exam, total; // member exam is the exam score in [0, 100]; member total is the total score in [0, 100] };
bool readStudents(string fName, studentType stuList[], int& size); // pre: none // post: read students id and scores into the one-dimensional array of struct: stuList // The actual size of the array is returned by reference paramenter size // this function returns false if an error occurred when opening or reading the specified file, otherwise returns true
void printStudents(const studentType stuList[], int size); // pre: none // post: print the id, and the total score in array StuList // size stores the the number of elements in stuList
// declare other functions
int main() { studentType studentList[30]; // the array used for storing the information of students from a file int numOfStudents = 0; // numOfStudents is the actual number of students in the data file string fileName; // it stores the file name of the data file // declare other variables if necessary cout << "Enter the filename of the student data file: " << flush; cin >> fileName; cout << endl; if (!readStudents(fileName, studentList, numOfStudents)) cout << "Input file error." << endl; else { // code for processing if (numOfStudents >= 2) cout << "There are " << numOfStudents << " students in total. " << endl << endl; else cout << "There is " << numOfStudents << " student in total. " << endl << endl; cout << "Top Student List" << endl; // write your code to diplay top students } cout << endl; system("pause"); return 0;
bool readStudents(string fName, studentType stuList[], int& size);
void printStudents(const studentType stuList[], int size);
Attached File(s)
in1.txt ( 20bytes )
Number of downloads: 29
in1_b.txt ( 20bytes )
Number of downloads: 17
in2.txt ( 196bytes )
Number of downloads: 18
in2_b.txt ( 262bytes )
Number of downloads: 15
in3_b.txt ( 574bytes )
Number of downloads: 20
|