Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

and the following functions: - (10) struct IntArray* mallocintArray(int length): allocates, initializes, and returns a pointer to a new struct IntArray. Hint: see example from

image text in transcribed

image text in transcribed

and the following functions: - (10) struct IntArray* mallocintArray(int length): allocates, initializes, and returns a pointer to a new struct IntArray. Hint: see example from class - also, you'll need two malloc calls, one for the instance and one for the instance's dataPtr (a pointer to an int array of size length). - (10) void freelntArray(struct IntArray *arrayPtr): frees the instance's dataPtr and frees the instance. - (10) void readIntArray(struct IntArray *array): prompts and reads positive (>0) ints from the user to fill the array (i.e., read one int for each array index). Your program should print an error message and prompt again if the user enters a value that cannot be parsed as a positive int. Hint: I recommend using fgets and strtol-you can Google for examples of these (cite your sources) and we'll cover them in labs. Hint: strategically, you might consider skipping the validation initially and coming back to it once the remainder of the program is functional. - (15) void swap(int *xp, int *yp): swaps the int values stored at the xp and yp pointers. - (15) void sortIntArray(struct IntArray *array): sorts the input array in ascending order using Bubble Sort (Google it, cite your sources) by repeatedly calling your swap function as appropriate. - (10) void printIntArray(struct IntArray *array): prints the array (e.g., " [1,3,5,7] ). - (10) int main(): prompt the user to input a positive (>0) int length from the user (print an error message and prompt again if the input cannot be parsed as a positive int), call mallocintArray to create an array, call readlntArray to prompt the user to fill the array, call sortIntArray to sort it, call printArray to print the resulting sorted array, then call freelntArray to free the heap memory used by the array. Here is output from a sample run of the application (your output does not need to match exactly): Enter length: cat Invalid input Enter length: 5 Enter int: 3 Enter int: puppy Invalid input Enter int: 7 Enter int: 5 Enter int: 8 Enter int: 2 [2,3,5,7,8]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

1 Life sciences, genomics, and biotechnology for health

Answered: 1 week ago

Question

What is cultural tourism and why is it growing?

Answered: 1 week ago