MidtermA Flashcards

1
Q
  1. Which of the following commands would you use to create an object file Student.o
    for a Student class (assuming there is a Student.h and a Student.cc file)?

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

A

(a) g++ -c Student.cc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What would be the output of the following code assuming the user entered a 5?
    ~~~
    # include < iostream >
    # 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

(b) 5

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) void getValue(int*);
(c) void getValue(int);
(d) int* getValue();

A

(b) void getValue(int*)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Assuming there is a Date class, which of these functions would result in the copy
    constructor of the Date class being called?

(a) bool beforeDate(Date&);
(b) bool beforeDate(Date*);
(c) bool beforeDate(Date);
(d) None of these.

A

(c) bool beforeDate(Date);

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 < iostream >
    using namespace std ;
    class Egg {
    public :
    Egg ( string size = “ mini “ ){ cout &laquo_space;” Egg ctor “ ; }
    private :
    string size ;
    };
    class Chicken {
    public :
    Chicken (){ cout &laquo_space;” 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

(a) Egg ctor Chicken ctor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. If Student* stu is a pointer to a Student object, which of these is the proper way to
    assign this pointer to a double pointer output parameter?

(a) void getStudent(Student** student){
*student = stu;
}
(b) void getStudent(Student** student){
student = &stu;
}
(c) void getStudent(Student** student){
&student = *stu;
}
(d) void getStudent(Student** student){
**student = *stu;
}

A

(a) void getStudent(Student** student){
*student = stu;
}

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 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
8
Q
  1. Which of these variables could be used to refer to a dynamically allocated array of
    Student objects?

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

A

(b) 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 &laquo_space;w «” , “ &laquo_space;x «” , “ &laquo_space;y «” , “ &laquo_space;z ;
    }
    ~~~

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

A

(a) 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 example of an object category?

(a) Entity objects
(b) Control objects
(c) Boundary objects
(d) Dynamically allocated objects

A

(d) Dynamically allocated objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Which of these is NOT shown in a UML diagram? (select all that apply)

(a) Constructors
(b) Collection classes
(c) Member variables
(d) Private functions

A

(a) Constructors
(b) Collection classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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) bool lessThan(float pay) {
return this->pay < pay;
}
(d) Employee (Employee& e){
pay = e.pay;
}

A

(a) float getPay(){
return pay;
}
(c) bool lessThan(float pay) {
return this->pay < pay;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. Which of these are valid ways to initialize the nextId variable in the Employee class
    above (select all that apply)?
    ~~~
    class Employee {
    private :
    static int nextId ;
    }
    ~~~

(a) static int nextId = 100;
(b) static int Employee::nextId = 100;
(c) Employee::Employee(int nextId): nextId(nextId)
(d) int Employee::nextId = 100;

A

(d) int Employee::nextId = 100;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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 :
    Weapon ( int damage ){ this - > damage = damage ;}
    private :
    int damage ;
    };
    class Character {
    public :
    Character ( const string & n , int h , int damage ){
    name = n ;
    health = h ;
    weapon = new Weapon ( 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) Both the heap and the function call stack.

A

(b) The heap.

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