468,771 Members | 1,551 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

Main program call 3 functions:Insert,Delete & Search

14
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array.

Here is a description of the three functions:

Insert: Accepts as input the array and the element you want to insert into the array. The function should insert the element at the end of the array and should call the function Sort to sort the array.

Delete: Accepts as input the array and the element to delete. This function should call the function Search to find the element in the array. If it does not find the element, it should return false, otherwise, it should delete it and return true.

Search : This is a function of type Boolean. It should accept the array and an the element to look for. If it finds the element it should return true and the index where the element is in the array. Otherwise, it should return false.

Sort: Accepts as input the array and sorts it. Use one of the sorting techniques. ( insertion sort, quick sort…)

You should start with the following 10 elements in the array: 10,50,47,59,45,12,45,15,35,86.

In the main program, use a loop to enter this initial elements in the array. Then you should prompt the user for elements to add and delete from the array. If the operation to perform is add, add the element and print the resulting sorted array. If the operation to perform is delete, if the element is in the array, delete it and print the resulting array. If the element is not in the array, print a message "element no found".
If the operation is a search operation, if the element is found print a message stating that the element was found and give the index where the element was found otherwise, print "element not found.".
Nov 2 '06 #1
6 6067
flash
14
?????
????
???
Nov 4 '06 #2
flash
14
?Thanks for all because no body help me!!!
Nov 9 '06 #3
What do you have done so far? And what do you need help with, I mean what is your question specifically?
Nov 9 '06 #4
flash
14
This is my solution but not working well:

#include <iostream.h>

//functions prototype
void Insert(int[],int);
void Delete(int[],int);
int Search(int[],int);
void Sort(int[],int);

int n=0,i=0,location;
bool found;

//main
int main()
{

int grades[10],i,g;
for(i=0;i<4;i++){
cout<<"Enter a new grade ";
cin>>g;
Insert(grades,g);
//cout <<"grades["<<i<<"]="<<grades[i]<<endl;
} // end for loop

// functions definitions
Sort(grades,n);

//print out the values of the array
for(i=0;i<4;i++){
cout <<grades[i]<<endl;

}
Delete(grades,3);

/* for(i=0;i<3;i++){
cout <<grades[i]<<endl;

}
*/
return 0;
} // end main

// functions
void Insert(int a[],int item){
a[n]=item;
n++;
}

void Delete (int a[],int item){
Search(a,item);
if (found==true){
cout <<" out of search, found in place"<<location<<endl;
for (int k=location;k=3;k++){ //////here is to check//////
a[k]=a[k+1];
}
}
else
cout <<"not found!!";


}// end delete

int Search(int a[],int item){
// Assumption: Whenever it finds the value, it stops
for (int i=0;i<n;i++){
if (a[i]==item){
found=true;
cout <<"inside seearch,found in place "<<i<<endl;
location= i;
return location;
}
else
found=false;

}
}//end of search

void Sort(int a[], int length)
{
int count,SI, MI,temp;
for(count = 0;count<length-1;count++)
{
MI = count;
for(SI = count + 1; SI <length; SI++)
if(a[SI] < a[MI]) MI = SI;

// swap the grades
temp = a[MI];
a[MI] = a[count];
a[count] = temp;
}

} // end of sort
Nov 9 '06 #5
flash
14
who can help please ??
Nov 11 '06 #6
first, use code tags. second please identify the problem you are having with your current solution, and I'll try to help you debug it.
Nov 11 '06 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by john smith | last post: by
2 posts views Thread by Frank Schmitt | last post: by
3 posts views Thread by Paul Reddin | last post: by
4 posts views Thread by Bob Day | last post: by
2 posts views Thread by babaco | last post: by
5 posts views Thread by beginner | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.