Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

What is American Polity and Governance ?

Answered: 1 week ago

Question

3. Explain the forces that influence how people handle conflict

Answered: 1 week ago