Class and Data members: Create a class called Student that stores a student’s grades (integers) in a vector (do not use an array). The class should have data members that store a student’s name and course for which the grades are earned. Constructor(s): The class should have a 2-argument constructor that receives the student’s name and course as parameters and sets the appropriate data members to these values. Member Functions: The class should have functions as follows: Member functions to set and get the student’s name and course variables. A member function that adds a single grade to the vector. Only positive grades are allowed. Call this function AddGrade. A member function to sort the vector in ascending order. A member function to compute the average (x̄) of the grades in the vector. The formula for calculating an average is x̄ = ∑xi / n where xi is the value of each grade and n is the total number of grades in the vector. A member function to determine the lowest grade in the vector and a separate member function to determine the highest grade in the vector (they must contain an algorithm to search through the vector to determine the minimum or maximum value) A member function (getNumGrades) to return the number of grades that are stored in the vector (vector should be private).Therefore, you can create a public getNumGrades function that will simply return the size of the vector. A member function to display the student’s name, course, and vector of sorted grades. Write a program (client) that uses the class by creating a Student object and prompting the user for a file name. Appropriate error checking is required to ensure that the file exists and can be opened successfully. Also, the name of the file may contain a space; therefore, be sure to use getline instead of cin when you prompt the user to enter the name of the file. The client should read in the file contents and store them in the object. The file will be formatted such that the first line contains the student’s name, the second line contains the course name, and each successive line contains a grade. A typical input file might contain: John Smith CSIS 112 90 85 97 91 87 86 88 82 83 The client (i.e. main()) should read in the contents of the file. After each grade is read in, it should call the addGrade member function in the Student class to add the new grade (i.e. one grade at a time) to the vector. [Do not create a vector in main and pass the entire vector in to the addGrade function in the Student class. Pass in only one grade at a time and allow the addGrade function to add it to the vector of grades in the class.] Main() should then produce a report that displays the student’s name and course, the total number of grades in the file, the lowest grade, the highest grade, the average of all the grades, and finally, a listing of all of the grades that were read in. The listing of all of the grades must be displayed in sorted order (ascending – from lowest to highest). If a non-numeric or negative value is encountered in the file when reading in the grades, the program should output an error message indicating that a non-numeric or negative value was found in the file, and the entire program should then terminate. If a non-numeric or negative value is found, consider the entire file to be corrupted and don’t try to produce any calculations nor display the contents of the vector – just end the program with an appropriate error message.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Class and Data members:

Create a class called Student that stores a student’s grades (integers) in a vector (do not use an array).  The class should have data members that store a student’s name and course for which the grades are earned.

Constructor(s):

The class should have a 2-argument constructor that receives the student’s name and course as parameters and sets the appropriate data members to these values.

Member Functions:

The class should have functions as follows:

  1. Member functions to set and get the student’s name and course variables.
  2. A member function that adds a single grade to the vector. Only positive grades are allowed.  Call this function AddGrade.
  3. A member function to sort the vector in ascending order.
  4. A member function to compute the average (x̄) of the grades in the vector. The formula for calculating an average is

    x̄ = ∑xi / n  where xi is the value of each grade and n is the total number of grades in the vector.

  5.  

     

     A member function to determine the lowest grade in the vector and a separate member function to determine the highest grade in the vector (they must contain an algorithm to search through the vector to determine the minimum or maximum value)

  6. A member function (getNumGrades)  to return the number of grades that are stored in the vector (vector should be private).Therefore, you can create a public getNumGrades function that will simply return the size of the vector.
  7. A member function to display the student’s name, course, and vector of sorted grades.

Write a program (client) that uses the class by creating a Student object and prompting the user for a file name. Appropriate error checking is required to ensure that the file exists and can be opened successfully.  Also, the name of the file may contain a space; therefore, be sure to use getline instead of cin when you prompt the user to enter the name of the file.

The client should read in the file contents and store them in the object. The file will be formatted such that the first line contains the student’s name, the second line contains the course name, and each successive line contains a grade. A typical input file might contain:

