首页 > 编程语言 >C++ Grade Book System

C++ Grade Book System

时间:2022-10-22 09:33:45浏览次数:67  
标签:set string Grade 0.0 System virtual grade Book assessment

C++ Grade Book System

Define and implement a grade book system. The grade book must use polymorphism to manage a collection of assessments of different types. The necessary classes are described below as well as the main().

The descriptions provide the basics of the class. You need to apply good design principles that have been demonstrated through the examples in the book and in class. You will need to apply inheritance to make a good heirarchy as well as proper visibility modifers, naming conventions, how you provide access to the internal data, potentially useful overloading, appropriate operator definitions, etc.

Your submission will consist of a single zip file that contains only the source code which will be a set of .h and .cpp files. There must be one .h and one .cpp file for each class. The main() should be in its own .cpp. You may include the input file.

Class: BadNameException

Class: UnknownStudentException

These are empty exception classes.

Class: Assessment

An Assessment represents an entry in the grade book. An Assessment has the following features:

It is an abstract class.
It maintains a name (string) attribute with virtual set/get operations. The set operation throws BadNameException if the supplied name is the empty string.
It has an abstract operation
virtual double getGrade()=0;
that returns a grade between 0.0 and 4.0.
The only constructor it has defined accepts a string which is the Assessments initial name. The constructor throws BadNameException if the supplied name is the empty string.

Class: GradeBook

A grade book manages a collection of assessments. Assessments are managed on a per student basis. So, each student has a collection of associated assessments. GradeBook has the following features:

It maintains a course name (string).
It maintains a collection of assessments organized by student.
It has only the following operations defined:

// This operation initializes the GradeBook class appropriately.
//
GradeBook();

// These operations set and get the course name, respectively.
//
virtual void   setName(string newCourseName);
virtual string getName();

// This operation places the assessment in the collection associated 
// to the named student.
//
virtual void addAssessment(string studentName, Assessment *newAssessment);

// This operation returns the grade for the student. The operation 
// will throw UnknownStudentException if the student is not in
// the grade book.
//

virtual double getGrade(string studentName);
When computing the grade you may assume that all assessments are of equal weight.

Class: Essay

The class is a concrete subclass of Assessment. It represents a writing activity and consists of single grade that is between 0.0 and 4.0. The class has one constructor that takes string representing the name of the essay assessment. It has two other operations:

// These operations set and get the grade, respectively. The grade is
// always between 0.0. If a provide grade is less than 0.0, the grade
// is set to 0.0 and if the grade is greater than 4.0 it is set to 4.0.
//
virtual void setGrade(double newGrade);
virtual double getGrade();

Class: TeamProject

TeamProject represents an assessment that is completed by teams of two or more people. The assessment has two components to the grade: individual grade and a team grade. The grade for the assessment is computed as the average to the two scores. The class has one constructor that takes a string representing the name of the team project assessment. It has five other operations

// These operations set and get the individual grade, respectively. The grade
// is always between 0.0. If a provide grade is less than 0.0, the grade is set
// to 0.0 and if the grade is greater than 4.0 it is set to 4.0.
//
virtual void   setIndividualGrade(double newGrade);
virtual double getIndividualGrade();


// These operations set and get the team grade, respectively. The grade is always
// between 0.0. If a provide grade is less than 0.0, the grade is set to 0.0 
// and if the grade is greater than 4.0 it is set to 4.0.
//
virtual void   setTeamGrade(double newGrade);
virtual double getTeamGrade();

// This operation returns the grade for the assessment.
//
virtual double getGrade();
GradeBook does not maintain a master list of assessments. A student's grade is based solely on their specific collection of assessments.

main()

The main operation must read in grade book data from a file and output to the console the grades for each student. The input file will look consist of an initial line with the name of the grade book followed by some number of lines that contain the grade information for a set of assessments. The lines will be in one of two formats.

If the line contains a grade for an essay it will look like

studentName, e, 3.3
where studentName is a string containing no whitespace, e represents an essay assessment, and the number value is the grade for the assessment.

If the line contains a grade for a team project it will look like

studentName, tp, 3.3, 3.0
where studentName is a string containing no whitespace, tp indicates a team project assessment, and the number values are the individual grade and team grade, respectively.

The following is an example of an input file:

CMPSC 122
tom tp 3.33 3.0
fred tp 3.33 3.0
susan e 3.67
fred e 2.33
tom e 2.67
susan e 3.67
susan tp 3.0 3.33

Notice no assumption is made about the order of the assessment instances nor is there any assumption that each student has the same number of assessments.

The output should look something like

Grades for CMPSC 122
tom: 2.92
fred: 2.75
susan: 3.50

The grade should be shown to two decimal places.

源码传送门

传送门:https://pan.baidu.com/s/1FZttqUlu64mg0qDxGYrvDQ?pwd=1111

标签:set,string,Grade,0.0,System,virtual,grade,Book,assessment
From: https://www.cnblogs.com/codewriter/p/16815323.html

相关文章