// objectTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Student.h"
#include <stack>
#include <iostream>
usingnamespace 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>
usingnamespace 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!