so i need help trying to get the sequential search to where i need to have .
The function return the index where key is found or return -1 if not found and display a message if found or if not found
The numbers in the array are 80 32 20 16 10
=============
1: fill the array
2: print the array
3: calculate the average
4: show the highest number
5: double each number
6: selection sort in descending order
7: sequential search
8: show bar graph
9: quit
=============
Enter your choice:7
#include<iomanip>
#include<iostream>
usingnamespace std;
constint SIZE=5;
void fillArray(int ar[]);
void printArray(constint ar[]);
double findAvgArray(constint ar[]);
int checkHighestArray(constint ar[]);
void doubleNumArray(int ar[],int s);
void sortArray(int ar[],int s);
bool sequeSearch(constint ar[],int s,int k);
void showBarGraph(int ar[]);
int main()
{
// const int SIZE=5;
int ar[SIZE];
//fillArray[ar];
int choice;
int k;
do{
cout<<"==================="<<endl;
cout<<"1:Fill the array"<<endl;
cout<<"2:Print the array"<<endl;
cout<<"3:Calculate the average"<<endl;
cout<<"4:Show the highest Number"<<endl;
cout<<"5:Double each number"<<endl;
cout<<"6:sort in descending order"<<endl;
cout<<"7:Sequential Search"<<endl;
cout<<"8:Show Bar Graph"<<endl;
cout<<"9:Quit"<<endl;
cout<<"==================="<<endl;
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1: fillArray(ar);
break;
case 2: printArray(ar);
break;
case 3:findAvgArray(ar);
break;
case 4:cout<<"Highest number is "<<checkHighestArray(ar);
break;
case 5:doubleNumArray((ar),SIZE);
break;
case 6:sortArray((ar),SIZE);
break;
case 7:cout<<"Enter the Key: ";
cin>>k;
sequeSearch((ar),SIZE,k);
break;
case 8: showBarGraph(ar);
break;
case 9: cout<<"Thank you for using our System."<<endl;
break;
default:cout<<"Invalid choice"<<endl;
break;
}
}while(choice!=9);
// fillArray(ar);
//printArray(ar);
return 0;
}
void fillArray(int ar[])
{
for(int i=0;i<SIZE;i++)
{
cout<<"Enter a number ";
cin>>ar[i];
}
cout<<endl;
}
void printArray(constint ar[])
{
cout<<"The numbers in the array are ";
for(int i=0;i<SIZE;i++)
cout<<ar[i]<<" ";
cout<<endl;
}
double findAvgArray(constint ar[])
{
cout<<"The average number is ";
double total=0;
for(int i=0;i<SIZE;i++)
total +=ar[i];
total=total/SIZE;
cout<<total<<endl;
return total;
}
int checkHighestArray(constint ar[])
{
int highestNumber=0;
for(int i=1;i<SIZE;i++)
if(ar[i]>ar[highestNumber])
highestNumber=i;
return ar[highestNumber];
//cout<<"The highest number is "<<highestNumber<<endl;
//return ar[highestNumber];
}
void doubleNumArray(int ar[],int s)
{
int temp;
//cout<<"The numbers in the array doubled are ";
for(int i=0;i<SIZE;i++)
temp=ar[i]*2;
cout<<endl;
}
void sortArray(int ar[],int s)
{
int smallIndx;
int temp;
for(int last=SIZE-1; last>=1; last--)
{
smallIndx =0;
for(int i= 1; i<=last; i++)
{
if(ar[i] < ar[smallIndx])
smallIndx= i;
}
temp=ar[smallIndx];
ar[smallIndx]= ar[last];
ar[last]=temp;
}
// cout<<"All entries in the array have been sorted."<<endl;
cout<<endl;
}
bool sequeSearch(constint ar[],int s, int k)
{
int temp=0;
for(int i=0;i<s;i++)
{
if(ar[i]==k)
{
temp=1;
break;
}
}
}
void showBarGraph(int ar[])
{
for (int c=0;c<SIZE;c++)
{
cout<<"Slot "<<c+1<<" : ";
for(int f=0;f<ar[c];f++)
{
cout<<"*";
}
cout<<endl;
}
}
as well need help with bar graph to display like this mine isnt correct anything helps thank you
The numbers in the array are 20 16 32 80 10
=============
1: fill the array
2: print the array
3: calculate the average
4: show the highest number
5: double each
number
6: selection sort in descending order
7: sequential search
8: show bar graph
9: quit
=============
Enter your choice:
8
Slot 0: **
Slot 1: *
Slot 2: ***
Slot 3: ********
Slot 4: *
it doesnt display how i want it when i run it shows
The numbers in the array are 20 16 32 80 10
===================
1:Fill the array
2:Print the array
3:Calculate the average
4:Show the highest Number
5:Double each number
6:sort in descending order
7:Sequential Search
8:Show Bar Graph
9:Quit
===================
Enter your choice: 8
Slot 1 : ********************
Slot 2 : ****************
Slot 3 : ********************************
Slot 4 : ********************************************************************************
Slot 5 : **********
this is how it should be
Slot 1 : **
Slot 2 : *
Slot 3 : ***
Slot 4 : ********
Slot 5 : *
===================
so it displays the first number only
===================
1:Fill the array
2:Print the array
3:Calculate the average
4:Show the highest Number
5:Double each number
6:sort in descending order
7:Sequential Search
8:Show Bar Graph
9:Quit
===================
Enter your choice: 1
Enter a number 20
Enter a number 16
Enter a number 32
Enter a number 80
Enter a number 10
===================
1:Fill the array
2:Print the array
3:Calculate the average
4:Show the highest Number
5:Double each number
6:sort in descending order
7:Sequential Search
8:Show Bar Graph
9:Quit
===================
Enter your choice: 8
Slot 1 : ********************
Slot 2 : ****************
Slot 3 : ********************************
Slot 4 : ********************************************************************************
Slot 5 : **********
===================
so here is an example of what it should display
The numbers in the array are 10 8 16 40 5
=============
1: fill the array
2: print the array
3: calculate the average
4: show the highest number
5: double each number
6: selection sort in descending order
7: sequential search
8: show bar
graph
9: quit
=============
Enter your choice:
8
Slot 0: *
Slot 1:
Slot 2: *
Slot 3: ****
Slot 4:
so it displays the first number only
bool sequeSearch(constint ar[], int s, int k)
{
int temp=0;
for(int i=0;i<s;i++)
{
if(ar[i]==k)
{
temp=1;
break;
}
}
if(temp != 0)
{
cout << k << " was found at index " << i + 1 << endl;
}
return (temp == 1);
}