10 Points Front and Back

10 Points Front and Back

<p>Sample Quiz 2 CS / SE 2630 10 points front and back</p><p>// This is file: q2.h #include <iostream> using namespace std; class TA { public: int a1; TA() { a1 = 3; a2 = 5; a3 = 7; } virtual void DoIt1() {cout << "TA's DoIt1" << endl;} void DoIt2() {cout << "TA's DoIt2" << endl;} protected: int a2; private: int a3; }; class TB : public TA { public: void print() { cout << "a1 is " << a1 << endl; // # 1 cout << "a3 is " << a3 << endl; // # 2 cout << "a2 is " << a2 << endl; // # 3</p><p>} virtual void DoIt1() {cout << "TB's DoIt1" << endl;} virtual void DoIt2() {cout << "TB's DoIt2" << endl;}</p><p>TB():TA() { a1 = 6; // # 4 a2 = 8; // # 5 a3 = 10; // # 6 } }; (1) 1. In the above file: q2.h, give the number of 2 of the 6 numbered statements that will not compile:</p><p>______</p><p>(3) 2. Give the output of the following main program that uses the above h file, assuming that the 2 error statements are commented out. In addition, indicate whether statement 7 or 8 is invalid – assume the invalid one (statement 7 or 8) is commented out as well. #include "q2.h" int main() { TA a, *ap; TB b, *bp = &b; a = b; // # 8 b = a; // # 7 ap = new TB(); ap->DoIt1(); ap->DoIt2(); bp->print(); return 0; } (5) 3. Write the pop and push routines to complete the following template for a stack.</p><p>#ifndef __TSTACK_H #define __TSTACK_H template <class TStackInfo, int MAX> class TStack { private: TStackInfo elements[MAX]; int top; public: TStack() : top(0) {} TStackInfo Pop(); void Push ( const TStackInfo & element ); bool IsEmpty() const { return top == 0; } bool IsFull() const { return top == MAX; } };</p><p>// write Pop method here</p><p>// write Push method here</p><p>#endif</p><p>(1) 4. Declare an integer stack of 50 elements called intStack and a float stack of 100 elements called floatStack.</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us