Computer Science 235

Grades


Note: Projects are to be completed by each student individually (not by groups of students).

The purpose of this project is to compute the grade point averages for a number of students using the enrollment records for the students.

Example Inputs

The program is given a 'Student' file, a 'Grade' file, and a 'Query' file as input.

Student File

529173860
Dick B. Smith
879 Maple Road, Centralia, Colorado 24222
(312) 000-1000
925173870
Harry C. Anderson
635 Main Drive, Midville, California 48444
(660) 050-2200

Grade File

CHEM134
529173860
A
BOT180
925173870
B
PE273
925173870
D+
HIS431
529173860
B
BOT282
529173860
C+
ME527
925173870
E
BOT580
925173870
A-
ME305
925173870
A
HIS477
529173860
C

Query File

529173860
925173870

Example Output

The program outputs the entries from the Student file sorted by Student number. The program then outputs the entries from the Grade file sorted by Student number, Course, and Grade. The program then computes and reports the GPA for each student listed in the Query file.

Dick B. Smith
529173860
(312) 000-1000
879 Maple Road, Centralia, Colorado 24222
Harry C. Anderson
925173870
(660) 050-2200
635 Main Drive, Midville, California 48444

529173860	C+	BOT282
529173860	A	CHEM134
529173860	B	HIS431
529173860	C	HIS477
925173870	B	BOT180
925173870	A-	BOT580
925173870	A	ME305
925173870	E	ME527
925173870	D+	PE273

529173860	2.85	Dick B. Smith
925173870	2.42	Harry C. Anderson

Testing

Here are some ideas for tests.

  1. An empty Student file.
  2. An empty Grade file.
  3. An empty Query file.
  4. A query student ID that is not found in the Student file.
  5. A query student ID that is not found in the Grade file.
  6. A Student file that lists the same student more than once.

Student File Format

The 'Student' file gives the student number, name, address, and phone for each student. The information about each student is given on four separate lines in the file. There are no blank lines between students.

Grade File Format

The 'Grade' file gives the course, student number and grade for each course enrollment. The information about each enrollment is given on three separate lines in the file. There are no blank lines between entries.

Query File Format

The 'Query' file contains a list of student numbers. Each student number is given on a separate line.

Report Output Format

The report output file has three sections, the student output, the grade output, and the GPA output.

Student Output Format

The Student output consists of the entries from the Student file sorted by student number. Each part of a student entry is given on a separate line in the output. Name is first, Student number is second, Phone is third, and Address is last. There are no blank lines between students. There is exactly one blank line following the entire student output.

Grade Output Format

The Grade output consists of the entries from the Grade file sorted by Student number, Course, and Grade. Each entry from the Grade file is output on a single line. The Student number is output first, followed by a single tab character. The Grade is output next, followed by a single tab character. Finally the Course is output at the end of the line. There are no blank lines between grade entries. There is exactly one blank line following the entire grade output.

GPA Output Format

The GPA output gives the GPA for each student listed in the Query file. Each line of the GPA output contains Student number, GPA, and Name. The Student number is output first, followed by a single tab character. The GPA is output next, followed by a single tab character. Finally the Name is output at the end of the line. The GPA is formatted as a single digit followed by a decimal point and two more digits.

Computing GPAs

For each student number given in the Query file, use the information from the Grade file to compute the GPA for the student. If the given student number does not match any student in the Student file, do not give any output for that student number.

Compute the GPA by finding the average of all the grades with a matching student number in the Grade file. If the given student number has no matching grades in the Grade file, the GPA is 0.00.

Use the following point values for each grade.

          A = 4.0  A- = 3.7
B+ = 3.4  B = 3.0  B- = 2.7
C+ = 2.4  C = 2.0  C- = 1.7
D+ = 1.4  D = 1.0  D- = 0.7
          E = 0.0

Sorting Students

Sort the students in the 'Student' file in ascending order by student number.

To use the 'std::sort' function:

#include <vector>
#include <algorithm>
std::vector<Student> students;
std::sort(students.begin(), students.end());
  1. Include the needed header files.
  2. Create a 'vector' that holds the students to be sorted.
  3. Call sort with two parameters (the first and last items in the vector).

Comparing Students

When the std::sort function is sorting Student objects it will compare students by calling the less-than operator in the Student class. The std::sort function won't work unless the Student class has a less-than operator. Here's an example of the code you could add to your Student class to provide a less-than operator:

  bool operator < (Student s) const {
    return studentID < s.studentID;
  }

Sorting Grades

Sort the grades in the 'Grade' file in ascending order by student number. If two entries have the same student number, sort in ascending order by course. If two entries have the same student number and the same course, sort in ascending order by grade.

Comparing Grades

Here's an example of a less-than operator for the Grade class:

  bool operator < (Grade g) const {
    return studentID < g.studentID ||
      (studentID == g.studentID && course < g.course) ||
      (studentID == g.studentID && course == g.course && grade < g.grade);
  }

Implementation

  1. Your implementation needs to run on large files in a reasonable amount of time.
  2. How do you detect end-of-file when reading a file with getline? Put getline in the while condition:
       while (getline(in, s)) {
          ...
       }
    
  3. How do you output a GPA in the correct format?
       #include <iomanip>
       using namespace std;
       ...
       out << fixed << setprecision(2) << setfill('0') << gpa;
    
  4. Use ifstream (not fstream) when reading input files.

Command Line

The program is run with the names of the Student, Grade, Query, and Report files given on the command-line. For example the command could look like this:

lab1 student.txt grade.txt query.txt report.txt