IE 201 – Sample Midterm Questions

Transcription

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
relation.
2. (25) Draw the state of stack and heap after each enumerated line. (Draw
the state after each line as a separate diagram).
[1]
[2]
[3]
[4]
[5]
[6]
[7]
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
// CODE REQUIRED
void main()
{
// CODE REQUIRED
a[0] = new GS;
a[1] = new BJK;
for (int i = 0; i < nT; i++)
a[i].PrintFullName();
for (int i = 0; i < nT; i++)
delete a[i];
}
5. Consider the following main.
void main(){
[1]
TOWN w(“q”);
[2]
DISTANCE y(new CITY(“x”), &w);
[3]
DISTANCE*
p
=
new
DISTANCE(new
CITY(“z”));
[4]
}
TOWN(“c”),
new
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
constructor.
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;
b.g(b);}