I have a dynamic stack and I want to pop 5 student records and display them

I have a dynamic stack and I want to pop 5 student records and display them but I've come to a dead end... could anyone help me?

Here's my code:

#include <iostream>
#include <iomanip>
#include <string>
#ifndef DYNSTACK_H
#define DYNSTACK_H

using namespace std;

class DynStudentRecords
{
private:

struct StackNode
{
int id,
test1,
test2,
test3,
test4,
test5;
double avg;
string name;
string addy;

struct StackNode *next;
};
StackNode *top;

public:

DynStudentRecords()
{ top=NULL;}

~DynStudentRecords();

void push(int num, string val, string val2, int score1, int score2, int score3,
int score4, int score5);
void pop();
void display();
void show();
bool isEmpty();
};

DynStudentRecords::~DynStudentRecords()
{
StackNode *nodePtr, *nextNode;

nodePtr = top;

while (nodePtr != NULL)
{
nextNode = nodePtr->next;
delete nodePtr;
nodePtr = nextNode;
}
}

void DynStudentRecords::push(int num, string val, string val2, int score1, int score2, int score3,
int score4, int score5)
{
StackNode *newNode;

double num2;
double sum = 0;

sum = score1 + score2 + score3 + score4 + score5;

num2 = sum/5;

newNode = new StackNode;
newNode->id = num;
newNode->name = val;
newNode->addy = val2;
newNode->avg = num2;
newNode->test1 = score1;
newNode->test2 = score2;
newNode->test3 = score3;
newNode->test4 = score4;
newNode->test5 = score5;

if(isEmpty())
{
top = newNode;
newNode->next = NULL;
}
else
{
newNode->next = top;
top = newNode;
}
}

void DynStudentRecords::pop()
{
struct StackNode *temp;
if (top == NULL)
{
cout << "\nThe Stack is completely empty!!!"
<< endl << endl;
return;
}
temp = top;
top = top->next;
delete temp;
}

void DynStudentRecords::display()
{
struct StackNode *ptr = top;
cout << "Id #" << setw(10) << "Name" << setw(20)
<< "Address" << setw(19) << "Average" << setw(20)
<< "Test Scores" << endl;
while(ptr != NULL)
{
cout << "**************************************"
<< "*************************************" << endl
<< ptr->id << setw(15)
<< ptr->name << setw(21)
<< ptr->addy << setw(12)
<< ptr->avg << setw(11)
<< ptr->test1 << ","
<< ptr->test2 << ","
<< ptr->test3 << ","
<< ptr->test4 << ","
<< ptr->test5 << endl;

ptr = ptr->next;
}
}


bool DynStudentRecords::isEmpty()
{
bool status;
if(!top)
status = true;
else
status = false;
return status;
}
#endif



#include <iostream>
#include <string>
#include <iomanip>
#include "DynStack.h"

using namespace std;

int main()

{
DynStudentRecords stud;
cout << "Pushing student records into stack: " << endl << endl;

stud.push(251, "Percy Jackson", "1 Meadow Blvd", 46,55,76,88,99);
stud.push(255, "Mike Shell", "1435 Oriole Ave", 77,77,55,77,99);
stud.push(267, "Ed Kunz", "1423 Cardinal Ave", 65,87,85,95,100);
stud.push(311, "Hardy Menz", "6 Hillary St", 77,78,77,98,85);
stud.push(333, "Betty Boop", "5 Boop Terr", 65,85,99,79,91);
stud.push(345, "Happy Gilmore", "16 Happy St", 95,97,91,85,93);
stud.push(378, "Ray Shay", "346 Sunflower Dr", 90,80,70,85,99);
stud.push(411, "Bill Ding", "556 Moore Ave", 100,100,93,99,91);
stud.push(434, "Sue Tuch", "25 Mackenzie Dr", 85,46,87,88,90);
stud.push(544, "Ida B Happy", "333 Bellvue Ave", 90,85,93,94,75);
stud.push(555, "Dan Sharp", "23 Mockingbird Ln", 55,65,85,88,87);
stud.push(612, "Manny Flow", "44 Jackson St.", 85,73,64,89,90);
stud.push(619, "Carl Lewis", "91 Ent Cir", 90,76,58,84,85);
stud.push(675, "Stu May", "88 Hunt Ave", 85,55,44,76,99);
stud.push(723, "Pat Flat", "95 Emerson Square", 33,76,85,76,76);
stud.push(746, "Bart Simpson", "5502 Homer Ave.", 78,85,55,69,99);
stud.push(798, "Walt Disney", "1403 Disney Ln", 85,64,46,87,89);
stud.push(815, "Rhett Ray", "1092 Rant Blvd.", 90,76,85,49,99);
stud.push(819, "Shay Toe", "331 Bay St", 99,89,79,76,99);
stud.push(877, "Harry Toe", "45 104th Street", 90,80,86,88,99);
stud.display();

cout << endl << endl << "Popping and displaying 5 student records: \n" << endl;

stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();

//stud.display();

cout << endl << "Displaying the remaining records: " << endl << endl;

stud.display();

cout << endl << endl << "Popping all values +1 to show stack is empty"
<< endl << endl;
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
stud.pop();
system("PAUSE");
return 0;
}




Any help would be appreciated!
You might find things work out better with a slightly different interface.

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
struct Student
{
    int id ;
    int test[5] ;
    double average ;
    std::string name ;
    std::string address ;
};

class StudentStack
{
    struct StudentNode
    {
        Student student ;
        StudentNode* next ;
    };

    StudentNode* top ;

public:

    StudentStack() ;
    ~StudentStack() ;

    void push(const Student & s) ;
    void pop() ;
    Student & getTop() const ;

    bool isEmpty() const ;
};
Topic archived. No new replies allowed.