You are working for a university to maintain a list of grades and some related statistics for a student.
Class and Data members:
Create a class called Student that stores a student’s grades (integers) in a
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. When using a vector, you can manipulate it just like an array.
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. [Note that to receive credit for these functions, they must contain an
6. A member function (e.g. getNumGrades) to return the number of grades that are stored in the vector. Remember that a vector knows its own size. Therefore, you don’t need to keep track of the number of items stored in a vector in a separate data member in the class. You also don’t want to make your vector public – it 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
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
Note that the file may contain any number of grades for a given course. Therefore, you need to read in and store each grade until you reach the end of the file.
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).
All output should be labeled appropriately, and validity checking should be done on input of the filename and also the grades that are read in.
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. [Make sure the error message is displayed long enough for the user to read it before ending the program. – you may use the system(“pause”) command for this. Note that there are several security and performance issues with using system commands, and you’ll learn more about these later, but for now, feel free to use the system(“pause”) command. ]
The executing program should look something like this:
visual studio c++ code
Trending nowThis is a popular solution!
Step by stepSolved in 9 steps with 10 images
i keep getting an error for the getline(infile,studentName);
i keep getting an error for the getline(infile,studentName);
- private Vector location;private Vector velocity;private Vector acceleration;private int lifespan;private static final int MAX_LIFESPAN = 25;private static final int RADIUS = 7; public boolean isAlive() { } public void update() {//code here} Using java, if particle is alive then add velocity vector to location vector, add acceleration vector to velocity vector, and decrement lifespan by 1. Thank you.arrow_forwardAn n-sided regular polygon’s sides all have the same length and all of its angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon thatcontains:■ A private int data field named n that defines the number of sides in the polygon.■ A private float data field named side that stores the length of the side.■ A private float data field named x that defines the x-coordinate of the center of the polygon with default value 0. ■ A private float data field named y that defines the y-coordinate of the center of the polygon with default value 0.■ A constructor that creates a regular polygon with the specified n (default 3),side (default 1), x (default 0), and y (default 0).■ The accessor and mutator methods for all data fields.■ The method getPerimeter() that returns the perimeter of the polygon.■ The method getArea() that returns the area of the polygon. The formula for computing the area of a regular polygon is Area = (n * s2) / (4 *…arrow_forwardConvert the pseudocode into Python. 1. Pet ClassDesign a class named Pet, which should have the following fields:■ name: The name field holds the name of a pet.■ type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird".■ age: The age field holds the pet’s age.2. The Pet class should also have the following methods:■ setName: The setName method stores a value in the name field.■ setType: The setType method stores a value in the type field.■ setAge: The setAge method stores a value in the age field.■ getName: The getName method returns the value of the name field.■ getType: The getType method returns the value of the type field.■ getAge: The getAge method returns the value of the age field.3. Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the…arrow_forward
- 11:02 all 10% + Create 1 1000.01 Create 2 2000.02 Create 3 3000.03 Deposit 111.11 Deposit 2 22.22 Withdraw 4 5000.00 Create 4 4000.04 Withdraw 1 0.10 Balance 2 Withdraw 2 0.20 Deposit 3 33.33 Withdraw 4 0.40 Bad Command 65 Balance 1 Balance 2 Balance 3 Balance 4arrow_forwardMissing line of code pleasearrow_forwardInstructions: Turn all instances of classes into pointers. You will also need to combine the player and vector into one vector objects and fix all issues this causes. #ifndef ITEM_H #define ITEM_H class Item { public: Item() {}; enum class Type { sword, armor, shield, numTypes }; Item(Type classification, int bonusValue); Type getClassification() const; int getBonusValue() const; private: Type classification{ Type::numTypes }; int bonusValue{ 0 }; }; std::ostream& operator<< (std::ostream& o, const Item& src); bool operator< (const Item& srcL, const Item& srcR); int& operator+=(int& srcL, const Item& srcR); #endif // !ITEM_H #ifndef MONSTER_H #define MONSTER_H #include "Object.h" class Player; class Monster : public Object { public: Monster() {}; Monster(const Player& player); void update(Player& player, std::vector& monsters) override; int attack() const override; void defend(int damage) override; void print(std::ostream& o)…arrow_forward
- N-SIDED REGULAR POLYGON) In an n-sided regular polygon, all sides have the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: ▪ A private int data field named n that defines the number of sides in the polygon with default value 3. ▪ A private double data field named side that stores the length of the side with default value 1. A private double data field named x that defines the x-coordinate of the polygon's center with default value 0. ▪ A private double data field named y that defines the y-coordinate of the polygon's center with default value 0. A no-arg constructor that creates a regular polygon with default values. A constructor that creates a regular polygon with the specified number of sides and length of side, centered at (0, 0). A constructor that creates a regular polygon with the specified number of sides, length of side, and x- and y-coordinates. ▪ The accessor and…arrow_forwardPointer and classImplement a class called Team as specified:data members:name - the name of the Team (defined as a dynamic variable)members - a dynamic array of stringsize - number of members in the team.functions:Course(): default constructor set name to “TBD”, and size to 0, members toempty listCourse(string): one argument constructor set name, and size to 0, members toempty listaccessor - an accessor for the name and size variablemutator - an mutator for the name variableUse following main() to test your class.int main() {Team a,b("Mets");cout<<a.getName()<<endl; // print TBDa.setName("Yankee");cout<<a.getName()<<endl; // print Yankeecout<<b.getName()<<endl; // print Metscout<<a.getSize()<<endl; // print 0return 0;}arrow_forwardDice Rolling Class In this problem, you will need to create a program that simulates rolling dice. To start this project, you will first need to define the properties and behaviors of a single die that can be reused multiple times in your future code. This will be done by creating a Dice class. Create a Dice class that contains the following members: Two private integer variables to store the minimum and maximum roll possible. Two constructors that initialize the data members that store the min/max possible values of rolls. a constructor with default min/max values. a constructor that takes 2 input arguments corresponding to the min and max roll values Create a roll() function that returns a random number that is uniformly distributed between the minimum and maximum possible roll values. Create a small test program that asks the user to give a minValue and maxValue for a die, construct a single object of the Dice class with the constructor that initializes the min and max…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education