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
hw21and submit using the204subcommand. - This is an electronic homework and you do not need to print out anything to turn in during class.
Assignment
- Required reading: Sections 3 (Heap-based arrays) and 4 (Arrays & Functions) from the Unit 6 notes,
- 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$./showlargeEnter 5 numbers:100 200 300 400 500Big ones: 200 300 400 500
roche@ubuntu$./showlargeEnter 5 numbers:50 150 60 160 70Big ones: 150 160
roche@ubuntu$./showlargeEnter 5 numbers:1 2 3 4 5Big ones:
roche@ubuntu$./showlargeEnter 5 numbers:1000 1000 1000 1000 1000Big ones: 1000 1000 1000 1000 1000