Question: Design a bag that will do the following: Accept a student's name (string) and maintains an array of test scores. Methods are, Add which adds
Design a bag that will do the following:
Accept a student's name (string) and maintains an array of test scores. Methods are,
Add which adds 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. The function Add is a Boolean function that returns true when an item is added, otherwise it returns false.
Remove which removes the last score; scores in the middle or front, cannot be removed. If the array is empty then you cannot remove and must indicate that. The function Remove is a Boolean function that returns true when an item is removed, otherwise it returns false.
clear which clears the array of all the scores, but before you do that, you must call the private function print, which will print the name and data in reverse order, that is, the last score in the array will be printed first and so on.
Client File
#include #include #include #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 <> 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'); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
