Looking for some help: Objective: Classes, objects, data members, member functio
ID: 3682988 • Letter: L
Question
Looking for some help:
Objective: Classes, objects, data members, member functions, and header files. .
Problem Specification: 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 header file that contains the class declaration and interface for the class that will maintain objects of the class.
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.
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...
********Main file contains:
#include <iostream>
#include <iomanip>
#include <string>
#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 <<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 (y/n): ";
cin >> answer;
answer = toupper(answer);
}while (answer == 'Y');
cin.get();
return 0;
}
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
#include “proj1.h”
using namespace std;
class Student {
public
Student();
}
Student :: Student() {
cout << “Enter Student Name”;
String s;
s = cin.get();
int count = 0;
}
~Student() {
delete s; }
void add( double score) {
double ts = score;
if(a == isFull()) {
cout << “ Score cannot be added” << end1;
} else if(a == isEmpty()){
a.push_back(ts);
count++;}
else { a.push_back(ts);
count ++; }
cout << “Count:”<< count; }
void remove() {
if(a == isFull()) {
a.pop_back();
count --;}
else if(a == isEmpty()){
cout<< “Score cannot be removed”;
else { a.pop_back();
count --;}
cout<< “Count:” << count; }
void clear() {
cout << “ Student name “ << stud1;
reverse(a,n);
cout<< “ Array Elements: “ <<a; }
reverse(double[] a,int n) {
n=5;
int temp;
for(i=n;i>=0;i--) {
cout<<a[i];}
return a[];
}
int main(int argc, char** argv)
{
Student stud1;
char choice, answer;
int score;
int n;
std:: vector <double> a;
cout<< “Enter maximum no of test scores”;
cin >>n;
for(n=0;n<=5;n++)
{
do
{
system("CLS");
cout <<setw(30)<< " Main Menu ";
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))
cout << score << " Added ";
break;
case '2':
case 'R':
if(stud1.remove())
cout << " Removed ";
break;
case '3':
case 'C':
stud1.clear();
break;
}
cout << "Another Operation (y/n): ";
cin >> answer;
answer = toupper(answer);
} while (answer == 'Y');
}
if (n>5) {
cout<< “ Test Score number exceeded” << end1; }
cin.get();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.