John Smith

CSIS 112

90

85

97

91

87

86

88

82

83

The client (i.e. main()) should read in the contents of the file.  After each grade is read in, it should call the addGrade member function in the Student class to add the new grade (i.e. one grade at a time) to the vector. [Do not create a vector in main and pass the entire vector in to the addGrade function in the Student class.  Pass in only one grade at a time and allow the addGrade function to add it to the vector of grades in the class.]

Main() should then produce a report that displays the student’s name and course, the total number of grades in the file, the lowest grade, the highest grade, the average of all the grades, and finally, a listing of all of the grades that were read in.  The listing of all of the grades must be displayed in sorted order (ascending – from lowest to highest). 

If a non-numeric or negative value is encountered in the file when reading in the grades, the program should output an error message indicating that a non-numeric or negative value was found in the file, and the entire program should then terminate.  If a non-numeric or negative value is found, consider the entire file to be corrupted and don’t try to produce any calculations nor display the contents of the vector – just end the program with an appropriate error message. 

 

### Transcript and Explanation for Educational Purpose

#### Transcript of First Image

```
Enter the name of the file: John Smith Grades.txt
10 grades were recorded for this course.

Statistics
Average:       79.7
Lowest grade:   12
Highest grade:  97

The grades for John Smith - CSIS 112 are:
12
82
82
83
85
87
88
90
91
97
Press any key to continue . . .
```

#### Transcript of Second Image

```
Enter the name of the file: grades.txt
A negative grade was found in the file...Exiting program.
Press any key to continue . . .
```

### Explanation

In the **first image**, a program reads grades from a file named "John Smith Grades.txt". It records ten grades and calculates the following statistics:
- **Average**: 79.7
- **Lowest grade**: 12
- **Highest grade**: 97

The grades listed for the course CSIS 112 are: 12, 82, 82, 83, 85, 87, 88, 90, 91, 97.

The emphasis is on maintaining the decimal precision when calculating averages to avoid incorrect truncation. For instance, truncating an average of 89.9 to 89 could unintentionally affect outcomes.

The concept of **integer division** is mentioned, where dividing two integers results in an integer. To obtain a precise average, convert one or both numbers into a floating-point number (e.g., a double) before dividing.

In the **second image**, the program is designed to ensure data integrity by checking for invalid inputs. It detects a negative grade in the file "grades.txt" and exits, notifying the user with a message.

This approach emphasizes the importance of validating input data to maintain the accuracy and reliability of statistical calculations.
Transcribed Image Text:### Transcript and Explanation for Educational Purpose #### Transcript of First Image ``` Enter the name of the file: John Smith Grades.txt 10 grades were recorded for this course. Statistics Average: 79.7 Lowest grade: 12 Highest grade: 97 The grades for John Smith - CSIS 112 are: 12 82 82 83 85 87 88 90 91 97 Press any key to continue . . . ``` #### Transcript of Second Image ``` Enter the name of the file: grades.txt A negative grade was found in the file...Exiting program. Press any key to continue . . . ``` ### Explanation In the **first image**, a program reads grades from a file named "John Smith Grades.txt". It records ten grades and calculates the following statistics: - **Average**: 79.7 - **Lowest grade**: 12 - **Highest grade**: 97 The grades listed for the course CSIS 112 are: 12, 82, 82, 83, 85, 87, 88, 90, 91, 97. The emphasis is on maintaining the decimal precision when calculating averages to avoid incorrect truncation. For instance, truncating an average of 89.9 to 89 could unintentionally affect outcomes. The concept of **integer division** is mentioned, where dividing two integers results in an integer. To obtain a precise average, convert one or both numbers into a floating-point number (e.g., a double) before dividing. In the **second image**, the program is designed to ensure data integrity by checking for invalid inputs. It detects a negative grade in the file "grades.txt" and exits, notifying the user with a message. This approach emphasizes the importance of validating input data to maintain the accuracy and reliability of statistical calculations.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY