# hw4 - COMPUTER SCIENCE 50100 Computing for Science and...

This preview shows pages 1–3. Sign up to view the full content.

COMPUTER SCIENCE 50100 Computing for Science and Engineering FALL 2014 ASSIGNMENT # 4 (35 points) October 8 Announcement Exams 5, 6 and the Final are Tuesday, December 16, 8-10 am in Forney G140. Due Wednesday, October 29 at 11:30 am This assignment covers Sections 4.2.3–4.5 of the class notes. 1. (6 points) Provide the two missing statements for the following program, as directed by the comments. There is no need to check for failure of a C library function. // copy.c #include <stdio.h> #include <stdlib.h> double *copy(int m, int n, int n0, double (*a)[n0]); int main(void){ double a[10][10]; for (int j = 0; j < 100; j++) a[0][j] = (double)j; double (*b)[4]; // call the copy function to make a copy of a[i][j], // 3 <= i < 7, 3 <= j < 7, and assign the result to b ...one assignment statement... for (int i = 0; i < 4; i++){ for (int j = 0; j < 4; j++) printf("%f ", b[i][j]); printf("\n");} free(b);} double *copy(int m, int n, int n0, double (*a)[n0]){ // return a copy (with no gaps) of an array a of dimension m by n // where n0 is the stride for the row index of a ...one declaration with initialization... for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) b[i][j] = a[i][j]; return (double *)b;} 2. (18 points) Given below is a C implementation of a Set class. // set0.c #include <stdlib.h> #include <stdbool.h> typedef struct set{ 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
int size0, size; int nval; int *value;} Set; // array of int Set *Set_new(int size){ Set *set = (Set *)malloc(sizeof(Set)); set->size = set->size0 = size; set->nval = 0; set->value = (int *)malloc(size*sizeof(int)); return set;} void Set_delete(Set *set){ free(set->value); free(set);} void Set_add(Set *set, int element){ bool found = false; int i = 0; while (!found && i < set->nval)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern