MidtermB Flashcards

1
Q
  1. Which of the following commands is an example of linking?

(a) g++ -c Student.cc
(b) g++ -o p1 main.o Student.o
(c) g++ -o p1 main.cc Student.cc
(d) g++ main.cc

A

(b) g++ -o p1 main.o Student.o

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

include < iostream >

  1. What would be the output of the following code assuming the user entered a 5?
    ~~~
    # include < string >
    using namespace std ;
    void doubleNum ( int * num ){
    * num *= 2;
    }
    int main (){
    int num ;
    cout «” Enter an integer : “ ;
    cin&raquo_space; num ;
    doubleNum ( num );
    cout &laquo_space;” Your number doubled is : “ &laquo_space;num &laquo_space;endl ;
    }
    ~~~

(a) 2
(b) 5
(c) 10
(d) Error

A

(c) 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Which of these functions could return an int as an output parameter?

(a) int& getValue();
(b) int getValue(int);
(c) void getValue(int&);
(d) int* getValue();

A

(c) void getValue(int&);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Assuming that Book and Movie are both classes, which of these has the proper signature
    for a conversion constructor?

(a) Movie(Book&);
(b) Movie(Book*);
(c) Movie(Book);
(d) None of these.

A

(a) Movie(Book&);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What is the output of the following code?
    ~~~
    # include < string >
    # include < iostream >
    using namespace std ;
    class Egg
    {
    public :
    Egg ( string size = “ mini “ ){ cout < < “ Egg ctor “ ; }
    private :
    string size ;
    };
    class Chicken {
    public :
    Chicken (){ cout < < “ Chicken ctor “ ; }
    private :
    Egg * egg ;
    };
    int main (){
    Chicken chicky ;
    }
    ~~~

(a) Egg ctor Chicken ctor
(b) Chicken ctor Egg ctor
(c) Chicken ctor
(d) None of these.

A

(c) Chicken ctor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Which of these code snippets would produce an error?

(a) int x = 0, y = 1; int& z = x;
(b) int x, y; x = 1, y = 1; int& z = 1;
(c) int x, y; x = 1; y = 1; int& z = x;
(d) All of these.
(e) None of these.

A

(b) int x, y; x = 1, y = 1; int& z = 1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Which of these variables could be used to refer to a dynamically allocated array of
    Student pointers?

(a) Student** studentArray;
(b) Student* studentArray;
(c) Student* studentArray[10];
(d) Student studentArray[10];

A

(a) Student** studentArray;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Which of these variables could be used to refer to a statically allocated array of Student
    pointers?

(a) Student** studentArray;
(b) Student* studentArray;
(c) Student& studentArray;
(d) Student studentArray;
(e) None of these.

A

(a) Student** studentArray;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

include < iostream >

  1. How many int variables are allocated on the function call stack in this program?
using namespace std ;
int main (){
int x = 0;
int * y = & x ;
int & z = x ;
z = 10;
int w = * y ;
cout << w <<" , " << x <<" , " << y <<" , " << z ;
}

(a) 1
(b) 2
(c) 3
(d) 4
(e) None of these.

A

(b) 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Which of the following is NOT an Object-Oriented design principle?

(a) Data abstraction
(b) Encapsulation
(c) Principle of least privilege
(d) Model-View-Controller

A

(d) Model-View-Controller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Assuming these are functions in an Employee class with a pay member variable, which
    of these functions should be made const? Select all that apply.

(a) float getPay(){
return pay;
}
(b) void setPay(float pay){
this->pay = pay;
}
(c) void printPay() {
cout &laquo_space;pay;
}
(d) Employee (float pay){
this->pay = pay;
}

A

(a) float getPay(){
return pay;
}
(c) void printPay() {
cout &laquo_space;pay;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. When running the following piece of code, what part of memory would the Weapon
    object be stored?
    ~~~
    # include < iostream >
    # include < string >
    using namespace std ;
    class Weapon {
    public :
    setDamage ( int damage ){ this - > damage = damage ;}
    private :
    int damage ;
    };
    class Character {
    public :
    Character ( const string & n , int h , int damage ){
    name = n ;
    health = h ;
    weapon . setDamage ( damage );
    }
    private :
    string name ;
    int health ;
    Weapon weapon ;
    };
    int main (){
    Character joe ( “ Joe “ , 20 , 20);
    }
    ~~~

(a) No Weapon object was created.
(b) The heap.
(c) The function call stack.
(d) The heap and the function call stack.

A

(c) The function call stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly