Docsity

ECE 190 Exam 3: Problem Set, Exams of Introduction to Aerospace Engineering

Toggle sidebar
bg1
ECE 190 Exam 3
Tuesday, April 12th, 2011
Problem 1 (5 points): Warmup
Problem 2 (20 points): Problem Solving
Problem 3 (15 points): File I/O
Problem 4 (10 points): Debugging
Problem 5 (15 points): Function Activation Records
•Be sure your exam booklet has 11 pages.
•This is a closed book exam.
•You are allowed three handwritten 8.5 x 11” sheets of notes.
•Absolutely no interaction between students is allowed.
•Be sure to clearly indicate any assumptions that you make.
•Don’t panic, and good luck!
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download ECE 190 Exam 3: Problem Set and more Exams Introduction to Aerospace Engineering in PDF only on Docsity!

ECE 190 Exam 3

Tuesday, April 12th, 2011

Problem 1 (5 points): Warmup

Problem 2 (20 points): Problem Solving

Problem 3 (15 points): File I/O

Problem 4 (10 points): Debugging

Problem 5 (15 points): Function Activation Records

  • Be sure your exam booklet has 11 pages.
  • This is a closed book exam.
  • You are allowed three handwritten 8.5 x 11” sheets of notes.
  • Absolutely no interaction between students is allowed.
  • Be sure to clearly indicate any assumptions that you make.
  • Don’t panic, and good luck!

Warmup (5 points)

In this assignment, you are asked to implement a function to normalize an n-dimensional vector.

The function accepts one input vector, vector, one output vector, result, and the number of dimensions, n:

v o i d n o r m a l i z e ( f l o a t v e c t o r [ ] , f l o a t r e s u l t [ ] , i n t n ) ;

Recall from MP4 that a normalized vector has a length of one. Thus, to normalize a vector, one must divide each component of the vector by the length of the original vector.

To determine the length of the vector you may use the following formula:

length =

vector[0]^2 + vector[1]^2 + ... + vector[n − 1]^2

Getting Started

  • Invoke the ’ece190’ script
  • Execute ’cd mp’
  • Execute ’ls’ to verify that mp.c and Makefile are present
  • To compile the code, simply type ’make’.
  • To run the code, simply type ’make test’ and input the necessary information.

Specifics

  • To receive any credit for this problem, the code must compile.
  • sqrt() is the only function from math library that you are allowed to use.

f l o a t s t a r t s [ 4 ] = { 3. 0 , 5. 3 , 2. 7 , 5. 4 } ; f l o a t ends [ 4 ] = { 4. 0 , 6. 1 , 5. 4 , 5. 5 } ; i n t n I n s = i n t e r s e c t s e g m e n t s ( 4 , s t a r t s , ends ) ;

After this code is executed, nIns should be set to 3 indicating that 3 pairs of line segments intersect. (For this example, intersecting pairs of segments are 1 and 3, 2 and 3, and 2 and 4).

Getting Started

  • Invoke the ’ece190’ script
  • Execute ’cd problem’
  • Execute ’ls’ to verify that problem.c and Makefile are present
  • To compile the code, simply type ’make’.
  • To run the code, simply type ’make test’ and input the necessary information.

Specifics

  • To receive any credit for this problem, the code must compile.
  • To receive credit for check() function, the function must be used in intersect segments() function.

File I/O (15 points)

In this problem, you are asked to implement a function to save data about an array of polygons into a file. Each polygon is comprised of 4 vertices whose coordinates are stored in two 2D arrays.

Output file format

The file produced by this function should consist of the following fields:

  • A integer number stored as an ASCII string representing the number of polygons in the file (call this number n), followed by a newline.
  • For each of the n polygons, an ASCII string consisting of 8 real numbers separated by white spaces and followed by newline. The numbers will be the x and y coordinates of each vertex of the polygon, listed in the following order: x 0 y 0 x 1 y 1 x 2 y 2 x 3 y 3. The numbers are to be stored with two digits after the decimal point.

An example file is provided below:

3 1 2. 3 0 3 2. 1 0 4. 0 0 5. 0 0 1. 0 0 7. 4 0 6. 0 0 4. 5 6 1 0. 0 0 1. 0 0 1 1. 0 0 0. 5 0 1 2. 0 0 0. 0 0 2. 1 2 3. 1 4 3 1 2. 5 0 1 7. 0 0 5. 5 5 5. 0 1 4. 4 4 4. 0 0 1 2. 1 2 0. 1 1

Implementation Requirements

You are asked to implement the following function that creates a file on disk and stores data in the described format:

i n t s a v e p o l y g o n s ( c o n s t char ∗ f i l e n a m e , i n t num polygons , f l o a t x [ ] [ 4 ] , f l o a t y [ ] [ 4 ] ) ;

The function should accept 4 arguments: the name of the file to be saved to, file name, number of the polygons to be saved, num polygons, a 2D array of all the x coordinates of

Debugging (10 points)

In this problem, you are asked to find and fix bugs in the code that implements the bubble sort algorithm. When the code is executed, the elements in the array should be arranged such that they are in the increasing order. But because of the bugs, the code does not behave as expected.

Bubble Sort Algorithm

Bubble sort works by repeatedly marching through the array to be sorted, comparing each pair of adjacent elements of the array, and swapping them if they are in the wrong order. This process is repeated until no swaps are needed, which indicates that the array is already sorted in the desirable order.

The logic used by the insertion sort algorithm can be demonstrated using the following example:

array[4] = { 1, 4, 3, 2 } starting array

Iteration 1

{ 1, 4, 3, 2 } array[1] is greater than array[0], leave them in place

{ 1, 4, 3, 2 } becomes { 1, 3, 4, 2 } array[2] is less than array[1], swap them

{ 1, 3, 4, 2 } becomes { 1, 3, 2, 4 } array[3] is less than array[2], swap them

Iteration 2

{ 1, 3, 2, 4 } array[1] is greater than array[0], leave them in place

{ 1, 3, 2, 4 } becomes { 1, 2, 3, 4 } array[2] is less than array[1], swap them

{ 1, 2, 3, 4 } array[3] is greater than array[2], leave them in place

At this point, the array is already sorted, but the algorithm does not know this. One more pass through the array is needed to see that no swaps are occurring, which indicates that the array is already sorted in the desired order.

Getting Started

  • Invoke the ’ece190’ script
  • Execute ’cd debug’
  • Execute ’ls’ to verify that debug.c and Makefile are present
  • To compile the code, simply type ’make’.
  • To run the code, simply type ’make test’.

Specifics

  • To receive any credit for this problem, the code must compile.
  • There are fewer than 4 bugs in this code. To receive a full credit, you need to fix all of them.
  • There are no bugs in main() function. All bugs are in debug.c.
  • All bugs can be fixed with only minor modifications of the code.
  • Extensive code modifications are not allowed and will be penalized.
  • Do NOT change the given algorithm.
  • Each section you are asked to implement should consist of no more than 4-6 lines (if it is longer than that you are probably doing something wrong).

Testing

To test the code at the command line, follow this procedure:

  • Execute ’make’
  • Execute ’make test’
  • The output from the command prints out the resulting values from several runs of your code
  • If your program gets stuck (common if the run time stack is not implemented correctly), type ’Ctrl+C’ to stop the command.

To test the code in the LC-3 simulator, follow this procedure:

  • Execute ’make’
  • Open the lc3sim-tk
  • Load (in this order) fibonacci.obj and main-fibonacci.obj
  • Edit the memory location marked INPUT
  • Set breakpoints as necessary and debug your code!