Question: how do you create a makefile for this? //Stack.h #pragma once #include #include #include using namespace std; template class Stack { struct Node { T

how do you create a makefile for this?

//Stack.h

#pragma once #include #include #include using namespace std;

template class Stack { struct Node { T data; Node *next; }; Node *head; public: Stack() { head = NULL; } ~Stack() { Node *cur = head, *tmp; while (cur != NULL) { tmp = cur->next; delete cur; cur = tmp; } } void push(T data) { Node *cur=head, *newNode; newNode = new Node; newNode->data = data; newNode->next = NULL; if (head == NULL) { head = newNode; } else { newNode->next = head; head = newNode; } }

T top() { return head->data; } void pop() { Node *tmp = head; head = head->next; delete tmp; } friend ostream& operator<<(ostream &out,Stack &data) { Node *cur = data.head; while (cur != NULL) { out << cur->data << " "; cur = cur->next; } return out; } bool isEmpty() { if (head == NULL) return true; return false; } };

=========================

//Student.h

#pragma once #ifndef STUDENT_H #define STUDENT_H #include #include #include using namespace std;

class Student { private: float gpa; string ssn; public: Student(); 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

===============================

#include #include #include "Student.h"

Student::Student() { gpa = 0; ssn = ""; } 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; }

=========================

//Main.cpp

#include #include #include"Stack.h" #include"Student.h" using namespace std;

int main() { //declare stack of int type Stack intStack; intStack.push(5); intStack.push(4); intStack.push(3); intStack.push(2); intStack.push(1); cout << "Top of intStack is : " << intStack.top() << endl; cout << "intStack items are : "; cout< StudentStack; Student st[5]; st[0].setGPA(3.5); st[0].setSSN("111111111"); st[1].setGPA(3.5); st[1].setSSN("222222222"); st[2].setGPA(3.5); st[2].setSSN("333333333"); //push some students onto stack StudentStack.push(st[0]); StudentStack.push(st[1]); StudentStack.push(st[2]); Student pt = StudentStack.top(); cout << "Top of the stack is : " << endl; pt.print(); cout << "Print stack after one pop operation: "; StudentStack.pop(); while (!StudentStack.isEmpty()) { pt = StudentStack.top(); StudentStack.pop(); pt.print(); }

}

/*Output Top of intStack is : 1 intStack items are : 1 2 3 4 5 intStack items after one pop operation: 2 3 4 5 Top of the stack is : gpa: 3.5 ssn: 333333333 Print stack after one pop operation: gpa: 3.5 ssn: 222222222 gpa: 3.5 ssn: 111111111

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!