Microsoft Word - BCS230_182_homework5.docx BCS 230: Foundations of Computer Programming II CRN 90110, 90111 Fall 2018 Instructor: Dr. Jie Li...

1 answer below »
Please see the attachment.


Microsoft Word - BCS230_182_homework5.docx BCS 230: Foundations of Computer Programming II CRN 90110, 90111 Fall 2018 Instructor: Dr. Jie Li ---------------------------------------------------------------------------------------------------------------------------------- Homework 5 − Wednesday, November 14 Due Saturday, December 8, 11:59PM on Blackboard ---------------------------------------------------------------------------------------------------------------------------------------------------------- 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 student’s information including a student’s 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 student’s first name. 2 lastName A string variable that holds a student’s 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 of size. 7 appendScore Accepts a score and appends 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 student’s first name and last name, the actual number of scores, a list of all the scores, and the average score (with 2 decimal places). 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, appendScore, printStudent, and other member functions. Data validation and error handling is required. A valid score is between 0 and 100. Display an error message if a score is invalid and allow the user to reenter a score or quit when the user enters a value of -1. 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 (case-sensitive): the header file Student.h, the class implementation file Student.cpp the test program hw5main.cpp. Do NOT use any other file names. Be sure to include the integrity statement “I certify that this submission is my own original work” with your name and RAM ID in each source file. Extra credit: Write two extra member functions: setScores: Accepts two arguments, an int array (storing scores) and an integer (storing the number of the scores in the array) and copies the scores into the dynamic array member variable. If the number of scores in the argument exceeds the maximum number of scores, only copy the scores up to the maximum number of scores. getScores: Returns a student’s scores using a pointer variable. In the main function, add statements to test these two member functions. Figure 1. Sample Output If a user enters an invalid score, the program displays an error message “The score is invalid”. If more score than the maximum number of scores is entered, the program displays an error message “Exceeds the maximum number of scores” and quits data input. User enters less scores than the maximum number of scores
Answered Same DayDec 05, 2020BCS230

Answer To: Microsoft Word - BCS230_182_homework5.docx BCS 230: Foundations of Computer Programming II CRN...

Snehil answered on Dec 05 2020
152 Votes
hw5main.cpp
#include
#include
#include "Student.h"
using namespace std;
int main()
{
//Get user input
string fName, lName;
int mSize;
cout<<"Enter the student's first name: ";
cin>>fName;
cout<<"Enter the student's last name: ";
cin>>lName;
cout<<"Enter the maximum number of scores: ";
cin>>mSize;
//Shows constructor usage with parameters
Student s1(fName,lName,mSize);
int score;
while(true)
{
cout<<"Enter an integer scores between 0 and 100 or enter '-1' to exit: ";
cin>>score;
if(score==-1)
{
break;
}
else if(score>=0 && score<=100)
{
if(s1.appendScore(score)==false)
{
break;
}
}
else
{
cout<<"Invalid Score";
}
}
s1.printStudent();
//shows constructor usage without parameters
Student s2;
s2.printStudent();
//Shows setScores method usage
Student s3("Tony","Stark",5);
s3.printStudent();
int scores1[3]={33,87,46}, scores2[7]={10,20,30,40,50,60,70};
s3.setScores(scores1,3);
s3.printStudent();
s3.setScores(scores2,7);
s3.printStudent();
//Shows copy constructor
Student s4=s3;
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here