Questions
Write a single python file to perform the following tasks: (a) Get dataset “from sklearn.datasets import...

Write a single python file to perform the following tasks:

(a) Get dataset “from sklearn.datasets import load_iris”. Split the dataset into two sets: 20% of samples for training, and 80% of samples for testing.

NOTE 1: Please use “from sklearn.model_selection import train_test_split” with “random_state=N” and “test_size=0.80”.
NOTE 2: The offset/bias column is not needed here for augmenting the input features.

  1. (b) Generate the target output using one-hot encoding for both the training set and the test set.

  2. (c) Using the same training and test sets generated above, perform a polynomial regression (utilizing “from sklearn.preprocessing import PolynomialFeatures”) from orders 1 to 10 (adopting the weight-decay L2 regularization with regularization factor λ=0.0001) for classification (based on the

    one-hot encoding) and compute the number of training and test samples that are classified correctly.

NOTE 1: The offset/bias augmentation will be automatically generated by PolynomialFeatures. NOTE 2: If the number of rows in the training polynomial matrix is less than or equal to the number of

columns, then use the dual form of ridge regression (Lecture 6). If not, use the primal form (Lecture 6).

Submit a single python file with filename “A2_StudentMatriculationNumber.py”. It should contain a function A2_MatricNumber that takes in an integer “N” as input and returns the following outputs in the following order:

  • X_train: training numpy feature matrix with dimensions (number_of_training_samples ⨯ 4). (1%)

  • X_test: test numpy feature matrix with dimensions (number_of_test_samples ⨯ 4). (1%)

  • y_train: training target numpy array (containing values 0, 1 and 2) of length

    number_of_training_samples. (1%)

  • y_test: test target numpy array (containing values 0, 1 and 2) of length number_of_test_samples. (1%)

  • Ytr: one-hot encoded training target numpy matrix (containing only values 0 and 1) with dimension

    (number_of_training_samples ⨯ 3). (1%)

  • Yts: one-hot encoded test target numpy matrix (containing only values 0 and 1) with dimension

    (number_of_test_samples ⨯ 3). (1%)

  • Ptrain_list: list of training polynomial matrices for orders 1 to 10. Ptrain_list[0] should be polynomial

    matrices for order 1 (size number_of_training_samples x 5), Ptrain_list[1] should be polynomial matrices for

    order2(sizenumber_of_training_samplesx15),etc. (1.5%)

  • Ptest_list: list of test polynomial matrices for orders 1 to 10. Ptest_list[0] should be polynomial

    matrices for order 1, Ptest_list[1] should be polynomial matrices for order 2, etc. (1.5%)

  • w_list: list of estimated regression coefficients for orders 1 to 10. w_list[0] should be estimated regression

    coefficients for order 1, w_list[1] should be estimated regression coefficients for order 2, etc. (2%)

  • error_train_array: numpy array of training error counts (error count = number of samples classified incorrectly) for orders 1 to 10. error_train_array[0] is error count for polynomial order 1, error_train_array[1]

    is error count for polynomial order 2, etc. (2%)

  • error_test_array: numpy array of test error counts (error count = number of samples classified

    incorrectly) for orders 1 to 10. error_test_array[0] is error count for polynomial order 1, error_test_array[1] is error count for polynomial order 2, etc. (2%)

    Please use the python template provided to you. Remember to rename both “A2_StudentMatriculationNumber.py” and “A2_MatricNumber” using your student matriculation number. For example, if your matriculation ID is A1234567R, then you should submit “A2_A1234567R.py” that contains the function “A2_A1234567R”. Please do NOT zip/compress your file. Because of the large class size, points will be deducted if instructions are not followed. The way we would run your code might be something like this:

    >> import A2_A1234567R as grading
    >> N = 10
    >> X_train, X_test, y_train, y_test, Ytr, Yts, Ptrain_list, Ptest_list, w_list, error_train_array, error_test_array = grading.A2_A1234567R(N)

In: Computer Science

Java Write a method that counts how many times one string appears in another string. The...

Java

Write a method that counts how many times one string appears in another string. The method takes three input parameters: two Strings and one Boolean. The Boolean value determines whether the words are allowed to overlap each other. For example:

When the method is called with input parameters (“balloon”, “oo”, false), it returns 1.

When the method is called with input parameters (“hh”, “hhhhhh”, true) returns 5.

When the method is called with input parameters (“cc”, “abcdefg”, true), returns 0.

In: Computer Science

Write a Fortran program that reads in two NxN matrices A & B, and prints their...

Write a Fortran program that reads in two NxN matrices A & B, and prints their element-wise sum (A+B), element-wise difference (A-B), element-wise division (A/B), element-wise product (A*B), and their matrix product (matmul(A,B)), on the standard output.

In: Computer Science

the following question is based on the table information below. Assume that the data is populated...

the following question is based on the table information below.

Assume that the data is populated with records: CREATE TABLE teachers ( emp_id bigserial, first_name varchar(25), last_name varchar(50), school varchar(50), hire_date date, salary numeric); SELECT first_name, last_name, school, salary FROM teachers WHERE hiredate > '2008-01-01' ORDER BY last_name ASC;

Question 1) Will this query return an error?

Question 2) If there is an error, what is causing the error? if there is not an error, leave blank.

In: Computer Science

Bubble sort for 12, 2, 3, 21, 11, 10,8

Bubble sort for 12, 2, 3, 21, 11, 10,8

In: Computer Science

QUESTION 1 Answer the following questions about corrections in Population Models. Question: When you use the...

QUESTION 1 Answer the following questions about corrections in Population Models. Question: When you use the “floor(x)” command, you are doing what? (Select the BEST answer) rounding up dividing by a factor which determines the nutation of the answer truncating off the decimal/fractional portion of the number resetting the format command

a .rounding up

b .dividing by a factor which determines the nutation of the answer

c .truncating off the decimal/fractional portion of the number

d .resetting the format command

Question 2

Question:  In a Population Model problem which uses monthly time periods, the population at the end of a month is the same as the population before the start of the next month?

True or False

Question 3

Write a MATLAB code to find the number of values between 120 & 230 (inclusive) that are odd and multiples of either 11 or 13.

Store the answers as a single vector “m” with the first number you find meeting the criteria in location m(1), the second number in m(2), and so on. Then display the resulting “m” vector.

Use Matlab

3. A. enter the number of values that your code found between 120 & 230 that are odd and multiples of 11 or 13.

In: Computer Science

This assignment introduces the concept of dynamic memory allocation, destructors, copy constructors, and overloading the assignment...

This assignment introduces the concept of dynamic memory allocation, destructors, copy constructors, and overloading the assignment operator, , and also provides some insight into how the C++ string class works.

Assignment

In this assignment, you will create a class to represent a string of characters. You can think of this class as a simplified version of the C++ string class.

Program

You will need to write one class for this assignment. A main program to test your class has been provided.

The NIUString class

The NIUString class represents a string of characters. You can think of it as a "wrapper" we can put around an array of char that provides additional functionality (like the ability to assign one string to another, compare strings using the relational operators, etc.). Like the other classes we've written this semester, this class should be implemented as two separate files.

The class declaration should be placed in a header file called NIUString.h. Include header guards to prevent it from accidentally being #included more than once in the same source code file.

Data Members

The NIUString class should contain the following private data members:

a pointer to a char. I'll refer to this data member as the string array pointer. It will be used to dynamically allocate an array of char (the string array).

an unsigned integer or size_t variable used to keep track of the number of elements in the string array. I'll refer to this data member as the string capacity.

an unsigned integer or size_t variable used to store the current length of the C string stored in the string array. I'll refer to this data member as the string size. The string size must always be less than or equal to the string capacity.

In addition to the changes to the data members described above, your class declaration will need prototypes for methods described below.

Methods

The implementations of the class methods should be placed in a separate source code file called NIUString.cpp. Make sure to #include "NIUString.h" at the top of this file.

The NIUString class should have the following methods (most of which are quite small):

NIUString::NIUString()

This "default" constructor for the NIUString class should initialize a new NIUString object to an empty string with a capacity of 0. The required logic is:

< >Set the string size for the new object to 0.

Set the string capacity for the new object to 0.

Set the string array pointer for the new object to the special value nullptr.

NIUString::NIUString(const char* other)

This constructor for the NIUString class should initialize a new NIUString object to the C string other. The required logic is:

< >Set the string size for the new object to the length of the C string other.

Set the string capacity for the new object to the string size.

If the string capacity is 0, set the string array pointer for the new object to nullptr. Otherwise, use the string array pointer for the new object to allocate an array of char. The number of elements in the new string array should be equal to the string capacity.

Copy the characters of the C string other (up to, but not including the null character) into the string array.

NIUString::NIUString(const NIUString& other)

This "copy constructor" for the NIUString class should initialize a new NIUString object to the same string as the existing NIUString object other. The required logic is:

< >Set the string size for the new object to the string size of other.

Set the string capacity for the new object to the string capacity of other.

If the string capacity is 0, set the string array pointer for the new object to nullptr. Otherwise, use the string array pointer for the new object to allocate an array of char. The number of elements in the new string array should be equal to the string capacity.

Copy the contents of the string array of other into the string array of the new object. If other has a string size of 0, this loop will exit immediately.

NIUString::~NIUString()

The destructor for the NIUString class can simply call the clear() method described below.

NIUString& NIUString::operator=(const NIUString& other)

This overloaded assignment operator should assign one NIUString object (the object other) to another (the object that called the method, which is pointed to by this). The required logic is:

< >Check for self-assignment. If the address stored in the pointer this is the same as the address of the object other, then skip to the final step.

Delete the string array for the object pointed to by this.

Set the string size for the object pointed to by this to the string size of other.

Set the string capacity for the object pointed to by this to the string capacity of other.

If the string capacity is 0, set the string array pointer for the object pointed to by this to nullptr. Otherwise, use the string array pointer to allocate an array of char. The number of elements in the new string array should be equal to the string capacity.

Copy the contents of the string array of other into the string array of the object pointed to by this.

Return *this.

NIUString& NIUString::operator=(const char* other)

This overloaded assignment operator should assign a C string (the string other) to an NIUString object (the object that called the method, which is pointed to by this). The required logic is:

< >Delete the string array.

Set the string size for the object pointed to by this to the length of the C string other.

Set the string capacity for the object pointed to by this to the string size.

If the string capacity is 0, set the string array pointer for the object pointed to by this to nullptr. Otherwise, use the string array pointer to allocate an array of char. The number of elements in the new string array should be equal to the string capacity.

Copy the contents of the C string other (up to, but not including the null character) into the string array of the object pointed to by this.

Return *this.

size_t NIUString::capacity() const

This method should return the string capacity.

size_t NIUString::size() const

This method should return the string size.

bool NIUString::empty() const

This method should return true if the string size is 0. Otherwise, it should return false.

void NIUString::clear()

This method should set the string size and string capacity to 0. It should should then use the delete[] operator to delete the string array. Finally, the string array pointer should be set to nullptr.

void NIUString::reserve(size_t n)

This method modifies an object's string capacity without changing its size or the contents of the string array. The required logic is:

< >If n is less than the string size or n is equal to the current string capacity, simply return.

Set the string capacity to n.

Declare a temporary array pointer (a pointer to a char).

If the string capacity is 0, set the temporary array pointer to nullptr. Otherwise, use the temporary array pointer to allocate an array of char. The number of elements in the new temporary array should be equal to the string capacity.

Copy the contents of the string array into the temporary array.

Delete the string array.

Set the string array pointer to the temporary array pointer.

bool NIUString::operator==(const NIUString& rhs) const

This method should return true if the characters stored in the string array of the object that called the method are identical to the characters stored in the string array of the NIUString object passed in as rhs.

The logic for this method is less difficult that it might initially appear to be. The first step is to compare the string sizes of the two strings. If they are different, return false (two strings of different lengths can not be equal).

Otherwise, loop through the elements of both string arrays, starting at 0 and stopping when you reach the string size. (The size of which string doesn't matter, since you know they're the same by this point.) Compare the current element from each string array. If characters are different, return false. If the characters are the same, don't return true; do nothing and let the loop continue.

Once the loop ends and you've reached the end of both strings, return true.

bool NIUString::operator==(const char* rhs) const

This method should return true if the characters stored in the string array of the object that called the method are identical to the characters of the C string passed in as rhs (up to, but not including the null character).

The logic for this method is similar to that of the previous method.

const char& NIUString::operator[](size_t pos) const

This method should return element pos of the string array.

char& NIUString::operator[](size_t pos)

This method should return element pos of the string array.

In addition to the methods described above, you will need to write a couple of standalone functions. These functions are not (and can not be) methods. You should

Include a friend declaration for each of these functions in the NIUString class definition.

Put the definitions for these functions in NIUString.cpp.

ostream& operator<<(ostream& lhs, const NIUString& rhs)

This method should loop through the characters of the string array of the NIUString object passed in as rhs and print them one at a time using the stream object passed in as lhs.

bool operator==(const char* lhs, const NIUString& rhs)

This method should return true if the characters of the C string passed in as lhs (up to, but not including the null character) are identical to the characters stored in the string array of the NIUString object passed in as rhs.

The logic for this function is similar to that of the two relational operator methods.

Driver Program

A short main program to test your class is given below. Either type in this program or copy it to your UNIX account from the pathname ~t90kjm1/CS241/Code/Spring2017/Assign5/assign5.cpp.

/*********************************************************************
   PROGRAM:    CSCI 241 Assignment 5
   PROGRAMMER: your name
   LOGON ID:   your z-ID
   DUE DATE:   due date of assignment

   FUNCTION:   This program tests the functionality of the NIUString
               class.
*********************************************************************/  

#include <iostream>
#include "NIUString.h"

using std::cout;
using std::endl;

int main()
   {
   cout << "Testing default constructor\n\n";

   const NIUString s1;
   
   cout << "s1: " << s1 << endl;   
   cout << "s1 size: " << s1.size() << endl;
   cout << "s1 capacity: " << s1.capacity() << endl;
   cout << "s1 is " << ((s1.empty()) ? "empty\n" : "not empty\n");
   cout << endl;
   
   cout << "Testing second constructor\n\n";
   
   NIUString s2 = "some text";
   
   cout << "s2: " << s2 << endl;   
   cout << "s2 size: " << s2.size() << endl;
   cout << "s2 capacity: " << s2.capacity() << endl;
   cout << "s2 is " << ((s2.empty()) ? "empty\n" : "not empty\n");
   cout << endl;
   
   cout << "Testing second constructor with long string\n\n";
   
   NIUString s3 = "This is a really long string, but all of it will still end up in the array - pretty neat, huh?";
   
   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;

   cout << "Testing write form of subscript operator\n\n";
   
   s2[0] = 'S';
   s2[5] = 'T';
   cout << "s2: " << s2 << endl << endl;
      
   cout << "Testing read form of subscript operator\n\n";
   
   cout << "s2: ";
   for (size_t i = 0; i < s2.size(); i++)
      cout << s2[i];
   cout << endl << endl;

   cout << "Testing reserve() method\n\n";

   s2.reserve(9);

   cout << "s2: " << s2 << endl;   
   cout << "s2 size: " << s2.size() << endl;
   cout << "s2 capacity: " << s2.capacity() << endl;
   cout << "s2 is " << ((s2.empty()) ? "empty\n" : "not empty\n");
   cout << endl;
 
   s2.reserve(30);

   cout << "s2: " << s2 << endl;   
   cout << "s2 size: " << s2.size() << endl;
   cout << "s2 capacity: " << s2.capacity() << endl;
   cout << "s2 is " << ((s2.empty()) ? "empty\n" : "not empty\n");
   cout << endl;
 
   s2.reserve(15);

   cout << "s2: " << s2 << endl;   
   cout << "s2 size: " << s2.size() << endl;
   cout << "s2 capacity: " << s2.capacity() << endl;
   cout << "s2 is " << ((s2.empty()) ? "empty\n" : "not empty\n");
   cout << endl;
 
   s3.reserve(10);
  
   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << "s3 is " << ((s3.empty()) ? "empty\n" : "not empty\n");
   cout << endl;

   cout << "Testing equality operators\n\n";

   const NIUString s4 = "Some Text";
   
   cout << "s2 and s4 are " << ((s2 == s4) ? "equal\n" : "not equal\n");
   cout << "s3 and s4 are " << ((s3 == s4) ? "equal\n" : "not equal\n\n");
   
   cout << "s4 and \"Some Text\" are " << ((s4 == "Some Text") ? "equal\n" : "not equal\n");
   cout << "s4 and \"More Text\" are " << ((s4 == "More Text") ? "equal\n" : "not equal\n\n");
   
   cout << "\"Some Text\" and s4 are " << (("Some Text" == s4) ? "equal\n" : "not equal\n");
   cout << "\"More Text\" and s4 are " << (("More Text" == s4) ? "equal\n" : "not equal\n\n");

   cout << "Testing clear() method\n\n";

   s3.clear();
   
   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << "s3 is " << ((s3.empty()) ? "empty\n" : "not empty\n");
   cout << endl;

   cout << "Testing copy constructor\n\n";
   
   NIUString s5(s4);
   
   cout << "s5: " << s5 << endl;   
   cout << "s5 size: " << s5.size() << endl;
   cout << "s5 capacity: " << s5.capacity() << endl;
   cout << endl;

   cout << "Testing assignment operator\n\n";
   
   s3 = s5;

   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;

   s3 = "a different string";

   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;

   cout << "Testing self-assignment\n\n";

   s3 = s3;

   cout << "s3: " << s3 << endl;   
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;

   cout << "Testing chained assignment\n\n";

   s3 = s2 = "Hello, world";

   cout << "s2: " << s2 << endl;
   cout << "s2 size: " << s2.size() << endl;
   cout << "s2 capacity: " << s2.capacity() << endl;
   cout << endl;

   cout << "s3: " << s3 << endl;
   cout << "s3 size: " << s3.size() << endl;
   cout << "s3 capacity: " << s3.capacity() << endl;
   cout << endl;

   //
   // Extra Credit
   //
   // This code will call the move constructor and move assignment
   // operator if they exist.
   //
   // If those move semantics methods are not implemented, this code
   // will call the copy constructor and copy assignment operator
   // instead. The output will be different in that case.
   //
   cout << "Extra Credit: Testing move constructor\n\n";

   NIUString s6 = std::move(s5);

   cout << "s6: " << s6 << endl;
   cout << "s6 size: " << s6.size() << endl;
   cout << "s6 capacity: " << s6.capacity() << endl;
   cout << "s6 is " << ((s6.empty()) ? "empty\n" : "not empty\n");
   cout << endl;

   cout << "s5: " << s5 << endl;
   cout << "s5 size: " << s5.size() << endl;
   cout << "s5 capacity: " << s5.capacity() << endl;
   cout << "s5 is " << ((s5.empty()) ? "empty\n" : "not empty\n");
   cout << endl;

   cout << "Extra Credit: Testing move assignment operator\n\n";

   s5 = std::move(s6);

   cout << "s5: " << s5 << endl;
   cout << "s5 size: " << s5.size() << endl;
   cout << "s5 capacity: " << s5.capacity() << endl;
   cout << "s5 is " << ((s5.empty()) ? "empty\n" : "not empty\n");
   cout << endl;

   cout << "s6: " << s6 << endl;
   cout << "s6 size: " << s6.size() << endl;
   cout << "s6 capacity: " << s6.capacity() << endl;
   cout << "s6 is " << ((s6.empty()) ? "empty\n" : "not empty\n");

   return 0;
   }

In: Computer Science

selection sort for 12, 2, 3, 21, 11, 10,8

selection sort for 12, 2, 3, 21, 11, 10,8

In: Computer Science

The world today is more connected than ever. Research the impacts of always on connectivity has...

The world today is more connected than ever. Research the impacts of always on connectivity has on today’s culture. What ways Is being connected to everyone always good for society and what harm does it have on that same society. Does this trend look to be getting better or worse as we work our way further into the 21st century?

course: fundamentals of mobile application developement.
Answer the question in 500 words or more. Be sure to cover each part in your answer.

In: Computer Science

How would you best define Parallelism? In a 500-word paper describe describe parallelism and the different...

How would you best define Parallelism? In a 500-word paper describe describe parallelism and the different types of parallelism. Your answer should include the following:


What Parallelism is and means.


Define what events are and name a few examples.


What is meant when we say Parallelism can be involved on several levels? Give some examples of these levels.


In: Computer Science

Why use parallelism? In a 500-word paper, define the ways of measuring speed of computers, and...

Why use parallelism? In a 500-word paper, define the ways of measuring speed of computers, and discuss how parallelism is used in super- computing. Include in your answer:


The ways we can measure speed.


Examples of super-computing and how it is being used.


In: Computer Science

This code is an expression of cp command in c language. But I don't understand this...

