Write a function that takes as an input parameter

Assignment Help Data Structure & Algorithms
Reference no: EM131884659

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

Reference no: EM131884659

Questions Cloud

What is the overhead application rate of company : O.K. Company uses a job order cost accounting system and allocates its overhead on the basis of direct labor costs. O.K. expects to incur $800,000 of overhead.
Create a new monthly budget for quadrupled production : What is the incremental analysis if the Lees choose Option 1 over Option 2?
Calculate the bonds yield to maturity and yield to call : Calculate the bond's yield to maturity, yield to call, and current yield. Assume semiannual payments and Face Value of $1,000.
Why is the method deemed to be the most preferable : There are three methods or approaches firms can use to calculate their Pension Benefit Obligations (Liability). Which of the three methods is most preferable.
Write a function that takes as an input parameter : Write a function that takes as an input parameter an array of integers. The function should print out the address of every value in the array.
Compute the cash inflows and cash outflows : Sales are as follows: $200,000 for December, $300,000 for January, $250,000 for February, $200,000 for March, and $300,000 for April.
Find the adjusted monthly payment including principle : If cindy and rick (continuing first problem) pay for their home over the full 30 years, what total interest will they have paid?
Determine the inventory cost by the average cost methods : The units of Manganese Plus available for sale during the year were as follows: Mar. 1 Inventory 20 units @ $30 $600 June 16 Purchase 30 units.
What is its cost of equity capital : Coca cola has equity of $30 million and debt of $10 million. Its cost of debt is 6% and the tax rate is 35%. Its weighted average cost of capital is 12%.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd