Question
Objective: To learn to handle pointer variables and use dynamic arrays to manipulate data in a class. Tasks: In this programming assignment, you will write
Objective: To learn to handle pointer variables and use dynamic arrays to manipulate data in a class. Tasks: In this programming assignment, you will write a program that defines a class called Student whose objects can have a flexible number of scores. The program prompts the user for the following information: first name and last name of a student, the maximum number of scores, and the actual scores of a student. For example, a student may have a maximum of 10 scores but actually input 5 scores. After all the scores are entered, the program calculates the student average score. The program should output students information including a students first name and last name, the actual number of scores, a list of all the scores, and the average score. A sample output (partial) is shown in Figure 1. Your program should define a class Student and implement it as required. The class Student should have the following private member variables. Member Variable Description 1 firstName A string variable that holds a students first name. 2 lastName A string variable that holds a students last name. 3 maxSize An int variable that represents the maximum number of scores. 4 size An int variable that represents the actual number of scores entered for a student. 5 scores A pointer variable of type int that stores the address of an int dynamic array. The dynamic array is to store the student scores. The class Student should also have the following public member functions. Member Function Description 1 A constructor with default parameters This constructor has three formal parameters and use them to initialize firstName, lastName, and maxSize member variables. The default values are empty string for firstName and lastName, and 10 for maxSize. The value for maxSize should be positive, otherwise use 10 instead. The constructor also initializes size to 0 and creates a dynamic array of size maxSize whose address is stored in the pointer variable scores. 2 setFName Accepts a string argument and copies it into the firstName member variable. 3 setLName Accepts a string argument and copies it into the lastName member variable. 4 getFName Returns the value in firstName. 5 getLName Returns the value in lastName. 6 getNumScores Returns the actual number of scores, i.e., the value in size. 7 insertEnd Accepts a score and inserts it to the end of the current list of scores if the current number of scores is less than the maximum number of scores, otherwise outputs an error message Exceeds the maximum number of scores. 8 getAverage Calculates and returns the average score. 9 printStudent Outputs a students first name and last name, the actual number of scores, a list of all the scores, and the average score. 10 A destructor To destroy the dynamic array. 11 A copy constructor A constructor that creates a new Student object using another Student object. 12 Overloaded assignment operator = Overloads the assignment operator = to assign one Student object to a Student variable. The main function should contain statements to test class member functions including the constructor with default values, copy constructor, overloaded assignment operator, insertEnd, printStudent, and other member functions. Data validation and error handling is required. A valid score is between 0 and 100, inclusive. Display an error message if a score is invalid and allow the user to reenter a score or quit. The actual number of scores should be no more than the maximum number of scores. Display an error message Exceeds the maximum number of scores if the user tries to enter a score that exceeds the maximum number of scores. Submission: You should submit a ZIP file that contains three files on the following names:: the header file Student.h, the class implementation file Student.cpp, and the test program hw5main.cpp.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started