Fall 2006 ECE 575 Midterm Examination: C++, STL, DEVS Modeling, Exams of Electrical and Electronics Engineering

The fall 2006 midterm examination for ece 575, covering topics in c++, standard template library (stl), and devs modeling. The examination includes multiple-choice questions and problems related to class instantiation, virtual functions, destructors, stl iterators, and devs modeling of a traffic light system.

Typology: Exams

Pre 2010

Uploaded on 08/31/2009

koofers-user-fqu
koofers-user-fqu 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Fall 2006 ECE 575 Midterm Examination
Monday, October 16, 2006
Name: _______________________________
1. C++ (10 points)
(a) A class object is said to be concrete if it can be instantiated. Otherwise, the class is abstract. Three
classes A, B, and C are defined as follows. Pick all the concrete classes. (4 pts)
#include <string>
#include <vector>
class A
{
std::string Name;
public:
A(const std::string& name): Name(name) {}
};
class B: public A
{
static double CurrentTime;
protected:
B(const std::string& name): A(name) {}
virtual void print_out() = 0;
};
class C: public B
{
Std::vector<B*> Children;
public:
C(const std::string& name): B(name) {}
};
Check the following statements by F for false and T for true. (each 2 pts)
(b) A virtual function can be static. ( )
(c) A destructor can be virtual. ( )
(d) Call-by-value has an advantage over call-by-reference if the memory size of an argument is huge. ( )
2. Standard Template Library (STL) (10 pts)
(a) For making a loop, we need to use the iterator of a STL container. When should we use constant iterator
such as const_iterator? (5 pts)
(b) We want to model a graph structure G=<V, E> where V is a set of integers, EVV is a set of edges.
Figure 1 shows an instance of the graph. Which STL class among vector, list, set, map, and
multimap is good for representing the edge set EVV? (5 pts)
1
2
3
3
Figure 1. A Graph
1
pf3
pf4

Partial preview of the text

Download Fall 2006 ECE 575 Midterm Examination: C++, STL, DEVS Modeling and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

Fall 2006 ECE 575 Midterm Examination

Monday, October 16, 2006 Name: _______________________________

  1. C++ (10 points) (a) A class object is said to be concrete if it can be instantiated. Otherwise, the class is abstract. Three classes A, B, and C are defined as follows. Pick all the concrete classes. (4 pts) #include #include class A { std::string Name; public: A(const std::string& name): Name(name) {} }; class B: public A { static double CurrentTime; protected: B(const std::string& name): A(name) {} virtual void print_out() = 0; }; class C: public B { Std::vector<B*> Children; public: C(const std::string& name): B(name) {} }; Check the following statements by F for false and T for true. (each 2 pts) (b) A virtual function can be static. ( ) (c) A destructor can be virtual. ( ) (d) Call-by-value has an advantage over call-by-reference if the memory size of an argument is huge. ( )
  2. Standard Template Library (STL) (10 pts) (a) For making a loop, we need to use the iterator of a STL container. When should we use constant iterator such as const_iterator? (5 pts) (b) We want to model a graph structure G=<V, E> where V is a set of integers, EVV is a set of edges. Figure 1 shows an instance of the graph. Which STL class among vector, list, set, map, and multimap is good for representing the edge set EVV? (5 pts)

Figure 1. A Graph

  1. DEVS modeling. Consider the traffic light system of a four-way intersection as shown in Figure 2(a). Since both pairs of (north, south) and (east, west) are identically working, we would consider control of just north lights and east lights. Each way has three lights: R for red,  for left turn, G for green. Our design of the intersection traffic controller (ITC) is shown in Figure (b), which is a coupled DEVS model. R

G

G R

R

G

R G

?r !s ?r !s MC

ITC

M

!g1 !a1 !r !g (^) !a !r ?s ?s M !r2 !a2 !g !r !a !g (b) (c) (a) !s !s !s !s ?r1: ?r2:

MC

toM1: M1:inf toM2: M2:inf ?r:{0,1} ?r:{0,1} Figure 2. Intersection Traffic Lights (a) MC is a controller to circulate activation between two modules: M1 and M2. The state transition of MC is shown in Figure 2(c) in which inf means . Write atomic DEVS 7-tuple of Figure 2(c) as MC=< X, Y, S, ta,ext,,int, > (20 pts)

  1. DEVS Behavior and its Simulation. (40 pts=37 pts + 3 pts bonus) Consider a DEVS network as shown in Figure 3 which is a model for a pin-pong game. Figure 3. DEVS Network Model for Ping-Pong Game (a) When using ODEVS, we can capture this game’s status at time=2 as (A:wait,1.800,inf),(Table:Pong,0.600,1.000),(B:wait,0.600,inf) where each atomic model’s status is displayed in the form of ( name : state , te , ta ( state )). Fill out all the blanks of the following table. (9 pts = 9 * 1pts) A Table B tc (current time)

te (elapsed time)

ts=ta(s) (scheduled time span) inf 1.0 inf tL (last updating schedule time) tN (next schedule time) tr (remaining time to schedule time) (b) Fill out all the blanks of the transition at time = 2.4 , which is printed out by ODEVS. (28 pts = 14 * 2pt) (A:wait,______,inf),(Table:Pong,______,1.0),(B:wait,______,inf) --({______________,______________},2.4)--> (A:_______,______,______),(Table:_______,______,______),(B:_______,______,______)

  • Use convention of! name.y or? name. x for --({______________,______________},2.4)-->. Thank you for doing your best!

send,

!send ?receive

wait, 

!send ?receive

A

send, 0.

wait, 

!send ?receive

B

?receive !send

Match

Table

Idle, 

Ping, 1. Pong, 1. ?ipA !opB !opA ?ipB ?ipA ?ipB !opB !opA