1. Draw a structured flowchart or write structured pseudocode describing how to get from your home to your school. Include at least two decisions and two loops.
2. Draw a structured flowchart and write pseudocode that describes the process of guessing a number between 1 and 100. After each guess, the player is told that the guess is too high or too low. The process continues until the player guesses the correct number. Pick a number and have a fellow student try to guess it following the instructions.
In: Computer Science
Java
Starter Code:
import java.util.Scanner; Sample Output: Team Scores by quarter: Team 2 has won the game! |
In: Computer Science
Create a website with html about raccons, just a simple html model to build off of including multiple pages including a home, about us, and learn more page. Text filler not needed. Just the html structure.
In: Computer Science
In this problem you will need to read about the functions numpy.load and numpy.bincount. Store all answers in appropriate variables. numbers = np.load('randomints.npy')
Use only numpy functionality to carry out this part.
(a) Load the file randomints.npy into a numpy array. There are 100000 integers in this file and they are between 0 and 1000.
(b) Get a bincount array for the array loaded in the first part.
(c) Let M be the largest number of times an element occurs in the array.
What is the smallest number that occurs M times?
(d) What is the number of integers that occurred 111 times?
In: Computer Science
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM] = {-4, 9, 11, 17, 19}; int result[2*NUM]; SortArrays(arrA, arrB, result, NUM); printArray(result, 2*NUM); return 0; } void SortArrays (int a[], int b[], int c[], int size) { } void printArray(int m[], int length) { for(int i = 0; i < length; i++) cout<< m[i]<<" "; cout<endl;
}
In: Computer Science
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.
(b) Generate the target output using one-hot encoding for both the training set and the test set.
(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 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 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 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
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 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
In: Computer Science
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 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