New version page

Problem 1

This preview shows page 1 out of 4 pages.

View Full Document
View Full Document

End of preview. Want to read all 4 pages?

Upload your study docs or become a GradeBuddy member to access this document.

View Full Document
Unformatted text preview:

EE221 Exam No. 2 – Spring 2010 1 of 4 Total errors this page: ____ Name: __________________ PLEASE PRINT CLEARLY EE 221 Exam No. 2 (100pts. - 25% of the final grade) General Remarks Back side of this test will not be graded. Attach more pages if necessary. Midterm progress grade will be calculated based on the first two exams and homework so far. Three pages (one piece of paper each) of the cheat sheet are allowed. DL: __ ERR: __ PTS: __ MPTS: __ MGR: __ DL – exam difficulty level (adjustment), ERR – exam errors, PTS – exam points, MPTS – total progress points, MGR – total progress grade. Problem 1 (25pts.) Consider the recent homework assignments: debugging BadVector, rewriting SSID_Counter and array of it, completing linked list library (let’s call the classes there link, iter, and list), learning about function templates, and utilizing <vector> library in 2D array based temperature distribution simulation. 1. Circle the data containers that utilized template technology: H5-BadVector H5-Array_of_SSID_Counter H6-Link,Iter,List H8-2D_arrays 2. Circle classes that did not have destructors that de-allocate memory: H6-Link H6-ListIter H6-List H8-2D_arrays 3. Circle classes that have need for an assignment operator (implemented deep copy or blocked assignment): H5-BadVector H5-SSID_Counter H5-Array_of_SSID_Counter H6-Link H6-Iter H6-List 4. Circle classes that have a continuous data container inside such as an array: H5-BadVector H5-SSID_Counter H5-Array_of_SSID_Counter H6-Link H6-Iter H6-List 5. Circle the assignments that had multi-file projects: H5-BadVector H5-Array_of_SSID_Counter H6-Link,Iter,List H7-<T> H8-2D_arraysEE221 Exam No. 2 – Spring 2010 2 of 4 Total errors this page: ____ Problem 2A (20pts.) Implement a function that accepts a two dimensional matrix of double variable based on vector<T>, and coordinates of one of its element (R, C). The function should return the sum b1+b2+b3+b4 of the four elements from the same row, two to the “left” and two to the “right” of the (R, C) element as illustrated in the figures below. In case an addend is located outside of the matrix, “roll over” neighbor elements should be used as shown in the example figures below that illustrates two of such cases. double function(const ____________________ & V, size_t R, size_t C) { double sum=0; return( sum ); } Problem 2B (5pts.) Consider a three dimensional vectors defined as vector<vector<vector<double> > > A, B; You can access elements of that 3D vector similarly like 2D and 1D, i.e. C[i][j][k]=x; You can “look up” the sizes in each dimension of that 3D vector similarly like 2D and 1D. Assume that you are working in the i-th row and j-th column: what is the third size/range of the k variable? Complete the third for loop in the code fragment below: diff=0.0; for (size_t i=0; i<…; ++i) for (size_t j=0; j<…; ++j) for (size_t k=0; k<____________________; ++k) diff=diff+sqr(A[i][j][k]-B[i][j][k]);EE221 Exam No. 2 – Spring 2010 3 of 4 Total errors this page: ____ Problem 3 (20pts.) Analyze the definition of the following class that encloses two arrays of fixed size, one “dynamic” and one “static”. Write an assignment operator implemented as described in comments. Place the method declaration in the header file KLASS.H, and implement it in the KLASS.CPP file. Other methods and their implementations were skipped here as not relevant to the question. // assume insde KLASS.H file class KLASS { private: size_t mySizeP, myCapaP, mySizeS; // standard naming convention used static const size_t myCapaS=10; int * myArrP; int myArrS[myCapaS]; public: KLASS() : myCapaP(2), mySizeP(0), mySizeS(0) { myArrP=new int[myCapaP]; } ~ KLASS () { delete [] myArrP; } // … more functionality skipped here // TO DO: provide the declaration of a copy constructor //– 5pts. }; // assume inside KLASS.CPP file #include “klass.h” // TO DO: provide the implementation of a functional copy constructor // – 15 pts. Problem 3B Quick Questions (5pts.) In this class above if the copy constructor is correctly declared but never implemented passing variable by value to a function triggers the following action: shallow copy / deep copy / program crashes / program does not compile In the corrected BadVector class from recent homework using its assignment operator resulted in: shallow copy / deep copy / program crashes / program does not compileEE221 Exam No. 2 – Spring 2010 4 of 4 Total errors this page: ____ Problem 4 (25pts.) – Understanding of linked structures, and 90-point list homework Implement the function begin() in class listList that returns a listIter object which is an iterator that points to the first element of that list. Implement the postfix operator-- (int) for the class listIter that operates on the linked list made of listLink objects. The operator-- should have this functionality: it should advance backward its internal pointer to point to the previous list element except when the iterator points to the end of the list (null pointer value) it should ignore the request. //*** FILE list.h *** class listLink { private: double value; listLink * bLink; // pointer to the previous (back) link in the list or 0 listLink * aLink; // pointer to the next (ahead) link in the list or 0 listLink (double & v) : value(v), bLink(0), aLink(0) { } friend class list; friend class listIter; }; class listIter { protected: listLink * cLink; // pointer to the “current” link in the list public: listIter () : cLink(0) { } listIter (link * cl) : cLink(cl) { } listIter operator-- (int); // implement in .cpp file below as instructed (15p.) friend class list; … }; class listList { private: listLink * fLink; // pointer to the first link in the list or 0 listLink * lLink; // pointer to the last link in the list or 0 listLink() : fLink(0), lLink(0) { } public: listLink begin(); // implement in .cpp file below as instructed (10p.) … }; //*** FILE list.cpp *** #include


Loading Unlocking...
Login

Join to view Problem 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Problem 1 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?