Debugging - Introduction to Engineering - Previous Exam, Exams of Introduction to Aerospace Engineering

Main points of this past exam are: Debugging, Warmup, Problem Solving, Function Activation Records, Spheres Are Colliding, Function Accepts, Number of Dimensions

Typology: Exams

2012/2013

Uploaded on 04/01/2013

ekan
ekan 🇮🇳

5

(1)

72 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 190 Exam 3
Monday, April 11th, 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 10 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 Debugging - Introduction to Engineering - Previous Exam and more Exams Introduction to Aerospace Engineering in PDF only on Docsity!

ECE 190 Exam 3

Monday, April 11th, 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 10 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 determine if two n-dimensional spheres are colliding.

The function accepts two vectors for the centers of spheres, orig1 and orig2, radii of the spheres, radius1 and radius2, and the number of dimensions, n, and returns 1 if the spheres are collinding or 0 if they are not colliding:

i n t c o l l i d e ( f l o a t o r i g 1 [ ] , f l o a t o r i g 2 [ ] , f l o a t r a d i u s 1 , f l o a t r a d i u s 2 , i n t n ) ;

Two spheres are colliding if the distance between their centers is less than or equal to the sum of the radii of the spheres.

As a reminder, to determine the distance between two points in n-dimensional space you may use the following formula:

distance =

(orig2[0] − orig1[0])^2 + (orig2[1] − orig1[1])^2 + ... + (orig2[n − 1] − orig1[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.

The function should accept two arguments, array to be sorted, array, and its size, n, and should return two results: sorted array in place of the original array and the number of passes it actually took to sort the array, including the last pass needed to see that the array is already sorted.

You are also required to implement a helper function that swaps two integer values:

v o i d swap ( i n t ∗a , i n t ∗b ) ;

You are required to use this function to swap values in bubble sort() function.

Example Run

i n t a r r a y [ 5 ] = { 1 , 2 , 3 , 4 , 5 } ; /∗ u n s o r t e d a r r a y ∗/ i n t nP as ses = b u b b l e s o r t ( array , 5 ) ; /∗ c a l l bubble s o r t ∗/

After this code is executed, array should be sorted in the descending order (5, 4, 3, 2, 1) and nPasses should be set to 5 indicating that it took 5 passes through the array to arrange it in the required order.

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 swap() function, the function must be used in bubble sort() func- tion.

File I/O (15 points)

In this problem, you are asked to implement a function to save the status of a game of Chess into a file.

Output file format

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

  • Name of the white player, stored as an ASCII string, followed by a newline.
  • Name of the black player, stored as an ASCII string, followed by a newline.
  • Current player’s turn, represented by an ASCII character ’W’ or ’B’, followed by a newline.
  • Board data stored as a binary array. This data represents an 8x8 chess board (one byte per board cell, or 64 bytes total). The data should be stored one row per line in the file, meaning that the first 8 bytes are for the first row, followed by new line, the second 8 bytes are for the second row, followed by newline, and so on.

An example file is provided below: Joe Bob W < 8 b y t e s o f b i n a r y data f o r row 1 > < 8 b y t e s o f b i n a r y data f o r row 2 > < 8 b y t e s o f b i n a r y data f o r row 3 > < 8 b y t e s o f b i n a r y data f o r row 4 > < 8 b y t e s o f b i n a r y data f o r row 5 > < 8 b y t e s o f b i n a r y data f o r row 6 > < 8 b y t e s o f b i n a r y data f o r row 7 > < 8 b y t e s o f b i n a r y data f o r row 8 >

Implementation Requirements

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

Debugging (10 points)

In this problem, you are asked to find and fix bugs in the code that implements the insertion 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 actually crashes.

Insertion Sort Algorithm

Recall from lectures that insertion sort algorithm treats the array to be sorted as consisting of two parts: already sorted and yet to be sorted. Every repetition of insertion sort removes the first element from the yet to be sorted part of the array and inserts it into the correct position in the already sorted part of the array. Insertion step requires sequentially comparing the removed element with the elements from the already sorder part of the array until an appropriate place for insertion is found. The algorithm stops when the yet to be sorted part of the array becomes empty.

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

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

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

{ 1, 4, 3, 2 } becomes { 1, 3, 4, 2 } array[2] is less than array[1], insert it between 1 & 4

{ 1, 3, 4, 2 } becomes { 1, 2, 3, 4 } array[3] is less than array[2], insert it between 1 & 3

{ 1, 2, 3, 4 } array is now sorted

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 the insertion sort() function.
  • All bugs can be fixed with only minor modifications of the code.
  • Extencive 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) towers.obj and main-towers.obj
  • Edit the memory location marked INPUT
  • Set breakpoints as necessary and debug your code!