JavaScript
Write a function called "first" that takes in two arguments - the first is an argument called arr that is an array of numbers, the second is an optional number argument called num(hint: you'll need a default value - look back at the slides).
If "num" was not passed in (since it's optional), the "first" function will return an array containing the first item of the array.
If a value for "num" was given, the "first" function will return an array containing the first "num" values of the array.
See the example output below.
console.log(first([7, 9, 0, -2])); // [7] console.log(first([], 3)); // [undefined, undefined, undefined] console.log(first([7, 9, 0, -2], 3)); // [7, 9, 0] console.log(first([7, 9, 0, -2], 6)); // [7, 9, 0, -2, undefined, undefined]
In: Computer Science
USING MATLAB
Where indicated in the script below, write a function, called
myflip, which accepts one vector v (either a column or a row) and
outputs the same vector v of the same dimensions, but with the
values in reverse order (use MATLAB function flip()). In other
words, v will be overwritten by its flipped version. In your
function, you may only use length() and floor(). You only need one
loop.
%this code tests the function, myflip, which you will write below
v1 = 100*rand(1);
v1 = myflip(v1)
n = randi([2 100], 1, 1);
v2 = 100*rand(1,2*n);
v2 = myflip(v2)
n = randi([2 100], 1, 1);
v3 = 100*rand(2*n+1,1);
v3 = myflip(v3)
In: Computer Science
I. General Description In this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike assignment 5, the Student objects are sorted before they are written to the output file.
• The program must implement a main class, three student classes (Student, UndergradStudent, GradStudent), and a Comparator class called StudentIDComparator.
• The StudentIDComparator class must implement the java.util.Comparator interface, and override the compare() method. Since the Comparator interface is a generic interface, you must specify Student as the concrete type. The signature of the compare method should be public int compare(Student s1, Student s2). The compare() method returns a negative, 0, or positive value if s1 is less than, equals, or is greater than s2, respectively.
• To sort the ArrayList, you need to create a StudentIDComparator object and use it in the Collections’ sort method: StudentIDComparator idSorter = new StudentIDComparator(); Collections.sort(students, idSorter); //students is an arrayList of Students
Heres student.txt
James Bond,200304,3.2,undergraduate,true Michelle Chang,200224,3.3,graduate,Cleveland State University Tayer Smoke,249843,2.4,undergraduate,false David Jones,265334,2.7,undergraduate,true Abby Wasch,294830,3.6,graduate,West Virginia Nancy Drew,244833,2.9,graduate,Case Western Lady Gaga,230940,3.1,undergraduate,false Sam Jackson,215443,3.9,graduate,Ohio State University
He said you would need aorund 5 classes
In: Computer Science
4.What is the purpose of padding, Message Authentication Code (MAC), handshake protocol, change cyber suite (CCS) protocol?
5.How does TLS provide: confidentiality, availability, integrity, non-repudiation?
6.Is TCP a user of TLS services or does it provide services to TLS (hard question) – explain your answer in one sentence?
7.Does TLS use sequence numbers?
8.Sequence numbers can be used to launch replay attacks (as in TCP).How does TLS protect against replay attacks?
In: Computer Science
Write a java program calls the following methods:
a. printStars(): Takes an int (n) as parameter and prints n stars (*) using for loop.
ex.
6
******
In: Computer Science
In: Computer Science
Why does pumping strings in a CFL changes two parts of the string simultaneously?
In: Computer Science
is an operation of selecting a process that is to be serviced by the CPU.
a. Overlaying
b. Replacement
c. Paging
d. Scheduling
In: Computer Science
Python Question:
Write a function that checks to see if an array of integers is sorted in an increasing fashion, returning true if it is, false otherwise. Test it with at least4 arrays - 2 sorted and 2 not sorted. Use a CSV formatted input file as described in the previous question to run your program through some tests, where again the filename is passed as an argument.
Heres what I have so far:
import sys
# command line arguement 1. a csv file that contained rows of numbers to be tested.
file_name = sys.argv[1]
file = open(file_name)
# function that will check the csv file and see if the rows of numbers are sorted in an increasing pattern.
def is_sorted(arr):
_result = []
for i in range(len(arr) - 1):
if current_arr[i] > current_arr[i+1]:
return False
return True
# Read the file line by line
for line in file.readlines():
# For each line read,
# We create a new array to:
# Store the number we convert from strings,
current_arr = []
# Split the current line by commas,
for number in line.split(','):
# then convert each string in an array to an integer and
# then add it to the current array of numbers
current_arr += [int(number)]
when I order numbers in my csv file not sorted, I still get True returned instead of False
found_index = is_sorted(current_arr)
print(found_index)
In: Computer Science
2 algorithms for Prefix Averages, one that ran in
big-Oh n2 time and a
second that ran in big-Oh n time. Code up methods for both
algorithms. Show through different
input examples and using the Current Time method call how the
polynomial time algorithm runs
slower than the linear time version. Use system.out.println
statement to show your results.
please who can help with this question In Java
Thank you
In: Computer Science
Enter the network address of the subnet to which the host 222.242.88.128/28 belongs.
Please show work.
In: Computer Science
Enter the first usable host on the network 12.48.105.97 255.255.252.0.
Please show work.
In: Computer Science
What subnet mask would you use for the 178.32.0.0 network, such that you can get 50 subnets and 1000 hosts per subnet?
Please show work.
In: Computer Science
programming in python
Design a program that initializes a list of 5 items to zero (use repetition operator). It then updates that list with a series of 5 random numbers. The program should find and display the following data:
-The lowest number in the list
- Average of the numbers stored in the list
In: Computer Science
Is L={xcx | x∈{a,b}∗} a CFL? If so what does it's PDA look like and if not what about its proof?
In: Computer Science