Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi guys, I need some help with this program Design a class that will do the foll

ID: 3682291 • Letter: H

Question

Hi guys, I need some help with this program

Design a class that will do the following:

Accept a student’s name (string) and maintains an array of test scores (float). If there is

room you can add a score at the first available position. That is the position immediately

following the last added score. If the array is empty, you add at the first position. If the

array is full, then you cannot add and must indicate that. If there are scores in the array,

you can remove the last score; scores in the middle or front may not be removed. If the

array is empty then you cannot remove and must indicate that. You can also clear the

array of all the scores, but before you do that you must print the name and contents of the

array backward.

Requirements:

Create a CRC card

Define a default constructor that will ask for a student name to be entered from

       the keyboard and stores it. It also initializes a counter that keeps track of the number of

       scores in the array and is maintained when you add, remove, or clear.

Define a null destructor.

The maximum number of test scores is 5 and is stored in the class data as a static

      constant.

Two methods are defined to determine if the array is Full or is Empty.

The file “proj1.cpp” is the client file that tests the methods defined in the

implementation file and declared in the header file called “proj1.h”

Main file of the program:

#include <iostream>
#include <iomanip>
#include <string>
#include "proj1.h"

using namespace std;

int main()
{   Student stud1; // a student
    char choice, answer; // handles input from menu and controls loop
    int score;             // the iten to be added to the end of the array
     do{
    system("CLS");          // clears the screen
    cout <<setw(30)<< " Main Menu ";   // menu of options to add/remove or clear
    cout << setw(15)<< " "<< "(1)- (A)dd ";
    cout << setw(15)<< " "<< "(2)- (R)emove ";
    cout << setw(15)<< " "<< "(3)- (C)lear ";
    cout << setw(35)<< "Enter Choice ";cin >> choice;
    choice = toupper(choice);
    switch (choice)
    {   case '1':
        case 'A':
                cout << " Add what Score "; cin >> score;
                if (stud1.add(score))       // call to the add method
                    cout << score << " Added ";
                break;
        case '2':
        case 'R':
                if(stud1.remove())          // call to the remove method
                    cout << " Removed ";
                break;
        case '3':
        case 'C':
                stud1.clear();              // call to the clear method
                break;
     }
     cout << "another Operation "; cin>> answer; answer = toupper(answer);
    }     while (answer == 'Y');
cin.get();
return 0;  
}

Explanation / Answer

Here is the code for the class Student, which should be placed in the proj1.h file:

#include <iostream>
using namespace std;
class Student
{
//Accept a student’s name (string) and maintains an array of test scores (float).
string name;
float testScores[10];
int numOfScores;
public:
Student()
{
name = "";
numOfScores = 0;
}
Student(string nm)
{
name = nm;
numOfScores = 0;
}
//If there is room you can add a score at the first available position.
//That is the position immediately following the last added score.
//If the array is empty, you add at the first position.
//If the array is full, then you cannot add and must indicate that.
bool add(float scr)
{
if(numOfScores == 10)
{
cout<<"Score card is full. Cannot add scores anymore."<<endl;
return false;
}
else
testScores[numOfScores++] = scr;
return true;
}
//If there are scores in the array, you can remove the last score;
//scores in the middle or front may not be removed. If the
//array is empty then you cannot remove and must indicate that.
int remove()
{
float temp;
if(numOfScores == 0)
{
cout<<"Score card is empty. Cannot remove scores anymore."<<endl;
return -1;
}
else
temp = testScores[numOfScores--];
return temp;
}
//You can also clear the array of all the scores, but before you do that
//you must print the name and contents of the array backward.
void clear()
{
cout<<"Name: "<<name<<". Scores: ";
while(numOfScores > 0)
{
cout<<testScores[numOfScores-1]<<" ";
numOfScores--;
}
cout<<endl;
}
};
If you need any refinements, just get back to me.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote