#include<iostream>
using namespace std;
void output(int a[], int s);
void oddsum(int a[], int s);
void evensum(int a[], int s);
void search(int a[], int s);
void highest(int a[],int s);
void lowest(int a[], int s);
void bubble(int a[], int s);
void firstele(int a[]);
void lastele(int a[], int s);
void middle(int a[],int s);
void sum(int a[],int s);
int main() {
int a[1000],n,choice,i;
/*a is the array woth 1000 memory location, n for number of
elemebts and choicr for choice entering*/
cout<<"Ente Array ";
cin>>n;
cout<<"Enter the numbers:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
/*for reading array elements in each of the i'th position.*/
do {
cout<<"\n\nMENU";
cout<<"\n1. Output all Integer values";
cout<<"\n2. Sum of all Odd numbers:"; cout<<"\n3. Sum
of all even numbers:";
cout<<"\n4. Enter a search value:";
cout<<"\n5. Output the highest number:";
cout<<"\n6. Output the lowest number:";
cout<<"\n7. Bubble Sort:";
cout<<"\n8. Output the first element in the Array:";
cout<<"\n9. Output the last element in the Array:";
cout<<"\n10. Output the Middle number in the Array";
cout<<"\n11. Output the sum of all numbers in the
Array:";
cout<<"\n12. Exit";
//these are menu items
cout<<"\n\nEnter your choice 1-12:"; cin>>choice;
//reading choice from 1-12
switch(choice)
{
case 1:
output(a,n);
/*if 1 is entered then call output method*/
break;
case 2:oddsum(a,n); break;
/*choice entered is 2 means calling oddsum()*/
case 3: evensum(a,n); break;
/*3 for calling evensum()*/
case 4: search(a,n); break;
/* 4 option is for calling search a number method*/
case 5: highest(a,n); break;
/*5 for highest()*/
case 6:
lowest(a,n);
/*calling lowest()*/
break;
case 7:bubble(a,n); break;
/*bubblesort*/
case 8: firstele(a); break;
case 9: lastele(a,n); break;
case 10: middle(a,n); break;
case 11: sum(a,n);break;
case 12:break;
default:cout<<"\nInvalid choice";
}
}while(choice!=12);
/*if choice is equal to 12, then exit from the switch*/
return 0;
}
void output(int a[], int s)
{
cout<<"Entered elements are:";
for(int i=0;i<s;i++)
{
cout<<a[i];
}
/*printing elements from each podition of the i'th element in array
a*/
}
void oddsum(int a[], int s)
{
int sum=0;
cout<<"The sum of all odd numbers in the
array are:\n";
for(int i=0;i<s;i++)
{
if(a[i]%2!=0)
{
sum=sum+a[i];
}
/*a[i]%2 gives the reminder if it is not equal to
zero, then odd num add to sum*/
}
cout<<"Sum of odd numbers="<<sum;
}
void search(int a[],int s)
{
int num,count=0;
cout<<"enter the element that you want to
search:";
cin>>num;
for(int i=0;i<s;i++)
{
if(a[i]==num)
{
count=1;
cout<<"element present in the array with
position"<<i+1;
break;
}
}
/* this function search an element, if a[i] is equal to num then
present int the Arrray"*/
if (count==0)
cout<<"element not present in the array";
}
void evensum(int a[], int s)
{
int sum=0;
cout<<"The sum of all odd numbers in the
array are:\n";
for(int i=0;i<s;i++)
{
if(a[i]%2==0)
{
sum=sum+a[i];
}
}
cout<<"Sum of even numbers="<<sum;
}
void highest(int a[], int s)
{
int max;
for(int i=0;i<s;i++)
{
for(int j=i+1;j<s;j++)
{
if(a[i]>a[j])
{
max=a[i];
}
}
/*this function compares each element, with other then
find highest value*/
}
cout<<"Highest number=" << max;
}
void lowest(int a[], int s)
{
int min=a[0];
for(int i=0;i<s;i++)
{
for(int j=i+1;j<s;j++)
{
if(a[i]<a[j])
{
min=a[i];
}
}
/* compares and find lowest value*/
}
cout<<"lowest number="<<min;
}
void bubble(int a[],int s)
{
int i,j,temp;
for(i=0;i<s-1;i++)
{
for(j=0;j<(s-1-i);j++)
{
if(a[j]>a[j+1])
{
temp=a[j]; //swapping
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
void firstele(int a[])
{
cout<<"The first element in the array is:
"<<a[0];
//first element is in a[0]th position
}
void lastele(int a[],int n)
{
cout<<"The last element in the array is:
"<<a[n-1];
//last element is in n-1th position
}
void middle(int a[],int n)
{
int m=n/2;
cout<<"The middle element in the array is:
"<<a[m];
//m contains the minddle value
}
void sum(int a[],int n)
{
int s=0;
for(int i=0;i<n;i++)
{
s=s+a[i];
}
cout<<"The sum of the array is:
"<<s;
/*s calculates the sum of each a[i]
value*/
}
Task 1: Hardcode the algorithm == Write the loops and if statements necessary for an algorithm....