Starting from:

$30

Project #4 Using pointers to process arrays (

Project #4
Task #1 - Using pointers to process arrays (50
points)
Task
Modify project 3, task #2, to use pointers to process the array in the ac!ve_seconds func!on.
Requirements
Name your program project4_escalator.c
The program should include the following func!on:
 int ac!ve_seconds(int arrival[], int n)
The func!on calcuates the total number of ac!ve seconds. Array arrival[] represents the
arrival !me of each person, n is the length of array arrival, represen!ng the number of
people.
 This func!on should use pointer arithme!c– not subscrip!ng – to visit array elements. In
other words, eliminate the loop index variables and all use of the [] operator in the func!on.
In the main func!on, call the ac!ve_seconds func!on and display the result.
Pointer arithme!c is NOT required in the main func!on.
Examples (your program must follow this format precisely)
Example #1
Enter number of people: 2
Enter arrival times: 12 25
Active seconds: 20
Example #2
Enter number of people: 3
Enter arrival times: 12 15 20
Active seconds: 18
Example #3
Enter number of people: 5
Enter arrival times: 12 15 20 34 41
Active seconds: 35
Submission instruc!ons
1. Develop and test your program on the student cluster
1. To compile your program, run: $ gcc -std=c99 -Wall your_program.c
2. To execute your program, run: $ ./a.out
2. Name your program project4_escalator.c
1. To rename your program, run: $ mv your_program.c project4_escalator.c
3. Test your program with the shell script on Unix: try_project4_escalator
1. Upload the script to the same directory as your program.
2. Run: $ chmod +x try_project4_escalator
3. Run: $ ./try_project4_escalator
4. Download the program from student cluster and submit it on Canvas->Gradescope. Make
sure you submit a file with the correct name!
5. You can submit your program as many !mes as needed before the due date. Gradescope
will indicate the test cases with incorrect output, if any exists.
Task #2 - Exclusive or (50 points)
Task
The exclusive or of two arrays a and b of integers are the elements that are either in a or in b,
but not in both a and b. Write a program that finds the exclusive or of two input arrays. For
example, array a contains elements {8, 10, 12}, array b contains elements {23, 4, 8, 12}. The
exclusive or of a and b should contain {10, 23, 4}.
Requirements
Name your program project4_exclusive_or.c.
Follow the format of the examples below.
Your program should include the following func!on:
void exclusive_or(int *a, int n1, int *b, int n2, int *c, int *size);
The func!on should use pointer arithme!c – not subscrip!ng – to visit array elements. In
other words, eliminate the loop index variables and all use of the [] operator in the func!on.
The exclusive_or func!on finds the exclusive or of array a and array b, and stores the result in
array c. n1 is the number of elements of the array a and n2 is the number of elements in array b.
The func!on should keep track of the number of elements for the exclusive or and store it
through the pointer variable size.
In the main func!on, ask the user to enter the lengths of the arrays, the array elements, declare
the input arrays, and the output array. The length of the output array should be declared as the
sum of the lengths of the two input arrays. The actual length will be determined by the
exclusive_or func!on.
The main func!on call the exclusive_or func!on and display the result.
Pointer arithme!c is NOT required in the main func!on.
The order of the numbers in the output does not ma"er.
Examples (your program must follow this format precisely)
Example #1
Enter length of array #1: 5
Enter array elements: 31 17 32 2 88
Enter length of array #2: 3
Enter array elements: 17 2 31
Output: 32 88
Example #2
Enter length of array #1: 3
Enter array elements: 36 19 32
Enter length of array #2: 3
Enter array elements: 17 2 31
Output: 36 19 32 17 2 31
Example #3
Enter length of array #1: 3
Enter array elements: 31 17 2
Enter length of array #2: 3
Enter array elements: 17 2 31
Output:
Submission instruc!ons
1. Develop and test your program on the student cluster
A. To compile your program, run: $ gcc -std=c99 -Wall your_program.c
B. To execute your program, run: $ ./a.out
2. Name your program project4_exclusive_or.c
A. To rename your program, run: $ mv your_program.c project4_exclusive_or.c
3. Test your program with the shell script on Unix: try_project4_exclusive_or
A. Upload the script to the same directory as your program.
B. Run: $ chmod +x try_project4_exclusive_or
C. Run: $ ./try_project4_exclusive_or
4. Download the program from student cluster and submit it on Canvas->Gradescope. Make
sure you submit a file with the correct name!
5. You can submit your program as many !mes as needed before the due date. Gradescope
will indicate the test cases with incorrect output, if any exists.
General instruc!ons
Grading
Task #1
Total points: 50
A program that does not compile will result in a zero.
Run!me error and compila!on warning 3 points
1 points off, if a warning is present.
3 points off, if mul!ple warnings are present.
Commen!ng and style 8 points
 1 point off for not pu$ng name and descrip!on at the beginning
 2 to 4 points off if the code didn't have clarifying comments.
 1 to 3 points off (depending on how much indenta!on is off) if the program is not indented
properly.
Func!onality
 3 points off for each incorrect test case
 25 points off if pointer arithme!c is not used to process array
 10-20 points off if pointer arithme!c is not used correctly to process array
Task #2
Total points: 50
A program that does not compile will result in a zero.
Run!me error and compila!on warning 3 points
1 points off, if a warning is present.
3 points off, if mul!ple warnings are present.
Commen!ng and style 8 points
1 point off for not pu$ng name and descrip!on at the beginning
2 to 4 points off if the code didn't have clarifying comments.
1 to 3 points off (depending on how much indenta!on is off) if the program is not indented
properly.
Func!onality
 5 points off for each incorrect test case
 15 points off if pointer arithme!c is not used to process arrays
 5-10 points off if pointer arithme!c is not used correctly to process arrays
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
applica!on area to quickly read a program and understand how it works.
Your program should begin with a comment that briefly summarizes what it does. This
comment should also include your name.
In most cases, a func!on should have a brief comment above its defini!on describing what
it does. Other than that, comments should be wri"en only needed in order for a reader to
understand what is happening.
Variable names and func!on names should be sufficiently descrip!ve that a knowledgeable
reader can easily understand what the variable means and what the func!on does. If this is
not possible, comments should be added to make the meaning clear.
Use consistent indenta!on to emphasize block structure.
Full line comments inside func!on bodies should conform to the indenta!on of the code
where they appear.
Macro defini!ons (#define) should be used for defining symbolic names for numeric
constants. For example: #define PI 3.141592
Use names of moderate length for variables. Most names should be between 2 and 12
le"ers long.
Use underscores to make compound names easier to read: tot_vol and total_volumn are
clearer than totalvolumn. 

More products