QuestionQuestion

Mini-Project:

This Mini-Project is on packaging frequently used functions in separate libraries. Each library should have a header file, which contains function declarations, and a source file, which contains function definitions. You should also implement an application which calls the test functions of each library, hence each function coded will be called. You can use either C or C++ in your project.

Below are the libraries and functions that you should implement. The last library, myself, should contain at least three functions of your own, as well as the test function: Sorting library – sort.h

void quickSort(int arr[], int count)
Sorts the given array using QuickSort

void shellSort(int arr[], int count)
Sorts the given array using ShellSort

void bubbleSort(int arr[], int count) Sorts the given array using BubbleSort

void selectionSort(int arr[], int count)
Sorts the given array using SelectionSort

int testSort()

Checks whether the functions in the library behave as expected or not. You should return a nonzero value if everything is OK, zero otherwise. To test the functions, create integer arrays of different sizes, having both unsorted and sorted versions. Then call the related function with the unsorted version and compare the result with the sorted version. You can create the sorted version of the array with a function that you know for sure works correctly – like qsort in stdlib.
File reading/writing library – file.h

int readFromFile(int *data, unsigned int size, const char *filename)
Reads the integers in the given file and returns the number of integers successfully read.

int writeToFile(const int *data, unsigned int size, const char *filename)
Writes the integers to the given file and returns the number of integers successfully written.

int testFile()
Checks whether the functions in the library behave as expected or not. You should return a nonzero value if everything is OK, zero otherwise.

Array operations library – array.h

void printArr(const int arr[], int count)

Prints the content of the array to stdout.

int getMedianOf(const int arr[], unsigned int size)

Returns the median of the array. To get the median, you should sort the values in the array and return the value in the middle of the sorted values. Be careful, you cannot modify the given array.

double getMeanOf(const int arr[], unsigned int size)
Returns the mean of the values in the array.

double getSDOf(const int arr[], unsigned int size)
Returns the stardard deviation of the values in the array.

long long getSumOf(const int arr[], unsigned int size)
Returns the sum of the values in the array.

int isArrSorted(const int arr[], unsigned int size)
Returns a positive integer if the array is sorted in increasing order, a negaive integer in the array is sorted in decreasing order, and returns zero if the array is not sorted.

int isArrSame(const int arr1[], const int arr2[], unsigned int size)
Returns a positive integer if the given arrays are the same. Returns zero otherwise.

void fillWithRandom(int data[], unsigned int size, int min, int max)


Fills the given array with random integers, in the range of [min, max], both of them inclusive.
void fillWithVal(int data[], unsigned int size, int value)

Fills the given array with the given integer value.
int testArray()
Checks whether the functions in the library behave as expected or not. You should return a nonzero value if everything is OK, zero otherwise.
Your library – myself.h
function1
Performs function1 properly.
function2
Performs function2 properly.
function3
Performs function3 properly.
int testMyself()
Checks whether the functions in the library behave as expected or not. You should return a nonzero value if everything is OK, zero otherwise.

Notes on the project:

For file.h:
a)reading the file, then write what I have read into another into another file.The two files should be the same. To confirm you can read and compare the two file’s contents.
b)Write an array into a file, then read into another array from that file.(This might also be write into another array from that file, translating into English is complicated). Arrays should be the same.

For array.h:
a) Call the functions for an array whose SD, mean, sum etc. you know of, compare the results with the known values.
b) Check if an array is the same as itself, it should be. Then, compare two arrays you know are different.

You can use any of these functions or any functions you think of for myfunction1, myfunction2, myfunction3 as long as the function you thought isn’t too complex or hard to program(so the teacher doesn’t catch on to me). JUST PROGRAM 3 OF THESE FUNCTIONS(or of the ones you thought of) IN TOTAL for myfunction1, myfunction2 and 3; DON’T CREATE EVERY SINGLE ONE OF THEM

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include "sort.h"
#include "commonFunc.h"

void quickSort( int arr[], int count){
quickSort1(arr,0,count-1);
}
void quickSort1( int a[], int l, int r){
   int j;

   if( l < r )
   {
    // divide and conquer
       j = partition( a, l, r);
       quickSort1( a, l, j-1);
       quickSort1( a, j+1, r);
   }

}
int partition( int a[], int l, int r) {
   int pivot, i, j, t;
   pivot = a[l];
   i = l; j = r+1;

   while( 1)
   {
    do ++i; while( a[i] <= pivot && i <= r );
    do --j; while( a[j] > pivot );
    if( i >= j ) break;
    t = a[i]; a[i] = a[j]; a[j] = t;
   }
   t = a[l]; a[l] = a[j]; a[j] = t;
   return j;
}



void bubbleSort( int arr[], int count){
int i, j, temp;
int sorted;

for( i = 1; i < count; ++i) // repeat bubble pass n-1 times
{ // i from 1 to n-1

sorted = 1; // for efficiency reasons

for( j = 0; j < count-i; ++j)   // j from 0 to n-i-1
if( arr[j] > arr[j+1]) { // n-i comparisons
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
sorted = 0;
}
if (sorted) break; // no changes in a pass => already sorted
} // so no need for further bubble passes

}




void shellSort (int arr[], int count) {
    int h, i, j, t;
    for (h = count; h /= 2;) {
       for (i = h; i < count; i++) {
            t = arr[i];
            for (j = i; j >= h && t < arr[j - h]; j -= h) {
                arr[j] = arr[j - h];
            }
            arr[j] = t;
       }
    }
}...

By purchasing this solution you'll be able to access the following files:
Solution1.zip and Solution2.docx.

50% discount

Hours
Minutes
Seconds
$50.00 $25.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats