Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 4, Program Design 1. (50 points) Write a program that separates an input array into two arrays. It stores the elements that are greater

Project 4, Program Design 1. (50 points) Write a program that separates an input array into two arrays. It stores the elements that are greater than a value (entered by the user) in array larger, and the elements that are smaller or equal to the value in array smaller. The program should include the following function. void separate(int *a, int n, int value, int *larger, int *size, int *smaller); The function should use pointer arithmetic not subscripting to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function. The separate function finds the numbers that are greater than value in the array a and store them in array larger. The function finds the numbers that are smaller or equal to value in the array a and store them in array smaller. The fourth parameter size points to a variable in which the function will store the number of larger numbers in the array. The number of elements that are smaller than (or equal to ) value in the array can be calculated by the number of larger numbers and the size of the input array. In the main function, ask the user to enter the length of the array, the array elements, and the value for separating the array, declare the input array with the length, and two output arrays with the same length (the actual length will be determined by the separate function), and call the function. The function will store the actual lengths of the arrays storing the larger numbers. The main function should display the result. Example Input/Output: Enter the length of the array: 8 Enter the elements of the array: 12 0 -4 10 36 7 -8 45 Enter the value for separating the array: 7 Output: Array with elements larger than 7: 12 10 36 45 Array with elements smaller than or equal to 7: 0 -4 7 -8 2. (50 points) Write a program arrays.c that compares elements of two integer arrays a and b, and stores the elements in array c that are either in a or in b, but not in both a and b. For example, array a contains elements {1, 2, 3}, array b contains elements {3, 2, 6, 7}. Array c should contain {1, 6, 7}. Your program should include the following function: void find_elements(int *a, int n1, int *b, int n2, int *c, int *size); The function should use pointer arithmetic not subscripting to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function. The find_elements function finds the elements that in either array a or array b, but not both, and stores the result in array c. The function takes an int array parameters a1 and 2 as the first parameter and third parameters and the number of elements of the arrays as the second parameter. The sixth parameter size points to a variable in which the function will store the number of actual elements in array c. In the main function, ask the user to enter the lengths of the arrays, the array elements, declare the input arrays, and the output array with length as the sum of the lengths of the two input arrays (the actual length will be determined by the find_elements function), and call the function. The main function should display the result. Example Input/Output: Enter the length of the first array: 5 Enter the elements of the array: 9 8 5 6 4 Enter the length of the second array: 4 Enter the elements of the array: 6 9 7 1 Output: 8 5 4 7 1 Before you submit 1. Compile both programs with Wall. Wall shows the warnings by the compiler. Be sure it compiles on student cluster with no errors and no warnings. gcc Wall separate.c gcc Wall arrays.c 2. Be sure your Unix source file is read & write protected. Change Unix file permission on Unix: chmod 600 separate.c chmod 600 arrays.c 3. Test your programs with the shell scripts on Unix: chmod +x try_separate ./try_separate chmod +x try_find_elements ./try_find_elements 4. Submit separate.c and arrays.c on Canvas. Grading Total points: 100 (50 points each problem) 1. A program that does not compile will result in a zero. 2. Runtime error and compilation warning 5% 3. Commenting and style 15% 4. Functionality 80% -Functions implemented as required Programming Style Guidelines The major purpose of programming style guidelines is to make programs easy to read and understand. Good programming style helps make it possible for a person knowledgeable in the application area to quickly read a program and understand how it works. 1. Your program should begin with a comment that briefly summarizes what it does. This comment should also include your name. 2. In most cases, a function should have a brief comment above its definition describing what it does. Other than that, comments should be written only needed in order for a reader to understand what is happening. 3. Information to include in the comment for a function: name of the function, purpose of the function, meaning of each parameter, description of return value (if any), description of side effects (if any, such as modifying external variables) 4. Variable names and function names should be sufficiently descriptive that a knowledgeable reader can easily understand what the variable means and what the function does. If this is not possible, comments should be added to make the meaning clear. 5. Use consistent indentation to emphasize block structure. 6. Full line comments inside function bodies should conform to the indentation of the code where they appear. 7. Macro definitions (#define) should be used for defining symbolic names for numeric constants. For example: #define PI 3.141592 8. Use names of moderate length for variables. Most names should be between 2 and 12 letters long. 9. Use underscores to make compound names easier to read: tot_vol or total_volumn is clearer than totalvolumn.

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

What are the characteristics of modern science?

Answered: 1 week ago

Question

Identify three ways to manage an intergenerational workforce.

Answered: 1 week ago

Question

Prepare a Porters Five Forces analysis.

Answered: 1 week ago

Question

Analyze the impact of mergers and acquisitions on employees.

Answered: 1 week ago