Ask Computer Engineering Expert

Lab Assignment

For this lab you may work with a partner, or you may choose to work alone. Your partner should be in the same lab as you.. If you choose to work with a partner, you are still responsible for the lab in its entirety, even if you partner is abducted by aliens and mind melded with a two-toed sloth. One partner should turn in the lab via canvas, with both names on it, and the other should simply write on Canvas that they submitted with their partner.

Your file should start with comments including your name(s), etc., followed by your included files, and then your function declarations in the order in which the functions are written in the lab.

Your main should follow, calling each of the functions and, if needed or helpful, initializing variables before function calls and printing out values and arrays.

Following the main should be each of your functions in the order in which they are specified below.

Make sure your code is formatted and commented. The comments should include 3 test cases specifying, given these input parameters, you expect this output. For each function, you should also have main call the function with your 3 test cases.

In the comments at the top, write the name, email address, and office hours of your TA)

Arrays

About parameters: Unless I specify, you may choose whether your parameter is passed by value, pointer or reference. If a parameter doesn't change and shouldn't change within a function, you should pass by value.

1. Write a function that takes an array of integers as an input parameter (the address of the first value of the array). It returns nothing. It prints out the array as a single line, with commas between each number, and when the array is finished being printed, it prints an endl; so that we flush the buffer and move to a new line.

Note: you'll be using this function after running other functions to check out your results.

1. Write a function that takes as input parameters (using call by pointer) 3 integers. It generates a random number between 25 and 50 (not including 50). It then creates an array on the memory heap of that length. It generates a random high number (mine was between 5 and 10) and a random low number (between -5 and -10) and fills in the array iteratively with random numbers between the high and the low numbers*, and it returns that array. The input parameters should be modified so that it holds the length of the array, the high value, and the low value. In main, call the function 1 to print out the array.

*not including the high - in general when we specify a range, we include the first value but not the last. If I forget to say that in the future, you can assume that's what I intended.

2. Write a function that is almost exactly the same as the function above, only it takes an input parameter an integer (and you can pass in a number between 25 and 50 - your choice). Inside the function create an array on the stack instead of the heap. Fill it with random numbers as above. Return the address of the first value of the array, and then in the main use function 1 to print it out. This should NOT work. In comments explain why.

3. Write a function that takes as an input parameter an array of integers (and the size of the array). The function should print out the address of every value in the array.

4. Write a function that takes as an input parameter an array of doubles. The function should print out the address of every value in the array. See how this works?

For this next part, you will be writing a low pass filter using a very basic hanning window. The idea behind a low pass filter is to get rid of high frequencies, or, in essence, smoothing out the massive outliers in an array. The way to do this is to take a window size, usually an odd number in length, in which you take the average of the values before and after a value in an array and replace that value with the average. So, for instance, if you had an array as follows:

3,8,2,5,1,4,6,0,2

And you had a window size of 3, you would go through the array in window sizes of 3 and replace each center value with the average. For those values at the beginning and the end, in which you can't have a window on both sides, you'd replace the values with a 0. Otherwise each value gets replaced with its window average.

The resulting array would be:

0 4 5 2 3 3 3 2 0

Which is a much smoother array with fewer outliers.

Now, an even better way of smoothing out the outliers is to weight the window. So, in the process of averaging, the values farthest from the center value in the window are weighted the lowest, whereas the values closest to the center of the window are weighted the highest. This is known as a Hanning window.

For instance, if you have a window size of 5, you might weight the values by multiplying the values at location 1 and 5 with 1, the values at location 2 and 4 with 2 and the values at location 3 (the center) with 3, and then dividing the sum by 9 to get the weighted average. So in this case, given the following array and a window size of 5,

3,8,2,5,1,4,6,0,2

Using a hanning window for a filter, you'd get:

0, 0, 4, 3, 3, 3, 3, 0, 0,

(Note that this is even smoother than the really simple filter we used above).

So you can see where this is going:

2. Write a function for the hanning window. For this function, you should take as input parameters a part of the array (remember - whenever you pass in an array, no matter what you pass in, it is always interpreted as the address of the first value of the array. So if I passed in &arr[3], when that address enters the function, it will assume that the 4th address is the first address in the array. So DO NOT make a copy of each window and send that into the function -that is just wasteful and makes no sense). Assume the window size is an odd number in size, Weight the values appropriately. Return the weighted and averaged value.

3. Write a function for filtering the array. This function should return a new array. You can't write over the old array (why not?). You will have to create a new array on the heap, and return that new array. This function should take as input parameters the original array and the size of the original array, and should create a new array that has been filtered using the hanning window function.

Print out both arrays to see and check the difference.

4. Write a function that takes as input parameters an array, the length of the array, the highest value in the array, and the lowest value in the array. The function should print out a graph of the array by printing out a * for each value in the appropriate place (below is an example of my printout, which is probably easier than explaining it:

Random Array generated:

6, -2, -4, 5, -3, -4, -3, -1, 5, 2, -2, 0, -7, 2, -3, -4, -3, -1, -5, -3, 1, 7, 3, -7, -7, 3, -8, 1, -5, -4, -2, -5, -8, 0, -4,

Graph of the above array (printed using the function in 6):

Filtered Array (using the hanning window):

0, 0, 0, 0, -1, -2, -1, 0, 1, 1, 0, -1, -2, -2, -2, -2, -3, -2, -2, -1, 1, 2, 0, -2, -3, -3, -3, -2, -3, -3, -4, -4, -4, 0, 0,

Graph of the filtered array (printed using function 6):

5. Write a function that takes as input parameters two integer addresses (both call by pointer). It returns the address of a 2-dimensional array.

In the function, generate a random number between 5 and 10. That will be the size of the array of addresses (call it x). Then generate a second random number between 4 and 8. That will be the size of each array of integers (call it y). Adjust the input parameters to hold x and y.

Create the 2-dimensional array (of x, y in size), making sure the 2-d array is on the heap.

Fill this array with 0's. Then generate 5 random number pairs (between 0 and x, and between 0 and y) and place a 1 in each of those random number locations.

Make sure that there isn't already a 1 in that location (and if there is generate a new x and y random number set).

Return the 2 d array.

In the main, use a for loop (looping x times) to call the print function (function 1) to print out the matrix.

Attachment:- Lab-Arrays.rar

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92713006

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As