Question
(1) A templatized Stack Modify the code below to make the ADT Stack that is a template class has the code of the destructor in
(1) A templatized Stack
Modify the code below to make the ADT Stack that
- is a template class
- has the code of the destructor in which each node is directly deleted without using any member function. As each node is deleted, the destructor displays the address of the node that is being deleted.
(2) Testing
With a reference to main.cpp provided, enhance it so that you test Stack class for int type and Student type that are attached with this assignment. The required details are as follows.
- Each member function of the Stack class must be clearly tested for each data type, int and Student (16 tests = 8 member functions * 2 data types)
- From the output, the instructor must be able to clearly see what test is being done and how it is done.
- Do not interact with the user to receive inputs so that program testing time can be reduced.
- When you fill the stack with many keys or elements, use a loop for efficiency.
- Provide a makefile and remove unused functions and files.
HEADER FILE
#ifndef STUDENT_H #define STUDENT_H #include using namespace std;
class Student { private: float gpa; string ssn; public: void setGPA(float v); void setSSN(string s); void print();
class OutOfGPARange { }; // empty inner class definition under public class InvalidSSN { }; // empty inner class definition under public }; #endif
CPP FILE
#include #include "Student.h"
void Student::setGPA(float g) { //assert(g >= 0.0 && g <= 4.0);
//create an instance of the OutOfGPARange class, called exception if (g < 0.0 || g > 4.0) throw OutOfGPARange(); gpa = g; } void Student::setSSN(string s) { const int SSN_LENGTH = 9; if (s.length() != SSN_LENGTH) throw InvalidSSN(); //Checking each character is a digit should be here //Otherwise, throw InvalidSSN(); ssn = s; } void Student::print() { cout << "gpa: " << gpa << endl; cout << "ssn: " << ssn << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started