In: Computer Science
I'm looking for a program, written in vPython, that simulates the movement of a spherical mass, suspended from a ceiling, tied to a spring. We are supposed to take the gravitaional force into account but are allowed to ignore the effects of air-resistance (for now).
I am a newbie at vPython so comments within the program to explain what certain parts of the code do would be appreciated!
In: Computer Science
An increasing-order integer array may contain duplicate elements. Write a Java method that does a binary search through the array for finding a specific target and return an array of two integer indices that specifies the close interval of indices at which the target is found or null if the target is not present. Use this test driver to test
public class MultBS
{
int [] multBinarySearch(int [] x, int target)
{
// your codes go here
}
public static void main(String [] args)
{ int [] x = new int[]{2,3,3,4,4,4,5,6,7,7,7};
int [] range = multBinarySearch(x, 3);
System.out.println("Target was found from position " + range[0] + " to " + range[1]);
}
}
test your program to make sure you see
the printout is
"Target was found from position 1 to 2"
In: Computer Science
I have the following code:
//Set.java
import java.util.ArrayList;
public class Set<T> {
//data fields
private ArrayList<T> myList;
// constructors
Set(){
myList = new ArrayList<T>();
}
// other methods
public void add(T item){
if(!membership(item))
myList.add(item);
}
public void remove(T item){
if(membership(item))
myList.remove(item);
}
public Boolean membership(T item){
for (T t : myList)
if (t.equals(item))
return true;
return false;
}
public String toString(){
StringBuilder str = new StringBuilder("[ ");
for(int i = 0; i < myList.size() - 1; i++)
str.append(myList.get(i).toString()).append(", ");
if(myList.size() > 0)
str.append(myList.get(myList.size() - 1).toString());
str.append(" ]");
return str.toString();
}
}
(20 points) Fill the following table with the big-O running times of each of the methods implemented, as well as the running times for the same methods if they were implemented with LinkedList instead. (No need to explain here, only the big-O expression.)
| Array List | Linked List | |
| add | ||
| remove | ||
| membership | ||
| toString |
(20 points) Explain each of the eight running times in the table applying the rules of counting seen in class, and for the method calls, if 4 we have covered them already, directly refer to the running times of those methods. (Partial credit if you do not explain all eight. No points for ambiguous explanations. For instance, if you implement add in the class Set using addFirst in the class ArrayList, then you should say something like the following. “The add method of Set is implemented with just one method call to addFirst of ArrayList. addFirst of ArrayList is in O(n) in the worst case. Hence, the same bound on the running time applies to add”. )
In: Computer Science
Suppose a function receives a pointer as an argument. Explain how this function is declared within its calling function. In particular, explain how the data type of the pointer argument is represented. C++
In: Computer Science
What are the application and uses of Telemedicine?
In: Computer Science
please give complete code in python using def function thank you!
Validate Credit Card Numbers
Credit card numbers can be quickly validated by the Luhn checksum algorithm.
For instance, Ned Flander's credit card number is 8525.4941.2525.4158.
Here are the digits with checksum underlined:
8525494125254158_
Here are the digits doubled back:
16 5 4 5 8 9 8 1 4 5 4 5 8 1 10 8_
Here are the two-digit results subtracted nine:
7 5 4 5 8 9 8 1 4 5 4 5 8 1 1 8_
Here is the sum:
7+5+4+5+8+9+8+1+4+5+4+5+8+1+1+8=83
Here is the modulo 10 result: 83%10=3 and this is not a valid credit card number.
Compose a function luhn which correctly validates a given candidate 16-digit credit-card number (as a numeric input in int).
In: Computer Science
hi! I have this code. when I run it, it works but in
the print(the number we are searching for is ) it prints the number
twice. ex. for 5 it prints 55 etc. apart from this, it
works
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int n,i;
printf("Give me the size of the table : \n");
scanf("%d", &n);
int A[n],x,y;
for (i=0;i<n;i++)
A[i]=rand() % n;
for (i=0;i<n;i++)
printf("%d\n", A[i]);
srand(time(NULL));
y=rand()% n ;
printf("The number we are searching for is %d", y);
for (i=0;i<n;i++)
{
if (A[i]==y)
{
printf("%d is present at location
%d.\n", y,i+1);
break;
}
}
if (i == n)
printf("%d isn't present in the array.\n",
y);
return 0;
}
In: Computer Science
hours = 40;
status= True;
overtime = False
What is the value of each of the following Boolean expressions? [4 marks]
In: Computer Science
Rewrite the following Matlab code so it does the same thing but
with complete new variable names and structure.
function stump = stumpGenerator(dataX, dataY, Dt)
intervals = 100;
rangex1 = max(dataX(:,1)) - min(dataX(:,1));
rangex2 = max(dataX(:,2)) - min(dataX(:,2));
width = (rangex1/intervals);
height = (rangex2/intervals);
starterx1 = min(dataX(:,1)) - (width/2);
starterx2 = min(dataX(:,2)) - (height/2);
currepsilon = inf;
stump = [0,0,0,1,0,0];
for i = 1:(intervals + 1)
horzRightError = sum(Dt(find(((dataX(:,1) - starterx1) .* dataY)
< 0)));
horzLeftError = sum(Dt(find(((dataX(:,1) - starterx1) .* dataY)
> 0)));
vertUpError = sum(Dt(find(((dataX(:,2) - starterx2) .* dataY) <
0)));
vertDownError = sum(Dt(find(((dataX(:,2) - starterx2) .* dataY)
> 0)));
if (horzRightError <= horzLeftError)
horzError = horzRightError;
else
horzError = -horzLeftError;
end
if (vertUpError <= vertDownError)
vertError = vertUpError;
else
vertError = -vertDownError;
end
if (abs(horzError) <= abs(vertError))
if (currepsilon > abs(horzError))
currepsilon = abs(horzError);
stump(1) = 1;
stump(2) = 0;
stump(3) = starterx1;
stump(4) = horzError/(abs(horzError));
stump(5) = (log((1 - currepsilon)/currepsilon))/2;
stump(6) = currepsilon;
else
% do nothing, we already have the best stump
end
else
if (currepsilon > abs(vertError))
currepsilon = abs(vertError);
stump(1) = 0;
stump(2) = 1;
stump(3) = starterx2;
stump(4) = vertError/(abs(vertError));
stump(5) = (log((1/currepsilon) - 1))/2;
stump(6) = currepsilon;
else
% do nothing, we already have the best stump
end
end
starterx1 = starterx1 + width;
starterx2 = starterx2 + height;
end
end
In: Computer Science
Are the following languages regular languages or not ? Justify your answer with a proof.
In: Computer Science
In: Computer Science
Discuss cabling and what you would use for a smaller Mom and Pop type business. Define the business and how you would set up a network and what hardware and connection mechanisms need to be in place. How many computers would be needed? What other information do you need? (employees, locations, size, etc.)
In: Computer Science
What are the benefits and disadvantages of each of the following? Consider both the system level and programmer level.
In: Computer Science
Write a python source code for a Unit class corresponding to the UML model of a Unit shown. The description method should return a string value corresponding to the attributes of a Movie.
|
Unit |
|
-code: String -name: String -credit points: int |
|
+ __init__ (self, code, name, credit_points) + description (): String |
In: Computer Science