By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

Main program call 3 functions:Insert,Delete & Search

P: 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
Share this Question
Share on Google+
6 Replies

P: 14
Nov 4 '06 #2

P: 14
?Thanks for all because no body help me!!!
Nov 9 '06 #3

P: 8
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

P: 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;

int main()

int grades[10],i,g;
cout<<"Enter a new grade ";
//cout <<"grades["<<i<<"]="<<grades[i]<<endl;
} // end for loop

// functions definitions

//print out the values of the array
cout <<grades[i]<<endl;


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

return 0;
} // end main

// functions
void Insert(int a[],int item){

void Delete (int a[],int item){
if (found==true){
cout <<" out of search, found in place"<<location<<endl;
for (int k=location;k=3;k++){ //////here is to check//////
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){
cout <<"inside seearch,found in place "<<i<<endl;
location= i;
return location;

}//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

P: 14
who can help please ??
Nov 11 '06 #6

P: 8
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.