Ensf 480 Midterm 2018 Solutions
Ensf 480 Midterm 2018 Solutions
University of Calgary
Department of Electrical and Computer Engineering
ENSF 480: Principles of Software Design
Midterm Exam Ð Fall 2018 Solution
A. Class A can have access to all data members in class B and class B can have access to all data members
in class C.
B. Class A can have access to all data members in B and class B can have access to all data members in class A
and C.
C. Class B can have access to all data members in A and class C can have access to all data members in B.
D. Class B can have access to all data members in A and class C can have access to all data members in class A
and B.
E. None of the above is correct.
2. Which one of the following group of operators must be overloaded as a member function in a C++ class? In other words
they cannot be defined as a non-member global function.
3. A derived class inherits all the member functions of each of its base classes except:
A. the constructors and copy constructors
B. the destructor
C. the assignment operator.
D. A, B, and C are all correct answers
E. None of the above is a correct answer.
5. Consider the definition of the class String in C++ and assume all member functions are properly defined:
class String {
public:
String(int a = 0);
String(const char* b);
private:
int length;
char* storage;
};
Which of the following statements is a valid statement?
A. String s1(50);
B. String s2 = 100;
C. String s3;
D. String s4 = Ò123Ó;
E. A, B, and C are all valid statements
F. A, B, C, and D, are all valid statements
This problem concerns a template class called List that maintains a list of objects of different types. Partial definition
of class List and class Node in C++ are given.
Part a (6 marks) Ð In the following space write the definition of operator[], for class List. By using this operator you
should be able to retrieve or modify the value of the item in the ith node of the list. For example, if mylist is an instance of
List <int> with four nodes as follows,
you should be able to write the following statement to retrieve the value of the first node:
int y = mylist[0];
Or, to change the value of item in the third node from 200 to 1000, you should be able to write:
mylist[2] = 1000;
Note: If the index number is less than zero or greater than number of nodes in the list, or if the list is empty this function should
give the following message and return zero: ÒSomething went wrong: Out of Bound Error.Ó
int i = 0;
Node <T>* p = headM;
if(p == nullptr) {
cerr << ÒSomething went wrong: Out of Bound Error.Ó;
exit(1);
}
return p -> item;
}
Part b (5 marks) Ð Write the definition of overloaded operator << to print entire values in the list (one value per
line):
Node<T>* p = headM;
while (p)
os << p -> item;
p = p -> next;
}
return os;
}
Note: Some of the data members of classes JobHunter and JobSeeker are shown in this diagram. You need to pay
attention to relationship among the classes and consider more data members if needed.
Write the definition of your classes in the following space:
@Override
public void register(Observer o) {
observers.add(o);
o.update(jobs);
public JobSeeker(Subject s) {
subject = s;
subject.register(this);
}
@Override
public void update(ArrayList<String> jobs) {
this.jobs = jobs;
}
}
Note: to show Captain relation a role specified on the line between player and team is also accepted.
Part b (5 marks) Ð In the following space draw a use-case diagram that shows the actors and use cases needed in a simple
heating and cooling system that:
The owner of the house can set the temperature settings on the Thermostat.
Thermostat manages the heating device (Furnace}
Thermostat manages the cooling device (AC)
Part c (5 marks) Ð In the following space draw a sequence diagram between a bank-customer and the ATM-System
that shows details of a use case called withdraw-money (withdrawing money from a bank-account). You don't
have to show the bank database system in this diagram;