MT2 PracticeProblems - Problem 1 Does this code compile If...

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

View Full Document Right Arrow Icon
Problem 1: Does this code compile? If yes, what is the output? If no, make minimal changes (2 lines at most) to make this code compile and then write the output. 1. class A { 2. public: 3. A() 4. { cout << "A1 "; } 5. 6. A(int x) 7. { cout << "A2 "; } 8. 9. A(const A& other) 10. { cout << "A3 "; } 11. 12. ~A(){ cout << "~A ";} 13. 14. A& operator=(const A& rhs){ 15. std::cout << "A4 "; 16. return *this; 17. } 18. 19. }; 20. 21. class B { 22. A m_a; 23. 24. public: 25. B(const A& a) : m_a(a) 26. { cout << "B1 "; } 27. 28. ~B() 29. { cout << "~B "; } 30. 31. }; int main() { B b(A(1)); }
Image of page 1

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

View Full Document Right Arrow Icon
Problem 2: Write a function called reverseString that takes in as its parameter one string and returns a string with the characters in reverse order. Use the STL stack to reverse the string. This isn’t a very efficient way to perform string reversal, but it’s good stack practice.
Image of page 2
Problem 3: Given the following postfix expression: 7 8 * 92 + 2 17 14 - - + Show the contents of the stack after the 17 has been processed by the postfix evaluation algorithm defined below.
Image of page 3

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

View Full Document Right Arrow Icon
Problem 4: Given a circular queue of 4 elements, show the queue’s contents and the Head and Tail pointers after the following operations are complete: push(1); push(1); pop(); push(2); push(3); push(5); pop(); pop(); push(8); push(13);
Image of page 4
Problem 5: Implement a circular queue with the following class definition: class CircQueue { public : // Construct a new circular queue // arrSize is the size of the array that the queue will be stored in CircQueue( int arrSize); // Add num to the end of the queue. Return true if num can be added, // false if there is not enough room bool enqueue( int num); // Return the element at the front of the queue and "delete" it // You may assume that there will always be elements in the queue
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
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