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

The first 25 exercises should all have one-line solutions using map, foldr, or f

ID: 3811973 • Letter: T

Question

The first 25 exercises should all have one-line solutions using map, foldr, or foldl. You can also use other predefined functions, of course, but do not write any additional name functions and do not use explicit recursion. If you need helper functions, use anonymous ones. for example, if the problem says "write a function add2 that takes an int list and returns the same list with 2 added to every element," you answer should be fun add2 x = map ( fn a = > a + 2 ) x;

Exercise 2 Write a fnction ordlist of type char list - > int list that takes a list of characters and returns the list of the integer codes of those characters. for example, if you evaulate ordlist [#"A", #"b", #"C"] you should get [ 65, 98, 67 ]

Explanation / Answer

Solution for Exercise 2 (C++):-

Program :-

#include<iostream>
#include<string>
using namespace std;
int* ordlist(string str1)
{
int *arr,len=str1.length();
for(int i=0;i<len;i++)
{
arr[i]=(int)str1[i];
}
return arr;
}
int main()
{
string str;
cin>>str;
int* arra=ordlist(str);
for(int i=0;i<str.length();i++)
cout<<arra[i]<<" ";
return 0;
}

Output :-

AbcGA
65 98 99 71 65

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