IE 201 – Sample Midterm Questions

IE 201 – Sample Midterm Questions
1. Draw the class diagram of a supply chain. Your analysis should at least
include entities Company, Manufacturer, Supplier, Customer, Material,
Production Plant, Truck, Ship. You can also add other entities as you desire.
Make sure that you show at least one aggregation and one inheritance
2. (25) Draw the state of stack and heap after each enumerated line. (Draw
the state after each line as a separate diagram).
class A { int k; public: A(int x): k(x){}};
class B: public A
{A* pA; public: B(int y, A* p): A(y), pA(p) {}};
void main()
A a(4);
A* pA1 = &a;
B* pB = new B(7, pA1);
A* pA2 = pB;
A& x = a;
delete pA2;
3. Write a recursive function which returns the index of a given integer value
in a given integer array.
4. Write necessary additional code (only to the locations indicated as “CODE
REQUIRED”) so that the following main function works as intended (prints
‘Galatasaray Besiktas’ on the console) and without any memory leaks. Do not
use any if statements.
#define nT 2
void main()
a[0] = new GS;
a[1] = new BJK;
for (int i = 0; i < nT; i++)
for (int i = 0; i < nT; i++)
delete a[i];
5. Consider the following main.
void main(){
TOWN w(“q”);
DISTANCE y(new CITY(“x”), &w);
a. [10] Declare necessary classes (classes that are used in the main function or
additional classes as necessary) so that the main function works as intended. Do
not use if. Do not use function overloading. Each class must have only one
b. [5] Draw the class diagram.
c. [10] Draw the state of the memory “after” each numbered line. Indicate
how much memory is leaked.
d. [10] Is it possible to write destructors such that there will be no memory
leaks? If no, why? If yes, how?
5. Identify the problems in the following code segment.
class A
{ public: void f() = 0; };
class B : public A
{ public:
void g(A a) {a.f();}
void f(int) {} };
void main()
{ B b;