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

Please some help here: Objective: Classes, objects, data members, member functio

ID: 3685086 • Letter: P

Question

Please some help here:

Objective: Classes, objects, data members, member functions, and header files...

CREATE A HEADER FILE proj1.h (that CONTAINS CLASS declaration) , THE INTERFACE CLASS and the implementation file BASED ON THE FOLLOWING FILE:

********Main file contains:

#include
#include
#include
#include "proj1.h"

using namespace std;

int main(int argc, char** argv)

{  
    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 <     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 (y/n): ";
     cin >> answer;
    answer = toupper(answer);

}while (answer == 'Y');
   
cin.get();
return 0;  

}

Problem Specification:

THE 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.

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.

The test scores may be integers, floats or doubles. (Template class) Optional, I can fix it myself

Two methods are defined to determine if the array isFull or isEmpty.

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”

Class templates are used to accommodate different types.

Accessor methods are constants and parameters passed are also constants

Clear method calls the print function which prints the array elements last to...

Thanks

Explanation / Answer

//declaring constant number of scores
static const int num_scores = 5;
//declaring array of scores
float scores[num_scores];
//implementing add score method
void addScore(float score){
   int i=0;
   while(i<num_scores){
       if(scores[i]!=0)
           i++;
   }
   //if empty array insert at first position
   if(isEmpty())
       scores[0] = score;
   //if full array output a message
   else if(isFull())
       cout << "scores array is full "<<endl;
//else insert score at the end
   else
       scores[i] = score;
}
//implementing remove method
void remove()
{
   int i=0;
//if empty array send message to output
   if(isEmpty())
       cout << "score cannot be removed as scores array is empty "<<endl;
   else
   {
       while(i<num_scores){
       if(scores[i]!=0)
           i++;
       }
//else remove last element in array
       scores[i-1]=0;
   }
}
//implementing clear method
void clear()
{
   int i;
   cout << "scores array contents backward: " << endl;
   for(i=num_scores;i>0;i--)
       cout << scores[i] << endl;
   for(i=num_scores;i>0;i--)
       scores[i] = 0;
}
boolean isEmpty()
{
   if(scores[0] == 0)
       true;
return false;
}
boolean isFull()
{
   if(scores[num_scores-1]!=0)
       return true;
return false;
}