I am getting this error in following program.What is wrong in this?
task_constructor.cpp:18:7: error: expected unqualified-id before ‘delete’
task_constructor.cpp:49:1: error: expected ‘}’ at end of input
task_constructor.cpp:17:2: error: expected unqualified-id at end of input
//Following program asks the user to enter 5 elements , store them in a dta member of class array
//it then asks the user to enter the position from where he wants to remove the element,
//Then it removes the element and display the result.
#include<iostream>
usingnamespace std;
class array
{
int arr[5],n;
public:
array()
{n=5;}
array(int *element)
{
n=5;
for(int i=0;i<5;i++)
arr[i]=*(element+i);
}
voiddelete(int position)
{
n=4;
while(position<5)
{
arr[position]=arr[position+1];
position++;
}
}
void display()
{
for(int i=0;i<n;i++)
cout<<a[i];
cout<<endl;
}
};
int main()
{
int arr1[5];
int position;
cout<<"Enter 5 elements to be inserted into an array: ";
for(i=0;i<5;i++)
cin>>arr1[i];
array a1(arr);
cout<<"Elements entered by you are: \n";
a1.display();
cout<<"Enter the position from where you want to remove the element: ";
cin>>position;
a1.delete(position);
a1.display();
return 0;
}
Line 18: delete is a reserved word.
Line 30: a is not defined. You need to pass it as an argument.
Line 39: Loop variable i is not defined.
Line 41: arr is not defined. Did you mean arr1?