Write the following ML functions: DONT USE F FOR Write a function that takes two
ID: 3599840 • Letter: W
Question
Write the following ML functions: DONT USE F FOR
Write a function that takes two lists as parameter and deletes from the front of the first list as many elements as there are in the second list. If the first list is shorter than the second list, return nil.
Sample Run:
- dels([2,5,1,8], [4,3]); // there are 2 elements in the second list, so delete 2 elements
// from the first list
val it = [1,8] : int list
- dels([2,5], [4,5,3]); // first list is shorter so return nil
val it = [] : int list
Assuming that an int list contains the digits of an integer, write a function which takes this list as a parameter as well as an integer which is a power of 10. The function should return a list which contains the digits of their product.
Sample Run:
- mult([5,3,2],1000); // multiply 532 by 1000
val it = [5,3,2,0,0,0] : int list
Note: Write only one function for each part, and do not call any other functions
Explanation / Answer
class String {
public:
String (); //Empty string
String (char); //Stirng('x')
String (const char[]); //String("abcd")
char& operator[] (int); //Accessor/Modifier
char operator[] (int) const; //Accessor
int capacity () const; //Max chars that can be stored (not including null terminator)
int length () const; //Number of char in string
String operator+ (const String&) const; //Concatenation
String& operator+= (String); //Concatenation
bool operator== (const String&) const;
bool operator< (const String&) const;
String substr (int, int) const;
int findch (int, char) const;
int findstr (int, const String&) const;
friend std::istream& operator>>(std::istream&, String&);
friend std::ostream& operator<<(std::ostream&, const String&);
private:
char str[STRING_SIZE];
};
String operator+ (const char[], const String&);
String operator+ (char, const String&);
bool operator== (const char[], const String&);
bool operator== (char, const String&);
bool operator< (const char[], const String&);
bool operator< (char, const String&);
bool operator<= (const String&, const String&);
bool operator!= (const String&, const String&);
bool operator>= (const String&, const String&);
bool operator> (const String&, const String&);
#endif
Makefile
###############################################################
# String & Oracle
#
# CS II Kent State University
# Make file for string class and testing oracle
# J. Maletic Fall 2017
#
#
###############################################################
# Variables
CPP = clang++
OPTIONS = -g -Wall -W -Wunused -Wuninitialized -Wshadow -std=c++11
# Names of your test files - add them in as you build them.
# Names must start with "test_"
MYTESTS = test_default_ctor test_c_str_ctor
#test_ctor_charArray
# Names of test files (include or exclude ones you don't want) testoracle_split
CTOR = testoracle_ctor_default testoracle_ctor_char testoracle_ctor_charArray
REL = testoracle_equal testoracle_lessThan
COPY = testoracle_ctor_copy testoracle_assign testoracle_ctor_charArray_int testoracle_ctor_int testoracle_swap_assign
OPS = testoracle_concat testoracle_subscript testoracle_len_cap testoracle_input testoracle_find_char testoracle_find_string testoracle_substring
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.