SI 204 Spring 2017 / HWs


This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Homework 21: Heap-based arrays

Name: _____________________________________________ Alpha: ___________________

Describe help received: ________________________________________________________

  • Due before class on Wednesday, March 8
  • This homework contains code to be submitted electronically. Put your code in a folder called hw21 and submit using the 204sub command.
  • This is an electronic homework and you do not need to print out anything to turn in during class.

Assignment

  1. Required reading: Sections 3 (Heap-based arrays) and 4 (Arrays & Functions) from the Unit 6 notes,
  2. Write a program called showlarge.c that reads in 5 numbers from the user, stores them in an array, and then prints out the numbers in the array that are larger than 100.

    Although you could certainly write this program without using functions, to give you practice and check your reading I want you to write the following functions and use them in your short program:

    // allocates a size-len array, then reads in len numbers
    // and stores them in that array, and returns the array.
    double* readnumbers(int len);
    
    // prints out all numbers in the array data of size len that
    // are larger than minval.
    void printlarger(double* data, int len, double minval);

    Example runs:

    roche@ubuntu$ ./showlarge
    Enter 5 numbers: 100 200 300 400 500
    Big ones: 200 300 400 500
    roche@ubuntu$ ./showlarge
    Enter 5 numbers: 50 150 60 160 70
    Big ones: 150 160
    roche@ubuntu$ ./showlarge
    Enter 5 numbers: 1 2 3 4 5
    Big ones:
    roche@ubuntu$ ./showlarge
    Enter 5 numbers: 1000 1000 1000 1000 1000
    Big ones: 1000 1000 1000 1000 1000