Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could someone help me to JUST COMPLETE my code below please. The assignment asks that we have seperate header and cpp files it just wont

Could someone help me to JUST COMPLETE my code below please. The assignment asks that we have seperate header and cpp files it just wont compile right.

image text in transcribed

My code so far

main.cpp

#include #include #include "search.h" #include "sort.hh" #include "statistics.hh"

using namespace std;

//Function prototypes void data(int[],int);

int main() { //Declare variables int t,num,elements[50],key;

//Prompt and read input from the user cout>num;

while(num>50) { cout>num; }

//Call the methods data(elements,num); Display(elements,num,"unsorted"); sortArray(elements,num); Display(elements,num,"sorted");

cout>key;

t=binarySearch(elements,num,key); if(t

sort.cpp

#include #include #include "sort.hh" using namespace std;

void Display(int elements[],int n,string d) { int i; cout

void sortArray (int elements[], int size) { bool swap; int temp;

do { swap=false; for (int count =0; count elements[count+1]) { temp = elements[count]; elements[count]=elements[count+1]; elements[count+1]=temp; swap=true; } } } while (swap); }

sort.hh

#ifndef _SORT_HH_INCLUDED // is myheader.h already included? #define _SORT_HH_INCLUDED // define this so we know it's included

using namespace std; //Function prototypes void sortArray(int[],int); void Display(int[],int,string);

#endif

search.cpp

#include #include #include "search.h"

int binarySearch(int[],int,int);

#include #include using namespace std;

int binarySearch(int elements[], int size, int value) { int first=0, last = size-1, middle, position = -1; bool found =false;

while (!found && first value) last - middle-1; else first = middle +1; } return position;

}

search.h

#ifndef _SEARCH_H_INCLUDED // is myheader.h already included? #define _SEARCH_H_INCLUDED // define this so we know it's included //Function prototypes

int binarySearch(int[],int,int);

#endif

statistics.cpp

#include #include #include "statistics.hh"

//Method definition of mean: Recall that the mean is //the sum of the data values divided by the number //of pieces of data.

double mean(int elements[],int n) { int i,sum=0; for(i=0;i

statistics.hh

#ifndef _STATS_HH_INCLUDED // is myheader.h already included? #define _STATS_HH_INCLUDED // define this so we know it's included //Function prototypes

double mean(int[],int);

#endif

Write a program that prompts the user to enter the number of elements and the numbers themselves to be placed in an dynamic integer array that holds a maximum of 50 elements. (Do not forget to validate!!) - then prompts the user for an integer which will be searched for in the search. Make sure to include the following steps array using a binary along the way: i) A sort routine must be called before the binary search. You may use either the selection sort or the bubble sort. However, the sort must be implemented in its own function and its own implementation file called "sort.cpp". Write the appropriate header in "sort.hh" Next include a function called by main to implement the binary search. This function should be implemented in a file called "search.cpp", with a header in "search.hh". The ordered array produced by the sort should be passed to the search routine which returns the location in the sorted array of the sought value, or -1 if the value is not in the array iii) Add a value returning function that computes the mean of your data set, in a implementation file/header file called "statistics.cpp" and "statistics.hh" Recall that the mean is the sum of the data values divided by the number of pieces of data. Your program should output the size of the array entered, the array as entered by the user, the sorted array, the integer being searched for, the location of that integer in the sorted array (or an appropriate message if it is not in the array), and the mean of the data set<>

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago