1) What steps can you take to ensure that code changes made to your dependencies will not impact your code?
2) Describe the process of mocking and give some examples of scenarios where it might be used. How does this help us?
In: Computer Science
Since images are two dimensional arrays of pixels, and we can represent a pixel as a one-dimensional list of three integers, we can represent an image as a three dimensional matrix (that is, a list of lists of lists) of integers in Python. In the following problems, you will be manipulating matrices of this format in order to alter image files in various ways.
Part 4: Edge Detection Filter
We want to highlight pixels that are significantly brighter (in at least one of the color components) than their surrounding pixels. A sudden shift in brightness like this is bound to occur along any sharp visible edge. To accomplish this, we’ll take each pixel, multiply its color values by 8, and then subtract the color values of the 8 pixels that surround it on the grid. Pixels that are very similar to their surrounding pixels will then end up with a color close to black, since 8 times the color component of that pixel minus the color components of its 8 neighbors should end up around 0.
This means that for a pixel located at (x,y) in the original image with original red color value r(x,y), you can compute the red component for the pixel the new image r’(x,y) with the following formula:
r’(x,y) = 8*r(x,y) - r(x-1,y-1) - r(x,y-1) - r(x+1,y-1) - r(x-1,y) - r(x+1,y) - r(x-1,y+1) - r(x,y+1) - r(x+1,y+1)
A similar formula applies for the green and blue components. Note that this may produce a value that is above the maximum color component value of 255: if this occurs then you should just set the value to 255. Similarly, if the formula generates a negative number, just set the value to 0.
For pixels along the boundaries of the picture that do not have 8 neighbors, ignore the formula and set their pixel values to black ([0, 0, 0]), to avoid the issue of going out of bounds.
Constraints:
Do not import/use any Python modules except for copy (see part C hints)
Do not change the function names or arguments.
Your submission should have no code outside of the function definitions (comments are fine).
You are permitted to write helper functions outside of the ones provided in the template..
Examples:
edge_detect([[[0,0,10], [0,0,20], [0,0,30], [0,0,200]],
[[255,120,20], [70,120,30], [0,120,40], [0,0,60]],
[[0,120,30], [255,120,40], [0,120,60], [0,120,50]],
[[255,120,40], [255,120,60], [255,120,50], [255,120,40]]])
Output:
[[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]],
[[0, 0, 0], [50, 255, 0], [0, 255, 0], [0, 0, 0]],
[[0, 0, 0], [255, 0, 0], [0, 120, 110], [0, 0, 0]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]]
In: Computer Science
Write a C++ or Java code that does similar swap action:
def swap (Lst, indexA, indexB) :
t = Lst[indexA]
Lst[indexA] = Lst[indexB]
Lst[indexB] = t
L = [1,2,3,4,5,6,7,8,9,10]
i=3
j=7
print(L[i], L[j])
swap(L,i,j)
print(L[i],L[j])
In: Computer Science
I have code for an AVL tree. I Have have a node class and tree class. I need a node object that refrences the root(top) of the tree. my current code throws NullPointerException when I try to access the root properties. here is the important snippets of my code, it is in java.
public class Node {
private Node left=null,right=null;
public int height=1;
private String Item;
private int balance=0;
Node(String item) {
this.Item=item; }
}
--------------------------------------------------
public class AVLTree {
public Node root;
public AVLTree(){
root=null;
}
public void insert(String str){
AVLTree t = new AVLTree();
root.setItem(str);
root=t.insert(root,str);
}
public void delete(String str){
AVLTree t = new AVLTree();
root.setItem(str);
t.deleteNode(root,str);
}
private Node insert(Node node, String str) {
deleteNode(node, str);
if (node == null) {
return(new Node(str));
}
if (str.compareTo(node.getItem()) <1)
node.setLeft(insert(node.getLeft(),str));
else
node.setRight(insert(node.getRight(),str));
node.height = Math.max(height(node.getLeft()), height(node.getRight())) + 1;
int balance = getBalanceNode(node);
if (balance > 1 && str.compareTo(node.getLeft().getItem())<1)
return rightRotate(node);
if (balance < -1 && str.compareTo(node.getRight().getItem())>1)
return leftRotate(node);
if (balance > 1 && str.compareTo(node.getLeft().getItem())>1)
{
node.setLeft(leftRotate(node.getLeft()));
return rightRotate(node);
}
if (balance < -1 &&str.compareTo(node.getRight().getItem())<1)
{
node.setRight(rightRotate(node.getRight()));
return leftRotate(node);
}
return node;
}
private Node deleteNode(Node node, String str) {
if (node == null)
return node;
if (str.compareTo(node.getItem())<1)
node.setLeft(deleteNode(node.getLeft(),str));
else if( str.compareTo(node.getItem())>1)
node.setRight(deleteNode(node.getRight(),str));
else {
if( (node.getLeft() == null) || (node.getRight() == null) ) {
Node temp;
if (node.getLeft() != null)
temp = node.getLeft();
else
temp = node.getRight();
if(temp == null) {
temp = node;
node = null;
}
else
node = temp;
temp = null;
}
else {
Node temp = minValueNode(node.getRight());
node.setItem(temp.getItem());
node.setRight(deleteNode(node.getRight(),temp.getItem()));
}
}
if (node == null)
return node;
node.height = Math.max(height(node.getLeft()), height(node.getRight())) + 1;
int balance = getBalanceNode(node);
if (balance > 1 && getBalanceNode(node.getLeft()) >= 0)
return rightRotate(node);
if (balance > 1 && getBalanceNode(node.getLeft()) < 0) {
node.setLeft(leftRotate(node.getLeft()));
return rightRotate(node);
}
// Right Right Case
if (balance < -1 && getBalanceNode(node.getRight()) <= 0)
return leftRotate(node);
// Right Left Case
if (balance < -1 && getBalanceNode(node.getRight()) > 0) {
node.setRight(rightRotate(node.getRight()));
return leftRotate(node);
}
return node;
}}
In: Computer Science
Conduct an internet search on how to build a web portal ?
no copy subject e- portals development
In: Computer Science
Write a Java function to swap two integers.
In: Computer Science
What would the output be for the following program code segment?
#define ROWS 3
#define COLS 3
void addCoulmns(int arr[][COLS],int Sum[COLS]);
int main(void)
{
int array[ROWS][COLS] = {{ 10, 35, 23 },
{ 5, 4, 57 },
{ 4, 7, 21 }};
int ColSum[ROWS];
int rows;
int columns;
addCoulmns(array,ColSum);
for (columns = 0; columns < COLS - 1; columns++)
printf("%d\n",ColSum[columns]);
return(0);
}
void addCoulmns(int arr[][COLS],int Sum[COLS])
{
int row;
int col;
for (col = 0; col < COLS - 1; col++)
{
Sum[col] = 0;
for (row = 0; row < ROWS - 1; row++)
Sum[col] += arr[row][col];
}
return;
}
In: Computer Science
Write a method that displays every other element of an array.
Write a program that generates 100 random integers between 0 and 9 and displays the count for each number. (Hint: Use an array of ten integers, say counts, to store the counts for the number of 0s, 1s, . . . , 9s.)
Write two overloaded methods that return the average of an array with the following headers:
public static int average(int[] intArray)
public static double average(double[] dArray)
Also, write a test program that prompts the user to enter ten double values, invokes the correct method, and displays the average value.
Given this array, write the code to find the smallest value in it:
int[] myList = new myList[n];
In: Computer Science
UNIX
1. Compile and run shell0.c file
2. Design and implement shell1.c program to handle "exit"
command to terminate the program.
That is, if the user input-string is "exit", then the program
terminates.
3.Design and Implement shell2.c to implement a signal handler to handle ctrl+C (SIGINT) as listed below
void sig_int(int signo) { printf("\nCaught SIGINT!\n"); }
Here is shell0.c file
shell0.c
/*
* shell0.c
* running in loop to read input string (command) to be processed
* To exit, type EOF (ctlr+D) or ctlr+C
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
char *getinput(char *buffer, size_t buflen)
{
printf("$$ ");
return fgets(buffer, buflen, stdin);
}
int main(int argc, char **argv)
{
char buf[1024];
pid_t pid;
int status;
while (getinput(buf, sizeof(buf))) {
buf[strlen(buf) - 1] = '\0';
if((pid=fork()) == -1) {
fprintf(stderr, "shell: can't fork: %s\n",
strerror(errno));
continue;
} else if (pid == 0) {
/* child */
execlp(buf, buf, (char *)0);
fprintf(stderr, "shell: couldn't exec %s: %s\n", buf,
strerror(errno));
exit(EX_DATAERR);
}
if ((pid=waitpid(pid, &status, 0)) < 0)
fprintf(stderr, "shell: waitpid error: %s\n",
strerror(errno));
}
exit(EX_OK);
}In: Computer Science
In: Computer Science
Java
Q1: Create a class named Triangle, the class must contain:
Q2: Write a Java program that creates a two-dimensional array of type integer of size x by y (x and y must be entered by the user). The program must fill the array with random numbers from 1 to 100. The program must prompt the user to enter a search key between 1 and 100. Then, the program must check whether the search key is available in the array and print its location.
Here is a sample run:
Enter the number of rows: 5
Enter the number of columns: 5
Enter a search key between 1-100: 27
The key you entered is available at row 3, column 2.
Here is another sample run:
Enter the number of rows: 5
Enter the number of columns: 5
Enter a search key between 1-100: 33
The key you entered is not available in the array.
In: Computer Science
In: Computer Science
Design a multiplexed communication system that can be used for 1 of 4 senders (sources) to send 3 bits to 1 of 2 receivers (destinations) using a 3-bit 4×1 multiplexer and a 2-bit 1×2 demultiplexer. Assume that the most significant of the 3 bits denotes the header containing the destination ID and that the 2 less significant bits denote the message. Represent both the 3-bit 4×1 multiplexer and a 2-bit 1×2 demultiplexer using block diagrams with all inputs and outputs labeled. Show which outputs of the multiplexer connect to which inputs of the demultiplexer!
In: Computer Science
Draw an ER diagram and write a database design outline for the following prompt:
You run a coaching service to help high school students prepare for the SAT exam. You have a staff of coaches, each of which has an employee ID, an hourly rate (such as $20 per hour), and personal information consisting of their first name, last name, middle name/initial, address information, phone number, mobile phone number, and e-mail address. For each high school student, you want to keep similar personal information and a student ID number, date of birth, and expected date of graduation from high school. Coaching takes place in sessions, to each of which you assign a unique ID number. Each session consists of one coach and one student. In addition to being able to identify the coach and student involved in each session, you want to store its start date/time and end date/time.
In: Computer Science
Complete the program used on the instructions given in the comments:
C++ lang
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
vector<float>GetTheVector();
void main()
{
vector<int> V;
V = GetTheVector(); //reads some lost numbers from the file “data.txt" and places it in //the Vector V
Vector<int>W = getAverageOfEveryTwo(V);
int printTheNumberOfValues(W) //This should print the number of divisible values by 7 //but not divisible by 3.
PrintIntoFile(W); //This prints the values of vector W into an output file “output.txt”
}
As you see in the main program, there are four functions. The first function is called “GetVector()” that reads a set of integer, place them into the vector V, and returns the vector to the main program.
The second function is called “GetAverageOfEveryTwoNumber() that takes a vector “V” and finds the average of every two consecutive numbers, place the values into another vector called “W” and returns it to the main program. For example if the Vector is:
10 20 30 40 50 60 70 80 90 100
Then vector “W” should be:
15 25 35 45 55 65 75 85 95
Because (10+20) divided by 2 is 15, and so on.
The next function takes the vector “W” and count how many of the values are divisible by “7” but not divisible by “3”
Finally the last function prints the vector “W” into an output file called “output.txt”
In: Computer Science