Question 1

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#define DEF_A 0
#define DEF_B DEF_A+1
#define DEF_C DEF_B+1
int main(int argc, char *argv[]) {
cout << DEF_C;
return 0;
}
  • Question 2

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <string>
    using namespace std;
    class A {
    int x;
    protected:
    int y;
    public:
    int z;
    A() { x=1; y=2; z=3; }
    };
    class B : public A {
    public:
    void set() {
    y = 4; z = 2;
    }
    void Print() {
    cout << y << z;
    }
    };
    int main () {
    B b;
    b.set();
    b.Print();
    return 0;
    }
  • Question 3

    Which code, inserted at line 18, generates the output "AB"
    #include <iostream>
    using namespace std;
    class A
    {
    public:
    void Print(){ cout<< "A";}
    void Print2(){ cout<< "a";}
    };
    class B:public A
    {
    public:
    void Print(){ cout<< "B";}
    void Print2(){ cout<< "b";}
    };
    int main()
    {
    B ob2;
    //insert code here
    ob2.Print();
    }
  • Question 4

    What happens when you attempt to compile and run the following code?
  • Question 5

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <string>
    using namespace std;
    class SampleClass
    {
    string *s;
    public:
    SampleClass() { s = new string("Text");}
    SampleClass(string s) { this?>s = new string(s);}
    ~SampleClass() { delete s;}
    void Print(){ cout<<*s;}
    };
    int main()
    {
    SampleClass *obj;
    obj = new SampleClass("Test");
    obj?>Print();
    }