] > final exam

exit final exam

NAME¯

1–4 CHARACTERS CODE (if you want your final grade posted)¯

 
CSE 230: Final Exam
 
Tuesday, June 3, 3:30—5:28
Open Notes, Open Books
The exam consists of five¯ problems
Answers not appearing in designated spaces WILL NOT be graded

Problem #1 (10 points)
  1. Consider the following incomplete program.
    int main() 
    { 
       cls obj1( 111 ), obj2( 222 ); 
       cout << ”value = ” 
            << obj1.get() << endl; 
       cout << ”value = ” 
            << obj2.get() << endl; 
     
      return 0; 
    }

    Provide the missing code so that the program will produce the following output.

    value = 111  
    value = 222

  2. Consider the following incomplete program.
    int main() 
    { 
      cls a(0), b(1), aa(2) , bb(3), c(3); 
      return 0; 
    }

    Provide the missing code so that the program will produce the following output.

    3  
    3  
    2  
    1  
    0

Problem #2 (10 points)
  1. Show the output of the following program.
    #include <iostream> 
    using namespace std; 
    class cls { 
         static int a, b; 
       public
         cls()            {   a++;  } 
         cls(int x)       {   b++;  } 
         static int get() { return 10  a + b;  } 
    }
    int main() { 
      cls a, b(1), aa(2) , bb(3), c(3); 
      cout << cls::get() << endl; 
      return 0; 
    } 
    int cls::a = 0; 
    int cls::b = 0;
  2. Show the output of the following program.
    #include <iostream> 
    using namespace std; 
    class animal { 
      public
        void talks(); 
        void listens(); 
    }
    class cow : public animal{ 
      public
        void talks(); 
    }
    class cat : public animal{ 
      public
        void listens(); 
    }
    int main (){ 
       cat ct;   ct.listens();  ct.talks(); 
       cow cw;   cw.listens();  cw.talks(); 
       return 0; 
    } 
    void animal::listens(){ cout << ”(: ”;         } 
    void animal::talks() {  cout << ” bye!” << endl;   } 
    void cow::talks() {     cout << ”mooo” ; 
                            animal::talks();           } 
    void cat::listens() {   cout << ”:) ”; 
                            animal::listens();         }

Problem #3 (10 points)
  1. Consider the following incomplete program.
    int main() 
    { 
       arith<int> a(10), b(10); 
       arith<double> c(11.1), d(22.2); 
       cout << a.abs() << endl; 
       cout << b.abs() << endl; 
       cout << c.abs() << endl; 
       cout << d.abs() << endl; 
       return 0; 
    }

    Provide the missing code so that the program will produce the following output. The code is not allowed to contain output instructions.

    10  
    10  
    11.1  
    22.2

  2. Consider the following incomplete program.
    int main() 
    { 
       arith<int> a(10), b(10); 
       arith<double> c(11.1), d(22.2); 
       cout << a.type() << endl; 
       cout << b.type() << endl; 
       cout << c.type() << endl; 
       cout << d.type() << endl; 
       return 0; 
    }

    Provide the missing code so that the program will produce the following output. The code is not allowed to contain output instructions.

    int  
    int  
    double  
    double

Problem #4 (10 points)
  1. Show the output of the following program.
    #include <iostream> 
    using namespace std; 
    class A{ 
      public
        void f(){ cout << ”Af” << endl; } 
        virtual void g(){ cout << ”Ag” << endl; } 
    }
    class B : public A{ 
      public
        void  f(){ cout << ”Bf” << endl; } 
        virtual void g(){ cout << ”Bg” << endl; } 
    }
    class C : public B{ public
      void  f(){ cout << ”Cf” << endl; } 
    }
    int main() 
    {     A  a;     C  b; 
          A p;     C q; 
      p = &a;        p>f(); p>g(); 
      p = &b;        p>f(); p>g(); 
      q = &b;        q>f(); p>g(); 
      q = (C ) &a;  q>f(); p>g(); 
    }
  2. Show the output of the following program.
    #include <iostream> 
    using namespace std; 
    namespace days { 
      class cls { 
        public:       void speak(){ cout<<”Su Mo Tu We Th Fr San”; } 
      }
    } 
    namespace months { 
      class cls { 
        public
          void speak(){ cout<<”Ja Fe Ma Ap My Ju Jl Au Se Oc No Den”; } 
      }
    } 
    int main (){ 
      days::cls w; 
      months::cls d; 
      {  using months::cls;    cls d;  d.speak();  } 
      {  using namespace days; cls w;  w.speak();  } 
      w.speak();  d.speak(); 
      return 0; 
    }

Problem #5 (10 points)
  1. Consider the following incomplete program.
    #include <iostream> 
    using namespace std; 
    int main () 
    { 
      char name[11] = {’0’, ’1’ }
     
     
     
     
     
      cout << name << endl; 
      return 0; 
    }

    Provide the missing code so that the program will produce the following output. The code is not allowed to contain output instructions.

    01.......9

  2. Consider the following incomplete program.
    int main() { 
      A a, b; 
      a = new  A [3] ( ”obj x” ); 
      b = new  A [3] ( ”obj y” ); 
      a>copy(b,3); 
      delete [] a; 
      delete [] b; 
      return 0; 
    }

    Provide the missing code so that the program will produce the following output.

    new obj: obj x  
    new obj: obj x  
    new obj: obj x  
    new obj: obj y  
    new obj: obj y  
    new obj: obj y  
    dead obj: obj y  
    dead obj: obj y  
    dead obj: obj y  
    dead obj: obj y  
    dead obj: obj y  
    dead obj: obj y