{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cpp3_mult_f07 - CGS-2425 C EXAM 3 TEST FORM CODE"A SPECIAL...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CGS-2425 C++ EXAM 3, TEST FORM CODE "A", SPECIAL CODE "73", FALL 2007 This exam is OPEN BOOK, OPEN NOTES, CLOSED NEIGHBOR. Cheaters will receive a ZERO on the exam. Assume iostream and cmath have been included prior to any partial C++ code. The following class implements a data structure called stack that holds integers. Stack is variable in size. It can expand or shrink. You can "push" (insert) numbers in it and you can "pop" numbers out of it. Every time a push is performed, the size of the stack will increase. Every time a pop is performed, the stack size will decrease. The examples below show two stacks. The pointer (ptr) contains the address of the stack. Example 1 Example 2 _____ ptr -> |__4__| |__6__| |__8__| |__2 _| |__1__| top = 5 _____ ptr -> |__4__| |__6__| |__8__| top = 3 The next 4 questions refer to this Stack class. class Stack{ private: int *ptr; int top; public: Stack( ); ~Stack(void); void push(int); int pop(void); bool isEmpty(void); }; Stack::Stack(){ top = 0; } Stack::~Stack() {if (top>0) delete []ptr;}
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
bool Stack::isEmpty(void) { if (top == 0) return true; else return false; } int Stack::pop(void) { if (isEmpty()) { cout << "Stack is empty, nothing to pop out!";
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern