Presentation on theme: "Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2015."— Presentation transcript:
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2015
Programming Exercises 1.Your time machine is capable of going forward in time up to 24 hours. The machine is configured to jump ahead in minutes. To enter the proper number of minutes into your machine, you would like a program that can take a start time and an end time and calculate the difference in minutes between them, The end time will always be within 24 hours of the start time. Use military notation for both the start and end time (e.g., 0000 for midnight and 2359 for one minute before midnight). [… to be continued on the next slide…]
[… continued from the previous slide …] Write a function that takes as input a start time and an end time represented as an int, using military notation. The function should return the difference in minutes as an integer. Write a C++ program that calls your function with times entered by the user. (Hint : Be careful of time intervals that start before midnight and end the following day.)
2.The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are clustered close to the average. If the standard deviation is large, the numbers are scattered far from the average. The standard deviation, S, of a list of N numbers x i is defined as follows, where x(bar) is the average of the N numbers x 1, x 2, …. [… to be continued on the next slide …]
[… continued from the previous slide …] Define a function that takes a partially filled array of numbers as its argument and returns the standard deviation of the numbers in the array. Since a partially filled array requires two formal parameters: an array parameter and a formal parameter of type int that gives the number of array positions used. The numbers in the array will be of type double. Embed your function in a suitable C++ test program.
3.Use a one-dimensional array to solve the following problem. Write a function to check if a given array of integers contains a duplicate with other numbers in the array. Then, the function should store only the unique values into another array as an array parameter. Also, the number of unique values has to be returned via a call-by- reference parameter. (a) Write a C++ program that allows the user to test the function, and display the output of the array after duplicate elimination. (b) Suppose the integers represent scores between 0 and 100, inclusive. Please design a more efficient function to do the duplicate elimination, and test the function in your program.
Homework Submission Due: 2 weeks (Apr. 17, 2015) Submission instructions: –http://mslin.ee.ntut.edu.tw/http://mslin.ee.ntut.edu.tw/ – File names : Please name your file according to our homework. For example, _HW1.zip or _quiz2.rar