Midterm Flashcards
What is the output?
typedef long sqfeet;
sqfeet area = 3500;
cout<
Answer: 4
What is the output?
int foo[6] = {12, 2, 1, 30, 4, 7}; cout<
Answer: 30
What is the output?
char ch[]=”Dalhousie”;
char * pch_ptr = ch;
cout<
Answer: D
What is the output?
class Box{ Box(){ cout << "Box created!\n"; } ~Box(){ cout << "Box destroyed!\n"; } }; void main( ){ Box* myBoxArray = new Box[2]; }
Answer:
Box created!
Box created!
What is the output?
enum Suit { Diamonds = 5, Hearts, Clubs, Spades = 2 }; cout << Suit::Clubs;
Answer: 7
What is the output?
template T multiply( S i_var1, T i_var2) { return i_var1 * i_var2; }
void main(){ float pi = 3.14; int val = 2.0; cout << multiply(val, pi); }
Answer: 6.28
What is the output?
class People { public: virtual void Out() { cout << "We are People\n"; } };
class GoodPeople : public People { public: void Out() { cout << "We are Good\n"; } }; }
void main(){ People * we = new GoodPeople(); we->Out(); }
Answer:
We are Good
People * we = new GoodPeople();
For the code segment shown above, what is the actual type and the declared type of the variable “we”?
Actual type = pointer to GoodPeople
Declared type = pointer to People
Members of a class are _________ by default, while members of a struct are _________ by default
private
public
In object oriented design, _________ is represented by a has-a relationship, while _________ is represented by “is-a” relationship
aggregation
inheritance/generalization
Study the code below and identify the type of match (exact match, ambiguous match or promotion) that will result from each call to func
void Func(int value) { cout << value; } void Func(float value) { cout << value; }
void main(){ Func('a'); Func(0); Func(3.14159); }
1 promotion
- exact
- ambiguous
Identify the type and value of the variable z
int x = 10;
int * y = &x;
int z = *y;
//Type of variable z = int //Value of variable z = 10
A struct can contain structs as members. (T/F)
True
Static variables are global variables, with memory allocated on the Stack. (T/F)
False
If CAR is a class, CAR * myCar = new CAR creates a CAR object on the Heap (T/F)
True