This code is an expression of cp command in c language. But I don't understand this code very well. Please explain in notes one by one.

#define SIZE 1024

#include<string.h>
#include<stdio.h>
#include<sys/types.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/stat.h>


int main(int argc, char *argv[]){

if(argc != 3){
perror("argument 부족\n");
exit(0);
}

struct stat frstatbuf;
FILE* fr = fopen(argv[1], "r");

if(fr == NULL){
perror("read file 읽기 오류\n");
exit(0);
}

int frfd = fileno(fr);

fstat(frfd, &frstatbuf);

FILE* fw=fopen(argv[2], "w+");

int fwfd=fileno(fw);

fchmod(fwfd,frstatbuf.st_mode&(S_IRWXU|S_IRWXG|S_IRWXO));

char buf[1024];

while(1){
int n=fread(buf,sizeof(char),SIZE,fr);

if(n<SIZE){
fwrite(buf,sizeof(char),n,fw);

printf("파일을 다 읽었음\n");
exit(0);
}
fwrite(buf,sizeof(char),n,fw);
}

fclose(fr);
fclose(fw);
return 0;
}

In: Computer Science

Create the logic for a program that stores 5 names in an array. Your program will...

Create the logic for a program that stores 5 names in an array.

Your program will then ask the user which name (s)he wants to search. The program receives the name to be searched as input and searches the array for the name entered.

If the name is one of the names in the array, display the message "Name found.". Otherwise, display the message "Name not found.".

in pseudocode please in python

In: Computer Science

STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...

STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int -*mySet: myType -MAX_VALUE = 500000 static const: int -LIMIT = 1000 static const: int +recursionSet() +recursionSet(const recursionSet&) +~recursionSet() +getSetLength() const: int +generateElements(int): void + getElement(int) const: myType +setElement(int, myType): void +readValue(const string) const: int +printSet() const: void +operator == (const recusrionSet&): bool +tak(myType, myType, myType) const: myType +printSeptenary(myType) const: void +squareRoot(myType, myType) const: myType -recSqRoot(myType, myType, myType) const: myType +recursiveSum() const: myType -rSum(int) const: myType +checkParentheses(string) const: bool -recChkPar(string, int, int) const: bool +recursiveInsertionSort(): void -recInsSort(int, int): void -insertInOrder(myType, int, int): voidYou may add additional private functions if needed (but, not for the recursive functions). Note, points will be deducted for especially poor style or inefficient coding. Function Descriptions • The recursionSet() constructor should set the length to 0 and mySet pointer to NULL. • The recusrsionSet(const recursionBucket&) copy constructor should create a new, deep copy from the passed object. • The ~recursionSet() destructor should delete the myType array, set the pointer to NULL, and set the size to 0. • The setElement(int, myValue) function should set an element in the class array at the given index location (over-writing any previous value). The function must include bounds checking. If an illegal index is provided, a error message should be displayed. • The getElement(int) should get and return an element from the passed index. This must include bounds checking. If an illegal index is provided, a error message should be displayed and a 0 returned. • The getSetLength() functions should return the current class array length. • The printSet(int) function should print the formatted class array with the passed number of values per line. Use the following output statement: cout << setw(5) << mySet[i] << " • "; Refer to the sample executions for formatting example. The readValue(string) function should prompt with the passed string and read a number from the user. The function should ensure that the value is 3 1 and £ MAX_VALUE. The function should handle invalid input (via a try/catch block). If an error occurs (out of range or invalid input) an appropriate message should be displayed and the user re- prompted. Example error messages include: cout << "readSetLenth: Sorry, too many " << "errors." << endl; cout << "readSetLenth: Error, value " << cnt << " not between 1 and " << numMax << "." << endl; • Note, three errors is acceptable, but a fourth error should end the function and return 0. The generateList(int) function should dynamically create the array and use the following casting for rand() to fill the array with random values. mySet[i] = static_cast(rand()%LIMIT); • • • The printSeptenary(myType) function should print the passed numeric argument in Septenary (base-7) format. Note, function must be written recursively. The recursiveSum() function will perform a recursive summation of the values in class data set and return the final sum. The function will call the private rSum(int) function (which is recursive). The rSum(int) function accepts the length of the data set and performs a recursive summation. The recursive summation is performed as follows: rSum ( position )= • { array[ 0] array[ position ] + rSum ( position−1) if position = 0 if position > 0 The tak(myType) function should recursively compute the Tak 1 function. The Tak function is defined as follows: tak ( x , y , z) = { z tak ( tak ( x−1, y , z) , tak ( y−1, z , x) , tak ( z −1, x , y ) ) 1 For more information, refer to: http://en.wikipedia.org/wiki/Tak_(function) if y≥ x if y < x• • The squareRoot(myType, myType) function will perform a recursive estimation of the square root of the passed value (first parameter) to the passed tolerance (second parameter). The function will call the private sqRoot(myType,myType,myType) function (which is recursive). The private recSqRoot(myType,myType,myType) function recursively determines an estimated square root. Assuming initially that a = x, the square root estimate can be determined as follows: recSqRoot ( x , a , epsilon) = • • • • • { 2 if ∣ a − x ∣ ≤ epsilon a 2 (a + x) sqRoot x , , epsilon 2 a ( ) if ∣ a 2 − x ∣ > epsilon The recursiveInsertionSort() function should sort the data set array using a recursive insertion sort. The recursiveInsertionSort() function should verify the length is valid and, if so, call the recInsSort() function to perform the recursive sorting (with the first element at 0 and the last element at length-1). The recInsSort(int, int) function should implement the recursive insertion sort. The arguments are the index of the first element and the index of the last element. If the first index is less than that last index, the recursive insertion sort algorithm is follows: ▪ Recursively sort all but the last element (i.e., last-1) ▪ Insert the last element in sorted order from first through last positions To support the insertion of the last element, the insertInOrder() function should be used. The insertInOrder(myType, int, int) function should recursively insert the passed element into the correction position. The arguments are the element, the starting index and the ending index (in that order). The function has 3 operations: ▪ If the element is greater than or equal to the last element in the sorted list (i.e., from first to last). If so, insert the element at the end of the sorted (i.e, mySet[last+1] = element). ▪ If the first is less than the last, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and continue the insertion by recursively calling the insertInOrder() function with the element, first, and last-1 values. ▪ Otherwise, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and set the last value (i.e., mySet[last]) to the passed element. The checkParentheses(string) function should determine if the parentheses in a passed string are correctly balanced. The function should call the private recChkPar(string, int, int) function (which is recursive) The recChkPar(string, int, int) function should determine if the parentheses in a string are correctly balanced. The arguments are the string, an index (initially 0), and a parenthesis level count (initially 0). The index is used to track the current character in the string. The general approach should be as follows: ◦ Identify base case or cases. ◦ Check the current character (i.e., index) for the following use cases: ▪ if str[index] == '(' → what to do then ▪ if str[index] == ')' → what to do then ▪ if str[index] == any other character → what to do then Note, for each case, increment the index and call function recursively.

In: Computer Science

STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...

STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int -*mySet: myType -MAX_VALUE = 500000 static const: int -LIMIT = 1000 static const: int +recursionSet() +recursionSet(const recursionSet&) +~recursionSet() +getSetLength() const: int +generateElements(int): void + getElement(int) const: myType +setElement(int, myType): void +readValue(const string) const: int +printSet() const: void +operator == (const recusrionSet&): bool +tak(myType, myType, myType) const: myType +printSeptenary(myType) const: void +squareRoot(myType, myType) const: myType -recSqRoot(myType, myType, myType) const: myType +recursiveSum() const: myType -rSum(int) const: myType +checkParentheses(string) const: bool -recChkPar(string, int, int) const: bool +recursiveInsertionSort(): void -recInsSort(int, int): void -insertInOrder(myType, int, int): voidYou may add additional private functions if needed (but, not for the recursive functions). Note, points will be deducted for especially poor style or inefficient coding. Function Descriptions • The recursionSet() constructor should set the length to 0 and mySet pointer to NULL. • The recusrsionSet(const recursionBucket&) copy constructor should create a new, deep copy from the passed object. • The ~recursionSet() destructor should delete the myType array, set the pointer to NULL, and set the size to 0. • The setElement(int, myValue) function should set an element in the class array at the given index location (over-writing any previous value). The function must include bounds checking. If an illegal index is provided, a error message should be displayed. • The getElement(int) should get and return an element from the passed index. This must include bounds checking. If an illegal index is provided, a error message should be displayed and a 0 returned. • The getSetLength() functions should return the current class array length. • The printSet(int) function should print the formatted class array with the passed number of values per line. Use the following output statement: cout << setw(5) << mySet[i] << " • "; Refer to the sample executions for formatting example. The readValue(string) function should prompt with the passed string and read a number from the user. The function should ensure that the value is 3 1 and £ MAX_VALUE. The function should handle invalid input (via a try/catch block). If an error occurs (out of range or invalid input) an appropriate message should be displayed and the user re- prompted. Example error messages include: cout << "readSetLenth: Sorry, too many " << "errors." << endl; cout << "readSetLenth: Error, value " << cnt << " not between 1 and " << numMax << "." << endl; • Note, three errors is acceptable, but a fourth error should end the function and return 0. The generateList(int) function should dynamically create the array and use the following casting for rand() to fill the array with random values. mySet[i] = static_cast(rand()%LIMIT); • • • The printSeptenary(myType) function should print the passed numeric argument in Septenary (base-7) format. Note, function must be written recursively. The recursiveSum() function will perform a recursive summation of the values in class data set and return the final sum. The function will call the private rSum(int) function (which is recursive). The rSum(int) function accepts the length of the data set and performs a recursive summation. The recursive summation is performed as follows: rSum ( position )= • { array[ 0] array[ position ] + rSum ( position−1) if position = 0 if position > 0 The tak(myType) function should recursively compute the Tak 1 function. The Tak function is defined as follows: tak ( x , y , z) = { z tak ( tak ( x−1, y , z) , tak ( y−1, z , x) , tak ( z −1, x , y ) ) 1 For more information, refer to: http://en.wikipedia.org/wiki/Tak_(function) if y≥ x if y < x• • The squareRoot(myType, myType) function will perform a recursive estimation of the square root of the passed value (first parameter) to the passed tolerance (second parameter). The function will call the private sqRoot(myType,myType,myType) function (which is recursive). The private recSqRoot(myType,myType,myType) function recursively determines an estimated square root. Assuming initially that a = x, the square root estimate can be determined as follows: recSqRoot ( x , a , epsilon) = • • • • • { 2 if ∣ a − x ∣ ≤ epsilon a 2 (a + x) sqRoot x , , epsilon 2 a ( ) if ∣ a 2 − x ∣ > epsilon The recursiveInsertionSort() function should sort the data set array using a recursive insertion sort. The recursiveInsertionSort() function should verify the length is valid and, if so, call the recInsSort() function to perform the recursive sorting (with the first element at 0 and the last element at length-1). The recInsSort(int, int) function should implement the recursive insertion sort. The arguments are the index of the first element and the index of the last element. If the first index is less than that last index, the recursive insertion sort algorithm is follows: ▪ Recursively sort all but the last element (i.e., last-1) ▪ Insert the last element in sorted order from first through last positions To support the insertion of the last element, the insertInOrder() function should be used. The insertInOrder(myType, int, int) function should recursively insert the passed element into the correction position. The arguments are the element, the starting index and the ending index (in that order). The function has 3 operations: ▪ If the element is greater than or equal to the last element in the sorted list (i.e., from first to last). If so, insert the element at the end of the sorted (i.e, mySet[last+1] = element). ▪ If the first is less than the last, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and continue the insertion by recursively calling the insertInOrder() function with the element, first, and last-1 values. ▪ Otherwise, insert the last element (i.e., mySet[last]) at the end of the sorted (i.e., mySet[last+1] = mySet[last]) and set the last value (i.e., mySet[last]) to the passed element. The checkParentheses(string) function should determine if the parentheses in a passed string are correctly balanced. The function should call the private recChkPar(string, int, int) function (which is recursive) The recChkPar(string, int, int) function should determine if the parentheses in a string are correctly balanced. The arguments are the string, an index (initially 0), and a parenthesis level count (initially 0). The index is used to track the current character in the string. The general approach should be as follows: ◦ Identify base case or cases. ◦ Check the current character (i.e., index) for the following use cases: ▪ if str[index] == '(' → what to do then ▪ if str[index] == ')' → what to do then ▪ if str[index] == any other character → what to do then Note, for each case, increment the index and call function recursively.

In: Computer Science