hi
i have assiment and i shuld Suppos to send it after a few hours.
the ass is
LAB1-2 Chap10
A) Write a function, removeAt, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, index). The function should delete the array element indicated by index. If index is out of range or the array is empty, output an appropriate message.
B) Write a function, removeAll, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, Item). The function should find and delete all of the occurrences of Item in the array.
NOTE: Use function removeAt in the function removeAll.
C) Write a main function to test your functions
>>>
my solution;
#include<iostream>
using namespace std;
void removeat(int list[],int &leanght,int index)
{
if(leanght==0)
{
cout<<"the array its empty";
else if (index<0 || index>leanght)
cout<<"out of range";
else
{
for (int j=index;j<leanght;j++)
list[j]=list[j+1];
leanght--;
}
}
void removeall(int list[],int &leanght,int item)
{
int loc;
for(int i=0;i<leanght;i++)
if(list[i]==item)
loc=removeat( list,leanght, i);
}
int main();
{
int pos;
int leanght=8;
int list[8]={2,3,5,5,5,4,8,9};
int item;
cout<<list[];
cout<<"enter item";
cin>>item;
pos=removeall( list,leanght, item)
return 0;
}
You should probably begin by reading the errors, referring to the source code and figuring out why.
cout<<list[];
You cannot print out an array in this fashion. You need to use a loop and print out each element in turn.
Your removeall() will fail on arrays where consecutive elements are equal to the item you're searching for.
removeall(() doesn't return a value so pos = removeall(...) doesn't make sense.
Obviously you found the format buttons on the right when you're editing or making a post. The one with <> on it should be used for code.
Saying "I don't know but there are many errors" isn't useful. If you can't understand the errors, list them with the code. Also, the subject is useless.
Is it only one thing you can take from a post? In addition to the code tags, coder777 pointed out you have a semi-colon where you shouldn't have one. Line 29.
Be precise and informative about your problem
•Describe the symptoms of your problem carefully and clearly.
•Describe the environment in which it occurs (machine, OS, application, whatever).
•Describe the research you did to try and understand the problem before you asked the question.
•Describe the diagnostic steps you took to try and pin down the problem yourself before you asked the question.
Do the best you can to anticipate the questions a respondent will ask, and answer them in advance in your request for help.
When asking about code
Don't ask others to debug your broken code without giving a hint what sort of problem they should be searching for.
Use meaningful, specific subject headers
The subject header is your golden opportunity to attract qualified experts' attention. Don't waste it on babble like 'Please help me' Don't try to impress us with the depth of your anguish; use the space for a super-concise problem description instead.
If you do not know how to change the code, you are not ready for programming. You have to type on the keyboard. It is astonishing that you can type how i change ? but you cannot type int main().