CS135 Student Grade Calcuation–Structs Solved

25.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

Purpose:       After completing this assignment, you will be able to:

  • Show how to create a user-defined data type
  • Demonstrate how to use structs in a C++ program

Task: Write a C++ program which reads in several files of data containing student grade information and calculates each student’s course grade and outputs them to a file.

Discussion: You program should utilize six filenames as command-line arguments. The files are formatted in the following manner:

  • student info.txt—student id, student name
  • assignment info.txt – assignment number, points available
  • assignment scores.txt – student id, assignment number, points scored
  • txt – exam number, points available, exam weight
  • txt – student id, exam number, points scored • output file—formatted according to the example later on.

Here is an example of the input files:

$ more student_info.txt

  • Bill
  • Jill
  • Fred $

$ more assignment_info.txt

  • 10
  • 100

$

$ more assignment_scores.txt

  • 1 9
  • 1 10
  • 2 83
  • 2 97
  • 2 80

$

$ more exam_info.txt

  • 92 .3
  • 120 .4

$

$ more exam_scores.txt

  • 1 78
  • 1 89
  • 1 65
  • 2 85
  • 2 93
  • 2 54

$

To calculate the course total, use the following rules of thumb:

  • Assignments are worth 30% of the course grade
  • Each exam is worth the indicated weight percentage in the exam info file
  • If a student does not have a grade indicated for a particular graded item, then a grade of zero (0) should be assumed. For example, in the output above, Fred does not have a grade for Assignment 1, so Fred receives a 0 for that assignment.
  • The overall course grade can be calculated using the formula:

(hw per * hw wt) + (ex1 per * ex1 wt) + (ex2 per * ex2 wt) + …+ (exN per * exN wt)

Your program must read in the data using an array of structs. You should define three user-defined data types as structs in your program:

  • Assignment—
    • id (int)
    • points available (int)
    • points scored (int)

You should also declare three static variables within the Assignment struct definition:

  • number of assignments (int), initialized to zero
  • total assignment points (int), initialized to zero
  • total weight of assignments (float), initialized to the ASSIGNMENT WEIGHT constant
  • Exam—
  • id (int)
  • points available (int)
  • points scored (int)
  • percentage (float)
  • weight (float)

You should also declare one static variable within the Exam struct definition:

  • number of exams (int), initialized to zero
  • Student—
    • id (int)
    • name (string)
    • assignments (array of Assignment structs)
    • assignment percentage (float)
    • exams (array of Exam structs)
    • grade percentage (float)
    • letter grade (string)

You should also declare one static variable within the Student struct:

  • number of students (int), initialized to zero

You must utilize the provided preprocessor, named constant declarations, and main function to get started with your program. Looking at the main function plus the algorithms required to solve the rest of the program, it is clear you must write the following functions:

  • readSetupData—a void function that reads the student info, exam info, and assignment info into the array of student structs. This function must take in the student info filename, exam info filename, assignment info filename, and array of Student structs.
  • readScoreData—a void function that reads the score data for assignments and exams, and updates the appropriate Student in the array of Student structs for the given info. This function must take in the exam scores filename, the assignment scores filename, and the array of Student structs.

The readScoreData function will require you to also define the following helper functions:

  • findStudent—a value-returning function that takes in a student id and the array of Student structs, and returns the index position of the Student with the given id.
  • findExam—a value-returning function that takes in an exam id and an array of Exam structs, and returns the index position of the exam in the array.
  • findAssignment—a value-returning function that takes in an assignment id and an array of Assignment structs, and returns the index position of the assignment in the array.

Continuing the functions required from looking at the main function:

  • calculateGrades—a void function that calculates the grade percentages for assignments, exams, and overall course percentage, and the overall letter grade for the course. This function should take in only the array of Student structs.
  • writeGradeData—a void function that writes the grading data for each student to the output file. This function should take in the output filename and the array of Student structs.

Use the provide code below to get started with your program:

#include <cmath> // round

#include <cstdlib> // atoi, exit

#include <fstream> // ifstream, ofstream

#include <iomanip> // setprecision #include <iostream> // cout, fixed using namespace std;

const int MAX_STUDENTS = 40; const int MAX_ASSIGNMENTS = 20; const int MAX_EXAMS = 3; const float ASSIGNMENT_WEIGHT = .3;

const float DMINUS = 60.0; const float D = 63.0; const float DPLUS = 67.0; const float CMINUS = 70.0; const float C = 73.0; const float CPLUS = 77.0; const float BMINUS = 80.0; const float B = 83.0; const float BPLUS = 87.0; const float AMINUS = 90.0; const float A = 93.0;

// **************

// YOUR CODE HERE // **************

int main(int argc, char *argv[]) { // filename and filestream variables string sfile, efile, afile, escores, ascores, ofile;

// keep track of each Student in an array Student students[MAX_STUDENTS];

// check command-line args if (argc != 7) { cout << “Must supply required filenames in the correct order:”

<< endl; cout << ”          ./a.out <studinfo> <exinfo> <hwinfo> <exscores>

<hwscores> <outfile>” << endl;

exit(1);

}

// grab the command-line args sfile = argv[1]; efile = argv[2]; afile = argv[3]; escores = argv[4]; ascores = argv[5]; ofile = argv[6];

// process the files, do the calculations, and write the output readSetupData(sfile, efile, afile, students); readScoreData(escores, ascores, students); calculateGrades(students); writeGradeData(ofile, students);

return 0;

}

Criteria:           Submissions must adhere to the criteria specified in the syllabus. Your program should run like this:

$ g++ cs135-grade-calc.cpp

$ ./a.out stud_info.txt exam_info.txt hw_info.txt exam_scores.txt \ hw_scores.txt grades.out

$ more grades.out

Id       Name               Assignments            Exam 1           Exam 2            Crs Grade

———————————————————–

1             Bill 83.6 84.8 70.8 78.9 (C+)
2             Jill 97.3 96.7 77.5 89.2 (B+)
3           Fred

$

72.7 70.7 45.0 61.0 (D-)

 

  • Struct-OOP.zip