Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume yy is a list of ints that looks like the following: yy = [1,3,5,7,9,11,13

ID: 3802039 • Letter: A

Question

Assume yy is a list of ints that looks like the following:
yy = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31]

Assume you have it defined in your ML environment.

Write an ML expression for each of the following. Assume yy is the original list for each problem.
1. Remove the first item of yy

2. Make a list containing only the first item of yy

3. Take 5 to the front of yy

4. Take [2,5] to the front of yy

5. Take [2,5] to the back of yy

6. Remove the first item of yy and take its double (that is, multiply it by 2) to the front of yy

7. Remove the third item in yy

8. Remove the second item of yy and take it on the front

9. Remove the third item of yy and take it on the back

Explanation / Answer

#include<iostream>
using namespace std;

int main()
{
//Creates an array with specified data
int yy [] = {1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31};
int count = 16, temp;
//Displays the original data
cout<<" Original: ";
//Loops till count
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
//Loops till count and push the array data to one position back
for(int x = 0; x < count; x++)
yy[x] = yy[x+1];
//Decrease the counter
count--;
cout<<" After Removing First Item: ";
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
cout<<" Make a list containing only the first item of yy: ";
//Creates a new array with the first element of the array yy
int zz[] = {yy[0]};
cout<<zz[0];
cout<<" After Taking 5 to the front of yy: ";
temp = yy[0];
yy[0] = yy[1];
yy[1] = temp;
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
cout<<" After Taking [2,5] to the front of yy: ";
temp = yy[0];
yy[0] = yy[2];
yy[2] = temp;
temp = yy[1];
yy[1] = yy[5];
yy[5] = temp;
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
cout<<" After Taking [2,5] to the back of yy: ";
temp = yy[count - 1];
yy[count - 1] = yy[2];
yy[2] = temp;
temp = yy[count - 2];
yy[count - 2] = yy[5];
yy[5] = temp;
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
cout<<" After Removing the first item of yy and take its double (that is, multiply it by 2) to the front of yy: ";
yy[0] = yy[0] * yy[0];
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
cout<<" After Removing the third item in yy: ";
for(int x = 2; x < count; x++)
yy[x] = yy[x+1];
count--;
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
cout<<" After Removing the second item of yy and take it on the front: ";
temp = yy[1];
yy[1] = yy[0];
yy[0] = temp;
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
cout<<" After Removing the third item of yy and take it on the back: ";
temp = yy[2];
yy[2] = yy[count - 1];
yy[count - 1] = temp;
for(int x = 0; x < count; x++)
cout<<yy[x]<<" ";
}//End of main

Output:

Original: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
After Removing First Item: 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
Make a list containing only the first item of yy: 3
After Taking 5 to the front of yy: 5 3 7 9 11 13 15 17 19 21 23 25 27 29 31
After Taking [2,5] to the front of yy: 7 13 5 9 11 3 15 17 19 21 23 25 27 29 31
After Taking [2,5] to the back of yy: 7 13 31 9 11 29 15 17 19 21 23 25 27 3 5
After Removing the first item of yy and take its double (that is, multiply it by 2) to the front of yy: 49 13 31 9 11 29 15 17 19 21 23 25 27 3 5
After Removing the third item in yy: 49 13 9 11 29 15 17 19 21 23 25 27 3 5
After Removing the second item of yy and take it on the front: 13 49 9 11 29 15 17 19 21 23 25 27 3 5
After Removing the third item of yy and take it on the back: 13 49 5 11 29 15 17 19 21 23 25 27 3 9

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote