in many applications, the order of the data items in a list changes over time. N
ID: 645160 • Letter: I
Question
in many applications, the order of the data items in a list changes over time. Not only are new data items added and existing ones removed, but data items are repositioned within the list. The following operation is needed to move a data item to the beginning of an array. Do not use a vector for this assignment.
Precondition: the array is not empty.
Postcondition: This function removes the data item marked by a cursor from an array and reinserts the data item at the beginning of the array.
A cursor is some indicator for the element to be moved. It may be an index number or a search key. For example, the function could take in the index number 4 to move the fifth element of the array to the front. Alternatively, the function could take in the search string "Joe" and if found in the array, that "Joe" element would be moved to the front. You can select the strategy you prefer for the cursor.
Minimum Requirements:
Create a class that has an array as a private data member. You cannot use a vector for this assignment (5 points).
You must include a function (member or non-member function) to fulfill the precondition and postcondition listed above (5 points).
Include a class function to add elements to the array (5 points).
You will also need a client program that creates an object of your class and calls the function(s) you created to meet the requirements of this project (5 points). please write in c++
Explanation / Answer
class A1()
{
private int arr[MAX];
void arrinput(int n)
{
for (int i =0; i<n; i++)
scanf("%d",&arr[i])
}
void precondition()
{
if arr[] = NULL return 0;
}
void postcondition(int input)
{
for (i = 0; i < n; i++)
arr[i + 1] = arr[i];
arr[0] = input;
}
int main()
{
A1 a;
a.arrinput(10);
a.precondition();
a.postcondition(6);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.