#include using namespace std; //function to sort elements of array void sort(int a[], int n) { int i,j,temp; for(i=1;ia[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } } //function to search location of item using binary search int binary_search(int a[],int n,int item) { int beg,end,mid; beg=0; end=n-1; mid=(beg+end)/2; while((beg<=end)&&(a[mid]!=item)) { if(item>n; cout<<"Enter "<>a[i]; } cout<<"\nThe size of the array entered by user is: "<>item; cout<<"\nThe integer being searched is: "<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

#include<iostream>
using namespace std;
//function to sort elements of array
void sort(int a[], int n)
{
int i,j,temp;
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
//function to search location of item using binary search
int binary_search(int a[],int n,int item)
{
int beg,end,mid;
beg=0;
end=n-1;
mid=(beg+end)/2;
while((beg<=end)&&(a[mid]!=item))
{
if(item<a[mid])
{
end=mid-1;
}
else
{
beg=mid+1;
}
mid=(beg+end)/2;
}
if(item==a[mid])
{
return mid;
}
else
{
return -1;
}
}
//function to calculate mean
float mean(int a[],int n)
{
int i;
float sum=0;
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
sum=sum/n;
return sum;
}
//main function declaration
int main()
{
int a[50],n,i,item,loc;
cout<<"Enter no. of elements you wants: ";
cin>>n;
cout<<"Enter "<<n<<"array elements:"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nThe size of the array entered by user is: "<<n<<endl;
cout<<"\nArray elements entered by user is:"<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
sort(a,n);
cout<<endl<<"\nAfter sorting array elements are:"<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
cout<<endl<<"\nEnter item to search: ";
cin>>item;
cout<<"\nThe integer being searched is: "<<item<<endl;
loc=binary_search(a,n,item);
if(loc==-1)
{
cout<<"\nSearch unsuccessfull";
}
else
{
cout<<"\nThe location of that integer in the sorted array is: "<<loc<<endl;
}
cout<<"\nThe mean of the data set is: "<<mean(a,n);
return 0;
}

 

for all the functions that are used write prototypes of them and they should be written after main. like the example below: 

Below is an example of a program where the function is written using prototypes:

void foo();

int main() {

foo();

}

void foo() {

cout <<This is an example where I have  a prototype above main and am implemented after main" << endl;

}

 

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Fundamentals of Multithreaded Algorithms
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education