Please some help here (it has been a week and i can get the right program done)
ID: 3686328 • Letter: P
Question
Please some help here (it has been a week and i can get the right program done)
This is for an ADT program based on Classes.
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 <iostream>
#include <string>
#include <iomanip>
#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:
default constructor accepts 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...
Explanation / Answer
student.h:
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Student
{
private:
const static int score = 5;
string name;
T tests[score];
int itemCount;
public:
Student()
{
name = "";
cout << "Please enter the student name: ";
cin >> name;
itemCount = 0;
}
~Student(){}
bool isEmpty() const;
bool isFull() const;
template<K>
bool add(T);
template<T>
bool remove();
template<T>
bool clear();
void print(int) const;
};
#endif
template <class T>
bool Student <T> :: add(T test)
{
if (isEmpty())
{
test[itemCount]= test;
return true;
}
else
{
if (isFull())
{
cout << " All tests have been taken ";
return false;
}
else
{
test[itemCount++]= test;
return true;
}
}
}
Main Program:
#include <iostream>
#include <iomanip>
#include <string>
#include "student.h"
using namespace std;
int main()
{ Student<float> stud1; // a student
char choice, answer; // This will handle the 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 ";
else
cout << " Array is full, cannot add more ";
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;
}