1. Write a function, double_array(int row, int col), which returns a pointer to a struct called Double_Array. The Double_Array struct holds an uninitialized 2 dimensional double array, the row size, and the column size (accessed using .array, .rowsize, .colsize respectively).

Note:

  • From this point on, all functions will be referred to by their parameter signature
    • i.e. the types of the parameters will be given, but not their variable names.
  • This gives you design control over the local variable names used in the function.
  • However, in some cases parameter names are provided in the question.
    • In these cases, please use them.

2. Using the function rand_double() you used in Lab Assignment 2, write a function randomize_array(struct Double_Array *, double, double) that takes a Double_Array struct, and two values of type double and initializes each element of the array in Double_Array to a randomly generated value between the two input values (inclusive).

3. Create a function called print_array() that takes a Double_Array struct pointer and prints the array with each element displaying 1 decimal place, with the column elements lining up vertically.

4. Create a function called free_array() which takes a Double_Array struct pointer and frees the struct as well as the array within it.

5. Create a function called swap_rows(struct Double_Array *, int, int) where the two integer are row numbers to be swapped. Make sure each row number is valid according to the structure. If valid the rows are swapped and the function returns 1, otherwise the rows are not swapped and the function returns 0.

6. Create a function called swap_columns(struct Double_Array *, int, int) where the two integer are column numbers to be swapped. Make sure each column number is valid according to the structure. If valid the columns are swapped and the function returns 1, otherwise the columns are not swapped and the function returns 0.

7. Create a main() called a2_q1.c that performs the following:

  • Prints the following header
-------------------------------------
Question 1
-------------------------------------
  • Creates a Double_Array struct that holds a 6 row by 9 column array
  • Randomly initializes the array in the struct (you may choose the upper and lower bounds a and b)
  • Prints out the array from the struct
  • Randomly pick two rows to swap, and swaps them
  • Inform the user which two rows were swapped and then print out the array
  • Randomly pick to columns to swap, and swap them
  • Inform the user which two columns were swapped and then print out the array
  • Print 3 blank lines

Make sure you free all malloced memory before exiting the program.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.