Question: C++ Help main has function definitions, they should be in a .cpp file header should not have or using namespace getInteger has while true and

C++ Help

main has function definitions, they should be in a .cpp file

header should not have or using namespace

getInteger has while true and break, not allowed

getInteger does not check for invalid data type

min and max should be constants and global

srand should be called in main

int * array = new int [size] not (size)

you do you have another search at the bottom of main

delete []array

.CPP File

#include  #include #include #include #include "header.h" using namespace std; int getInteger(int min,int max){ int value; while(true){ cin>>value; if(value>min && value<max){ break; }else{ cout<<"Value can not be 10 or 20"<array,int ,int value,int cap){ int i; for(i=cap-1;(i>=0 && *(array+i) > value);i--){ array[i+1]= array[i]; } array[i+1] = value; } //dynamic memory allocation int* createArray(int size){ //set to current time srand(time(nullptr)); int min = -50; int max = 50; int range = (max - min); int cap=0; int *array = new int(size); //here we set the values of the array with max+1 for(int i=0;i<size;i++){ *(array+i)= max+1; } //randomly insert value to the array for(int i=0;i<size;i++){ int value; value = rand() % range + min; insert(array,size,value,cap); cap++; } return array; } //display the array 5 value in one row void displayArray(const int* array,int size){ int count=0; for(int i=0;i<size;i++){ if(count==5){ cout<array+i)<<" "; } cout<array,int size,int value){ int s=0; int e=size-1; int mid; while(e>=s){ mid = (s+e)/2; if(*(array+mid)==value){ return true; }else if(*(array+mid)>value){ e = mid-1; }else{ s = mid+1; } } return false; } int main() { cout << "Enter size of the array: "; int size = getInteger(10, 20); //create an array and fill with random values int *array = createArray(size); displayArray(array, size); // get 3 values from the user to search in the array for (int i = 0; i < 3; i++) { cout << "Enter value to Search: "; int value = getInteger(-50, 50); string result = binSearch(array, size, value) == 0 ? "False" : "True"; cout << result << endl; } //Get new value from the user to search inside the array cout << endl; cout << "Enter new Value: "; int value = getInteger(-50, 50); string result = binSearch(array, size, value) == 0 ? "Not Found" : "Found"; cout << result << endl; delete (array); return 0; 

.H File

#ifndef UNTITLED6_HEADER_H #include  using namespace std; int getInteger(int min,int max); void insert(int *array,int size,int value,int cap); int* createArray(int size); void displayArray(const int* array,int size); bool binSearch(const int* array,int size,int value); #define UNTITLED6_HEADER_H #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!