CSSE 120 -- Intro. to Software Development

Homework 25

  1. Take a look at the Python vs C comparison document.  You may find this helpful as you try to do things in C that you already know how to do in Python.  Feel free to suggest things that we might add to this document.
  2. Complete the assigned reading for the next session listed on the schedule page.
  3. (10 pts) Complete the Angel quiz over the reading assignment. You'll find the quiz on the course Angel page, under Lessons → Homework → Homework 25 → Strings and Chars
  4. (35 points total below) Using Eclipse, checkout the HousePrices project. Within that project, open the file main.c, which contains a template for the rest of this assignment. Add your name and the date you start solving the problems to the initial comments and commit your work to your repository.
  5. Background: For this exercise we are interested in using arrays to help us study the prices of 4-bedroom houses in Vigo County. In particular, we would like to know the

    1. average (mean) price,
    2. median price,
    3. 5 highest prices, and
    4. 5 lowest prices
    of 4-bedroom homes in Vigo county. We will guide you in helping us to do this study by giving you a template to follow.

    To see data like we'll give below, point your browser to http://www.trulia.com/home_prices/Indiana/.

    Click on the Vigo County link on the Indiana map, then on the link for "Homes for sale in Vigo County". Make sure the "Homes for sale" checkbox is checked on the page that appears in your browser window.

    You should see a a list of homes for sale that you can sort by address, price, type, beds, baths or broker. Sort by beds. You should see several pages of listings (with up to 15 listings on each page). You don't need to do anything with this data for the homework, but we wanted to show how the data could be acquired.

  6. (5 points) In the main.c file, fill in the code for the function findMean. findMean() takes an array and its size, and  returns the mean of the values in the array.  Test the findMean function by invoking it in the main() function and printing the value it returns.  Your results should be formatted as shown below. 
    The mean value of the array is x.
    

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  7. (10 points) Fill in the code for function sort(). sort() takes an array and its size, and sorts it in increasing order.  You may use Kochan's sort on p. 144-5 or any other sorting method you find or create. Test the sort function by invoking it in the main() function and then calling the printArray() function to see that the houses array is sorted.  After testing and debugging this function, commit your work to your Subversion repository.
  8. (5 points) Fill in the code for function findMedian. findMedian() takes an already sorted array and its size, and  returns the median of the values in the array.  Test the findMedian function by invoking it in the main() function and printing its value.  Your results should be formatted as shown below
    The median value of the array is x.
    

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  9. (5 points) Fill in the code for function printNHighestPrices(). printNHighestPrices() takes an already sorted array, its size, and an int n as parameters and print a message with the n highest values in the array.  Test the printNHighestPrices function by invoking it in the main() function.  Your results should be formatted as shown below 
    The n highest values in order are x1, x2, ..., xn. 
    

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  10. (5 points) Repeat question 9 for function printNLowestPrices().
  11. (5 points) In function main() delete the statement used to initialize the houses array and fill the array with the prices below, taken from the website (in fall 2007) referenced in question 4. (Copy and paste are your friends here.)
    double houses[] = {129500.0, 129900.0, 138900.0, 159900.0, 
        44900.0, 490000.0, 89500.0, 34000.0, 82000.0, 219900.0,
        47500.0, 144900.0, 159999.0, 99900.0, 166900.0, 229900.0,
        240000.0, 89900.0, 299900.0, 49900.0, 585000.0, 275000.0,
        209900.0, 259900.0, 269900.0, 389900.0, 86500.0, 99900.0,
        79900.0, 175000.0, 54900.0, 139900.0, 129900.0, 34900.0,
        119900.0, 257700.0, 149900.0, 139900.0, 149900.0, 174900.0,
        145900.0, 189900.0, 212900.0, 48900.0, 75900.0, 330000.0,
        17500.0, 235000.0, 449900.0, 179900.0, 119900.0, 147000.0,
        155000.0, 239000.0, 219900.0, 309000.0, 131900.0, 345000.0,
        165000.0, 299900.0, 45000.0, 230000.0, 99500.0, 83500.0,
        156900.0, 289900.0, 45900.0, 185500.0, 19000.0, 124000.0,
        159900.0};
    
    Change the value of numberOfHomes in the line above the array initialization to 71. [Note: We would not have to calculate this number by hand if we were using Python.  Can you see why?].  Using the functions you have implemented and tested above, have your program provide the information requested in question 4.  Your output should be formatted as follows (substituting the actual values, of course):
    The mean price of 4 bedroom houses in Vigo County is $12345.67.
    The median price of 4 bedroom houses in Vigo County is $12345.67.
    The 5 most expensive 4 bedroom houses in Vigo County cost $12345.67, $12345.67, $12345.67, $12345.67, and $12345.67.
    The 5 least expensive 4 bedroom houses in Vigo County cost $12345.67, $12345.67, $12345.67, $12345.67, and $12345.67.
    
  12. Submit your code by committing the final version to your Subversion repository.
  13. (5 points) Now that you have gained experience programming with Python lists and C arrays, we're asking you to compare them. Answer the following two questions in the file listArrayComparison.txt found in your project:

    Suppose you are asked by a company that processes terabytes of data to use either Python lists or C arrays to help them process their data.

    1. (2 points) Which of these two data structures is it easier for you to work with as a programmer? Why?
    2. (3 points) Now assume also that they also need the results quickly, that is, efficiency is a concern. Which data structure should you use? Why?
  14. When you are through, be sure to commit your solution back to your SVN repository.