473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 6391
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

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

Similar topics

2
by: john smith | last post by:
Hi, when there is a vector<> of pointers to some objects, does calling resize cause vector to call delete on each object, or is there a memory leak problem? for example: struct base {//some...
2
by: Frank Schmitt | last post by:
Hi! Suppose I have a class template Foo with a member function template bar - so far so good: template <typename T> struct Foo { template <typename U> void bar(const U& u); };
3
by: Paul Reddin | last post by:
Hi, V8.1 fp4a We have been performing some performance measurements on SQL functions and have observed the following and need to verify if this is expected behaviour. Our SQL Functions...
7
by: PaulR | last post by:
Hi, We have several inter-related SQL Table Functions, which all optimise fine on their own and most of the time together. However, increasingly as we are adding logic and making their logic...
5
by: TS | last post by:
From my presentation layer, I call a validation method in my business layer that i pass a custom class to that holds all parameters. I am currently also passing an error message by reference so...
4
by: Bob Day | last post by:
Using VS 2003, VB.Net, MSDE... The example below from help shows that the Sub Main contains an explicit Application.Run. Is this required? Are there pros and cons of doing it this way? I have...
2
by: babaco | last post by:
Hi, I've come upon a situation where I don't understand what's happening. Basically, I'm implementing a kind of 'chain of responsibility' using some covariant types: #include <iostream>...
8
by: gtb | last post by:
The lines if __name__ == 'main': someClass().fn() appear at the end of many examples I see. Is this to cause a .class file to be generated? The last line of the sample below has a string...
5
by: beginner | last post by:
Hi All, It is really convenient to use nested functions and lambda expressions. What I'd like to know is if Python compiles fn_inner() only once and change the binding of v every time fn_outer()...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.