Modifying a stack to a set

Hi all, got a stack example here that I've been modifying in Visual studio, Can anyone explain how I would modify this into a class for a Set?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// objectTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Student.h"
#include <stack>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	//Create and refer to objects in a Java style
	Student s("Bobby Bobster","Professor Smith","12/12/1912");
	s.getDetails();

	//Refer to an object via a pointer
	Student *ptr;
	ptr = new Student("Steve Student","Mr Lecturer","17/11/1980");
	ptr->getDetails();

	//Create an array of objects. Note that arrays make use of the 
	//default constructor.
	Student *arrayPtr = new Student[10];
	for (int i = 0; i < 10; i++)
	arrayPtr[i].getDetails();
	getchar();

	//Create a stack of students and perform some straightforward 
	//functions (push, pop, top and empty)
	//Note that the template allows us to create a stack of objects
	//not just simple types (int, double, string, etc.)
	stack<Student> myStack;
	myStack.push(s);
	myStack.push(*ptr);
	myStack.push(arrayPtr[0]);
	cout << "The contents of the stack are..." << endl << endl;
	while (!myStack.empty())
	{
		myStack.top().getDetails();//examine carefully
		myStack.pop();
	}
	getchar();

	//Release the memory taken up by the pointers. Note that this 
	//is not done by the destructor
	delete ptr;
	delete []arrayPtr;
	return 0;
}


student header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#pragma once
#include <string>
using namespace std;

class Student
{
private:
	string name;
	string tutor;
	string DOB;
public:
	Student(string N, string T, string D);
	Student();
	virtual ~Student(void);
	void getDetails();
	
};



Any guidance or advice would be very appreciated, been reading for hours and my eyes have gone square. Please note the set needs to be an abstract data type this is what seems to be confusing me!
Last edited on
Hello!

I found many example in google.

http://www.csci.csusb.edu/dick/cs202/stl.html

You can find the Set in that description.
Can anyone explain how I would modify this into a class for a Set?
Can you explain better what you have to do?
I need to develop a template class implementing a set abstract data type so then I can compare this with the STL set container.
Last edited on
Topic archived. No new replies allowed.