using namespace std;
class ArrayManipulation {private:int* arr;int size;
public:ArrayManipulation() {arr = nullptr;size = 0;}
};
int main() {int x;cout << "Enter x: ";cin >> x;
}
using namespace std;
class ArrayManipulation {
private:
int* arr;
int size;
public:
void createArray() {ArrayManipulation() {
arr = nullptr;
size = 0;
}
cout << "Enter Number of array elements: ";
cin >> size;
arr = new int[size];
cout << "Enter elements of array:" << endl;
for (int i = 0; i < size; i++)
cin >> arr[i];
}
void swapFirstAndLast(int x) {
if (x == arr[0]) {
int temp = arr[0];
arr[0] = arr[size - 1];
arr[size - 1] = temp;
cout << "Array after swapping first and last elements: ";
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
}
else
cout << "Error";
}
~ArrayManipulation() {
delete[] arr;
}
};
int main() {
ArrayManipulation obj;int x;
cout << "Enter x: ";
cin >> x;
obj.createArray();
obj.swapFirstAndLast(x);
return 0;
}