Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. Problem Specification: Write a program to merge arrays containing occurrence d

ID: 3816200 • Letter: #

Question

. Problem Specification:

Write a program to merge arrays containing occurrence data for the pink moon.
Your program should begin with the following prompt, using the symbolic constant of your name provided in the
program header file, lab9.h:
PINK MOON PROGRAM WRITTEN IN C
This program was written by Sharon Software.

How do you want to see the data sorted?

Your program should allow the user to display the dates in whichever order they choose:

Year
Date in April
Time of day


You should prompt the user if they want the data ascending or descending.


Tasks:

1. Use a header file for this specific lab assignment. Call it

pink_moon.h


2. Place the following lines into the header


#ifndef PINK_MOON_H

#define PINK_MOON_H

int year_markers[] = { 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, };
int day_markers[] = { 18, 6, 25, 15, 4, 22, 11, 30, 19, 8, };
int time_markers[] = { 244, 1919, 1957, 742, 1206, 524, 608, 58, 1112, 235, };
char *day_of_week_markers[] = { "Mon", "Fri", "Thu", "Tue", "Sat", "Fri", "Tue", "Mon", "Fri", "Sat", };

#endif


3. The following is a sample program that uses the pink_moon.h header file and prints out some test data.


#include <stdio.h> #include <stdlib.h> #include <pink_moon.h>

void print_full_table( int [], int [], int [], char **, int n );

int main() {

}

print_full_table( year_markers, day_markers, time_markers, day_of_week_markers, 4 );

return EXIT_SUCCESS;

void print_full_table( int year[], int day[], int time[], char **dow, int n ) {

int i;

for ( i = 0; i < n; i++ ) {
int hh = time[ i ] / 100;

}

return; }

int mm = time[ i ] - hh * 100;
printf( "%d. %d %2d %2.2d:%2.2d %s ", i+1, year[ i ],

day[ i ], hh, mm, dow[ i ] );

}

return; }


4. You can use the following command at the Linux prompt to download the header file and the sample program from Github, a version control repository commonly used by programmers.


git clone https://github.com/untamedspud/lab9-spring2017.git


Confirm that this code compiles and runs successfully, and that you understand what it does, before you continue on with your program.


git clone https://github.com/untamedspud/lab9-spring2017.git


You can rename the pnkmoon.c file to be lab9.c and build on it from there if you would like.


5. Prompt the user to sort the data so that this interaction would work:


How do you want to see the data sorted? [1–byyear, 2–bydayinApril

3–bytimeofday, 4- exit] ?


2 Ascending[1] or descending[2] order? 1


Blue Moon Dates by day in April,


Ascending

1. Mon, April 30, 2018 at 00:58.

2. Sat, April 8, 2020 at 02:35.

3. Mon, April 18, 2011 at 02:44.

4. Fri, April 22, 2016 at 05:24. .

. .

How do you want to see the data sorted? [1–byyear, 2–bydayinApril

3–bytimeofday, 4- exit] ?4 Goodbye.


6. Create a function to sort the data in the parallel arrays using the selection sort.

void sort_parallel_arrays( int arr[], int idx[], int n, ordering a );

The first argument, arr, is the array containing the data to be sorted. The second argument is an index, used to indicate what the sequence is through the data after the array is sorted. The third argument, n, is the number of elements in the arrays arr and idx. The fourth element represents ascending or descending.

The idx array should be prepopulated with the numbers 0 through n, representing the ordering of the array arr as it is passed in to the function.





Problem Specification: occurrenocidaua Write a program to merge armays containing Your program should begin with the following prompt, asing symbo program header file, lab9h: ThaR PEegrataa vaa NEitten by Rov do you want to see the dat Your program should allow the user to display Year Date in April Time of day You should prompt the user if they want the data Page l of 5 Tasks: Use a header file for this specific lab assignment, Call it pink noon. 2. Place the following lines into the header int rear markers 2015. 201 2017. 2018. 2015. 2020. 1 25, 15, 4 3. The following is a sample program that uses the pink moon.h header file and prints out some test data void print table int int main print full able year narkoers, day markets. time markers ki printf 2d 12.2 2.2d ss i 1, year 1 day

Explanation / Answer

#include <stdio.h>
#define NA -1
void moveToEnd(int mPlusN[], int size)
{
int i = 0, j = size - 1;
for (i = size-1; i >= 0; i--)
if (mPlusN[i] != NA)
{
mPlusN[j] = mPlusN[i];
j--;
}
}
int merge(int mPlusN[], int N[], int m, int n)
{
int i = n; /* Current index of i/p part of mPlusN[]*/
int j = 0; /* Current index of N[]*/
int k = 0; /* Current index of of output mPlusN[]*/
while (k < (m+n))
{
if ((i < (m+n) && mPlusN[i] <= N[j]) || (j == n))
{
mPlusN[k] = mPlusN[i];
k++;
i++;
}
else // Otherwise take element from N[]
{
mPlusN[k] = N[j];
k++;
j++;
}
}
}
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);

printf(" ");
}
int main()
{
int mPlusN[] = {2, 6, NA, NA,10, NA, 12, 15};
int N[] = {5, 7, 9, 25};
int n = sizeof(N)/sizeof(N[0]);
int m = sizeof(mPlusN)/sizeof(mPlusN[0]) - n;
moveToEnd(mPlusN, m+n);
merge(mPlusN, N, m, n);
printArray(mPlusN, m+n);
return 0;
}