Answer:
num_ones = amount_to_change % 5
Explanation:
It is given that the cashier has to change the money in the maximum number of 5 dollar bills and remaining as $1 bills.
We have to write a single statement of code to assign the value to variable num_ones to find the value of $1 bills given amount_to_change.
Let us solve this by taking example:
If amount_to_change = $19
Then total number of $5 bills that can be given is 3. And amount that can be given as $5 bills is [tex]\bold{3 \times 5 = \$15}[/tex]
So, the remaining amount i.e. $19 - $15 = $4 will be given as one dollar bills.
Out of these $19, 4 bills of $1 can be found using the Modulus (%) operator.
Modulus operator leaves the remainder i.e.
Output of p % q is the remainder when a number 'p' is divided by 'q'.
19 % 5 = 4
4 is the number of one dollar bills to be given.
So, single line of code for the number of one dollar bills can be written as:
num_ones = amount_to_change % 5
Let us try it for amount_to_change = $30
We know that 6 number of $5 bills can be used to change the amount of $30 and no one dollar bill required.
num_ones = 30 % 5 = 0 (because 30 is completely divisible by 5 so remainder is 0)
So, the correct statement is:
num_ones = amount_to_change % 5
Assemble a Server computer based on your budget (state the amount in Ghana Cedis), discussing the type of components (giving their exact names, model numbers, types, cost, architecture, etc.) you would need and give reasons why you need them.
Answer:
Following are the answer to this question:
Explanation:
The server would be generally a powerful processor instead of a desktop pc. It must choose the Dell server browser to choose a server for industrial applications.
Dell Poweredge R730 has been its pattern. There should be the reason whether these servers are efficient, available, flexible, and support the concept of even a virtual environment. Its same servers are easy to use, as well as the memory will be connected to this server is 8 TB.A company wants a recruiting app that models candidates and interviews; displays the total number of interviews on each candidate record; and defines security on interview records that is independent from the security on candidate records. What would a developer do to accomplish this task? Choose 2 answers
a. Create a roll -up summary field on the Candidate object that counts Interview records.
b. Create a master -detail relationship between the Candidate and Interview objects.
c. Create a lookup relationship between the Candidate and Interview objects.
d. Create a trigger on the Interview object that updates a field on the Candidate object.
Answer:
c. Create a lookup relationship between the Candidate and Interview objects.
d. Create a trigger on the Interview object that updates a field on the Candidate object.
Explanation:
Objects relationships is considered a form of field type that joins two or more objects together such that, after understanding objects and fields, it creates some form of bonding known as object relationships. This helps define security on interview records that is independent from the security on candidate records.
For an example, in a standard object like Account, where a sales representative opens an account, and has had interviews or chats with a few people at that account’s company, and as well made contacts with the likes of executives or IT managers and still stored those contacts’ information in salesforce.
Hence, what would a developer do to accomplish this task is to:
1. Create a lookup relationship between the Candidate and Interview objects.
2. Create a trigger on the Interview object that updates a field on the Candidate object.
1. Two TCP entities communicate across a reliable network. Let the normalized time to transmit a fixed length segment equal 1. Assume that the end-to-end propagation delay is 3 and that it takes 2 to deliver data from a received segment to the transport user. The receiver initially grants a credit of 7 segments. The receiver uses a conservative flow control policy and updates its credit allocation at every opportunity. What is the maximum achievable throughput
Answer:
The answer is "0.77"
Explanation:
The fixed-length segment value = 1
The propagation time of one end to another end is = 3
The Transfer power to move the consumer from the obtained segment = 2
The second last sender assigns a loan = 7 segments
The overall transmission time = 3+2+3 = 8
The maximum throughput value is:
[tex]\to \frac{7}{(1 + 8)}\\\\ \to \frac{7}{9}\\\\\to 0.77[/tex]
Normally you depend on the JVM to perform garbage collection automatically. However, you can explicitly use ________ to request garbage collection.
Answer:
System.gc()
Explanation:
System.gc() can be defined as the method which can be used to effectively request for garbage collection because they runs the garbage collector, which in turn enables JMV which is fully known as JAVA VIRTUAL MACHINE to claim back the already unused memory space of the objects that was discarded for quick reuse of the memory space , although Java virtual machine often perform garbage collection automatically.
Which of the following statements represents the number of columns in a regular two-dimensional array named values?
A) values[0].length
B) values.length
C) values.length)
D) values[0].length0
E) values.getColumnLength0)
Answer:
(a) values[0].length
Explanation:
In programming languages such as Java, an array is a collection of data of the same type. For example, a and b below are an example of an array.
a = {5, 6, 7, 9}
b = {{2,3,4}, {3,5,4}, {6,8,5}, {1,4,6}}
But while a is a one-dimensional array, b is a regular two-dimensional array. A two-dimensional array is typically an array of one-dimensional arrays.
Now, a few thing to note about a two-dimensional array:
(i) The number of rows in a 2-dimensional array is given by;
arrayname.length
For example, to get the number of rows in array b above, we simply write;
b.length which will give 4
(ii) The number of columns in a 2-dimensional array is given by;
arrayname[0].length
This is with an assumption that all rows have same number of columns.
To get the number of columns in array b above, we simply write;
b[0].length which will give 3
Therefore, for a regular two-dimensional array named values, the number of columns is represented by: values[0].length
Boolean expressions control _________________ Select one: a. recursion b. conditional execution c. alternative execution d. all of the above
Answer:
Option D, all of the above, is the right answer.
Explanation:
A Boolean expression is an expression in Computer Science. It is employed in programming languages that create a Boolean value when it is evaluated. There may be a true or false Boolean value. These expressions correspond to propositional formularies in logic. In Boolean expression, the expression 3 > 5 is evaluated as false while 5 > 3 is evaluated as true
Boolean expressions control all of the above method execution and as such option d is correct.
What is Boolean expressions?A Boolean expression is known to be a kind of logical statement that is said to be one of the two options that is it can be TRUE or FALSE .
Conclusively, Note that Boolean expressions are used to compare two or more data of any type only if both parts of the expression have equal basic data type. Boolean expressions control recursion, conditional execution and alternative execution.
Learn ore about Boolean expressions from
https://brainly.com/question/25039269
Create an application in Java that asks a user for a number of hours, days, weeks, and years. It then computes the equivalent number of minutes (ignoring leap years).
Answer:
//import the Scanner class
import java.util.Scanner;
//Begin class definition
public class NumberOfMinutes{
//Begin main method
public static void main(String []args){
//Create an object of the Scanner class
Scanner input = new Scanner(System.in);
//initialize a variable nm to hold the number of minutes
int nm = 0;
//Prompt the use to enter the number of hours
System.out.println("Please enter the number of hours");
//Receive the input using the Scanner object and
//Store the entered number of hours in a variable nh
int nh = input.nextInt();
//Prompt the user to enter the number of days
System.out.println("Please enter the number of days");
//Receive the input using the Scanner object and
//Store the entered number of days in a variable nd
int nd = input.nextInt();
//Prompt the user to enter the number of weeks
System.out.println("Please enter the number of weeks");
//Receive the input using the Scanner object and
//Store the entered number of weeks in variable nw
int nw = input.nextInt();
//Prompt the user to enter the number of years
System.out.println("Please enter the number of years");
//Receive the input using the Scanner object and
//Store the entered number of years in a variable ny
int ny = input.nextInt();
//Convert number of hours to minutes and
//add the result to the nm variable
nm += nh * 60;
//Convert number of days to minutes and
//add the result to the nm variable
nm += nd * 24 * 60;
//Convert number of weeks to minutes and
//add the result to the nm variable
nm += nw * 7 * 24 * 60;
//Convert number of years to minutes and
//add the result to the nm variable
nm += ny * 52 * 7 * 24 * 60;
//Display the number of minutes which is stored in nm
System.out.println("The number of minutes is " + nm);
} //End main method
} //End of class definition
Sample Output:Please enter the number of hours
>>12
Please enter the number of days
>>2
Please enter the number of weeks
>>4
Please enter the number of years
>>5
The number of minutes is 2664720
Explanation:
The code contains comments explaining every line of the program. Please go through the comments. The actual lines of executable code are written in bold face to distinguish them from comments.
A sample output has also been provided above. Also, a snapshot of the program file, showing the well-formatted code, has been attached to this response.
#Write a function called after_second that accepts two #arguments: a target string to search, and string to search #for. The function should return everything in the first #string *after* the *second* occurrence of the search term. #You can assume there will always be at least two #occurrences of the search term in the first string. # #For example: # after_second("11223344554321", "3") -> 44554321 # #The search term "3" appears at indices 4 and 5. So, this #returns everything from the index 6 to the end. # # after_second("heyyoheyhi!", "hey") -> hi! # #The search term "hey" appears at indices 0 and 5. The #search term itself is three characters. So, this returns #everything from the index 8 to the end. # #Hint: This may be more complicated than it looks! You'll #have to look at the length of the search string and #either modify the target string or take advantage of the #extra arguments you can pass to find(). #Write your function here!
Answer:
Following are the code to this question:
def after_second(s,sub):#defining a method a fter_second
first = s.find(sub)#defining a variable first that hold method find value
if first != -1:#defining if block to check first variable value not equal to -1 using slicing
s = s[len(sub)+first:]#defining s variable to calculate sub parameter length of parameter and use slicing
second = s.find(sub)#defining second variable to calculate find method value
if second != -1:#defining if block to calculate second variable slicing
return s[len(sub)+second:]#return s variable value
print(after_second("heyyoheyhi","hey"))#defining print method to call after_second method
print(after_second("11223344554321","3"))#defining print method to call after_second method
Output:
hi
44554321
Explanation:
In the above python code a method "after_second" is declared, that accepts two-variable "s, and sub" as the parameter inside the method a first variable is declared that uses the inbuilt method "find" to find the value and stores it value. In the next step, two if blocks are used, in which both if blocks use the slicing to checks its value is not equal to "-1".
In the first, if block the first variable is declared that uses the s variable to calculate subparameter length by using slicing and defines the second variable that finds its value and stores its value. In the next, if block the s variable is used to return its calculated value, and at the end of the print, the method is used to call the method by passing parameter value and prints its return value.If the current date is Monday, February 26, 2017, what will be displayed by the alert dialog box after the following code executes? var thisDay = new Date(); alert(thisDay.toDateString());
Answer:
Mon Feb 26 2017
Explanation:
Since the current date is considered as Monday, February 26, 2017, thisDay will be set to that value.
The toDateString() method returns the first three letters of the name of the day (The first letter is capitalized), the first three letters of the name of the month (The first letter is capitalized), the day of the month as an integer, and the year as an integer (There are spaces between all)
Lily is in her first year of undergraduate coursework and has not yet declared a major. She has attended a lot of career fairs and undergraduate major "open house" events to investigate her options. Marcia's theory of identity status suggests that the dimension Lily is most concerned with is the_____of 1 dimension.
Answer:
exploration
Explanation:
According to Marcia's theory of identity, the status suggests that the dimension Lily is most concerned with is the exploration dimension.
James E. Marcia who came up with the Marcia's theory of identity is a clinical and developmental psychologist. He also once taught at Simon Fraser University which is located in British Columbia, Canada and also in the State University of New York at Buffalo in Upstate, New York City.
James E. Marcia is also very much involved in clinical private practice, community consultation, clinical psychology supervision, and also in international clinical-developmental research and teaching.
How I to turn this ''loop while'' in ''loop for''?
var i = 0;
while (i < 20) {
var lineY = 20 + (i * 20);
line(0, lineY, 400, lineY);
i++;
}
Answer:
for (var i = 0; i <20; i++)
{
var lineY = 20 + (i * 20);
line(0, lineY, 400, lineY);
}
Explanation:
To turn the loop while to for loop, you start by considering the iterating variable i and its iterating operations which are;
var i = 0; while (i < 20) and i++;
Where var i = 0; is the initializing statement
(i < 20) is the conditional statement
i++ is the increment
The next is to combine these operations to a for loop; using the following syntax: for(initializing; condition; increment){}
This gives: for(var i = 0; i<20; i++)
Hence, the full code snippet is:
for (var i = 0; i <20; i++)
{
var lineY = 20 + (i * 20);
line(0, lineY, 400, lineY);
}
Oops, we made a mistake: we created a key "short" and gave it the value "tall", but we wanted to give it the value "long" instead. Write the line of code that will change the value associated with the key "short" to "long". Be consistent in whether you use single or double quotes to declare your strings: our autograder assumes you'll be consistent.
Answer:
Using java
//assuming that hashmap object name is ChangeMap
ChangeMap. replace("short", "long");
System.out.println("New HashMap: "
+ ChangeMap.toString());
Explanation:
From the above we have used the replace method to replace the value of the "short" key in the hashtable with "long" instead of the previous value "tall". We have used the printed the hashtable to the console using println and the ".toString()" method that we added to the function's parameter.
There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbour). Each day, for each cell, if its neighbours are both active or both inactive, the cell becomes inactive the next day,. otherwise itbecomes active the next day.
Assumptions: The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumsed to be always inactive. Even after updating the cell state. consider its pervious state for updating the state of other cells. Update the cell informationof allcells simultaneously.
Write a fuction cellCompete which takes takes one 8 element array of integers cells representing the current state of 8 cells and one integer days representing te number of days to simulate. An integer value of 1 represents an active cell and value of 0 represents an inactive cell.
Program:
int* cellCompete(int* cells,int days)
{
//write your code here
}
//function signature ends
Test Case 1:
INPUT:
[1,0,0,0,0,1,0,0],1
EXPECTED RETURN VALUE:
[0,1,0,0,1,0,1,0]
Test Case 2:
INPUT:
[1,1,1,0,1,1,1,1,],2
EXPECTED RETURN VALUE:
[0,0,0,0,0,1,1,0]
This is the problem statement given above for the problem. The code which I have written for this problem is given below. But the output is coming same as the input.
#include
using namespace std;
// signature function to solve the problem
int *cells(int *cells,int days)
{ int previous=0;
for(int i=0;i
{
if(i==0)
{
if(cells[i+1]==0)
{
previous=cells[i];
cells[i]=0;
}
else
{
cells[i]=0;
}
if(i==days-1)
{
if(cells[days-2]==0)
{
previous=cells[days-1];
cells[days-1]=0;
}
else
{
cells[days-1]=1;
}
}
if(previous==cells[i+1])
{
previous=cells[i];
cells[i]=0;
}
else
{
previous=cells[i];
cells[i]=1;
}
}
}
return cells;
}
int main()
{
int array[]={1,0,0,0,0,1,0,0};
int *result=cells(array,8);
for(int i=0;i<8;i++)
cout<
}
I am not able to get the error and I think my logic is wrong. Can we apply dynamic programming here If we can then how?
Answer:
I am writing a C++ program using loops instead of nested if statements.
#include <iostream> // to use input output functions
using namespace std; // to identify objects like cin cout
void cells(int cells[],int days){ /* function that takes takes one array of integers cells, one integer days representing the number of days to simulate. */
int pos ,num=0; //declares variables pos for position of two adjacent cells and num to iterate for each day
int result[9]; //the updated output array
while (num< days) { //this loop keeps executing till the value of num is less than the value of number of days
num++;
for(pos=1;pos<9;pos++) //this loop has a pos variable that works like an index and moves through the cell array
result[pos]=(cells[pos-1])^ (cells[pos+1]); //updated cell state determined by the previous and next cells (adjacent cells) by bitwise XOR operations
for(pos=1;pos<9;pos++) //iterates through the array
cells[pos]=result[pos]; } //the updated cells state is assigned to the cell array simultaneously
for(pos=1;pos<9;pos++) //iterates through the array and prints the resultant array that contains the updated active and inactive cells values
cout << result[pos]; }
int main() { //start of the main function body
int j,day;
int output[9];
*/the two cells on the ends (first and last positions of array) have single adjacent cell, so the other adjacent cell can be assumed to be always inactive i.e. 0 */
output[0]=output[9]=0;
for(j=1;j<9;j++) //takes the input array from user
cin >> output[j];
cin >> day;
cells(output,day); } //calls the function cells to print the array with active and inactive cells states.
Explanation:
The program is well explained in the comments mentioned with every statement of the program. I will explain with the help of example:
Suppose the user enters the array = [1,0,0,0,0,1,0,0] and days=1
The while loop checks if the value of num is less than that of days. Here num is 0 and days is 1 So this means that the body of while loop will execute.
In the body of while loop the value of num is incremented by 1. The first loop initializes a variable pos for position of adjacent cells. The statement is a recursive statement result[pos]=(cells[pos-1])^ (cells[pos+1]) that uses previous state for updating the state of other cells. The “^” is the symbol used for bitwise exclusive operator. In bitwise XOR operations the two numbers are taken as operands and XOR is performed on every bit of two numbers. The result of XOR is 1 if the two bits are not same otherwise 0. For example XOR of 1^0 and 0^1 is 1 and the XOR of 0^0 and 1^1 is 0. The second for loop update the cell information of all cells simultaneously. The last loop prints the updated cells states.
The main function takes the input array element from user and the value for the days and calls the cells function to compute the print the active and inactive cells state information.
The screenshot of the program along with its output are attached.
Some network applications defer configuration until a service is needed. For example, a computer can wait until a user attempts to print a document before the software searches for available printers.
What is the chief advantage of deferred configuration?
Answer:
The drivers wont be loaded and the deamons will not be running in the background unnecessarily, that makes the processes to run more faster
Explanation:
The chief advantage of deferred configuration or the advantage when some network applications defer configuration until a service is needed is that the drivers won't be loaded and the deamons will not be running in the background unnecessarily or when idle, that makes the processes to run more faster.
Network configuration is the activity which involves setting up a network's controls, flow and operation to assist the network communication of an organization or network owner.
what is the difference between ram and rom
Answer:
RAM is used to store programs and data the CPU needs. ROM has prerecorded data and is used to boot the computer
Explanation:
Do Exercise 6.4 from your textbook using recursion and the is_divisible function from Section 6.4. Your program may assume that both arguments to is_power are positive integers. Note that the only positive integer that is a power of "1" is "1" itself. After writing your is_power function, include the following test cases in your script to exercise the function and print the results: print("is_power(10, 2) returns: ", is_power(10, 2)) print("is_power(27, 3) returns: ", is_power(27, 3)) print("is_power(1, 1) returns: ", is_power(1, 1)) print("is_power(10, 1) returns: ", is_power(10, 1)) print("is_power(3, 3) returns: ", is_power(3, 3))
Answer:
Here is the python method:
def is_power(n1, n2): # function that takes two positive integers n1 and n2 as arguments
if(not n1>0 and not n2>0): #if n1 and n2 are not positive integers
print("The number is not a positive integer so:") # print this message if n1 and n2 are negative
return None # returns none when value of n1 and n2 is negative.
elif n1 == n2: #first base case: if both the numbers are equal
return True #returns True if n1=n2
elif n2==1: #second base case: if the value of n2 is equal to 1
return False #returns False if n2==1
else: #recursive step
return is_divisible(n1, n2) and is_power(n1/n2, n2) #call divisible method and is_power method recursively to determine if the number is the power of another
Explanation:
Here is the complete program.
def is_divisible(a, b):
if a % b == 0:
return True
else:
return False
def is_power(n1, n2):
if(not n1>0 and not n2>0):
print("The number is not a positive integer so:")
return None
elif n1 == n2:
return True
elif n2==1:
return False
else:
return is_divisible(n1, n2) and is_power(n1/n2, n2)
print("is_power(10, 2) returns: ", is_power(10, 2))
print("is_power(27, 3) returns: ", is_power(27, 3))
print("is_power(1, 1) returns: ", is_power(1, 1))
print("is_power(10, 1) returns: ", is_power(10, 1))
print("is_power(3, 3) returns: ", is_power(3, 3))
print("is_power(-10, -1) returns: ", is_power(-10, -1))
The first method is is_divisible method that takes two numbers a and b as arguments. It checks whether a number a is completely divisible by number b. The % modulo operator is used to find the remainder of the division. If the remainder of the division is 0 it means that the number a is completely divisible by b otherwise it is not completely divisible. The method returns True if the result of a%b is 0 otherwise returns False.
The second method is is_power() that takes two numbers n1 and n2 as arguments. The if(not n1>0 and not n2>0) if statement checks if these numbers i.e. n1 and n2 are positive or not. If these numbers are not positive then the program prints the message: The number is not a positive integer so. After displaying this message the program returns None instead of True of False because of negative values of n1 and n2.
If the values of n1 and n2 are positive integers then the program checks its first base case: n1 == n2. Suppose the value of n1 = 1 and n2 =1 Then n1 is a power of n2 if both of them are equal. So this returns True if both n1 and n2 are equal.
Now the program checks its second base case n2 == 1. Lets say n1 is 10 and n2 is 1 Then the function returns False because there is no positive integer that is the power of 1 except 1 itself.
Now the recursive case return is_divisible(n1, n2) and is_power(n1/n2, n2) calls is_divisible() method and is_power method is called recursively in this statement. For example if n1 is 27 and n2 is 3 then this statement:
is_divisible(n1, n2) returns True because 27 is completely divisible by 3 i.e. 27 % 3 = 0
is_power(n1/n2,n2) is called. This method will be called recursively until the base condition is reached. You can see it has two arguments n1/n2 and n2. n1/n2 = 27/3 = 9 So this becomes is_power(9,3)
The base cases are checked. Now this else statement is again executed return is_divisible(n1, n2) and is_power(n1/n2, n2) as none of the above base cases is evaluated to true. when is_divisible() returns True as 9 is completely divisible by 3 i.e. 9%3 =0 and is_power returns (9/3,3) which is (3,3). So this becomes is_power(3,3)
Now as value of n1 becomes 3 and value of n2 becomes 3. So the first base case elif n1 == n2: condition now evaluates to true as 3=3. So it returns True. Hence the result of this statement print("is_power(10, 2) returns: ", is_power(10, 2)) is:
is_power(27, 3) returns: True
Following are the program to the given question:
Program Explanation:
Defining a method "is_divisible" that takes two variable "a,b" inside the parameter.Usinge the return keyword that modulas parameter value and checks its value equal to 0, and return its value.In the next step, another method "is_power" is declared that takes two parameter "a,b".Inside the method, a conditional statement is declared, in which three if block is used. Inside the two if block it checks "a, b" value that is "odd number" and return bool value that is "True, False".In the last, if block is used checks "is_power" method value, and use multiple print method to call and prints its value.Program:
def is_divisible(a, b):#defining a method is_divisible that takes two parameters
return a % b == 0#using return keyword that modulas parameter value and checks its value equal to 0
def is_power(a, b):#defining a method is_power that takes two parameters
if a == 1:#defining if block that checks a value equal to 1 or check odd number condition
return True#return value True
if b == 1:#defining if block that checks b value equal to 1 or check odd number condition
return False#return value False
if not is_divisible(a, b):#defining if block that check method is_divisible value
return False##return value False
return is_power(a/b, b)#using return keyword calls and return is_power method
print("is_power(10, 2) returns: ", is_power(10, 2))#using print method that calls is_power which accepts two parameter
print("is_power(27, 3) returns: ", is_power(27, 3))#using print method that calls is_power which accepts two parameter
print("is_power(1, 1) returns: ", is_power(1, 1))#using print method that calls is_power which accepts two parameter
print("is_power(10, 1) returns: ", is_power(10, 1))#using print method that calls is_power which accepts two parameter
print("is_power(3, 3) returns: ", is_power(3, 3))#using print method that calls is_power which accepts two parameter
Output:
Please find the attached file.
Learn more:
brainly.com/question/24432065
Recall that within the ArrayBoundedQueue the front variable and the rear variable hold the indices of the elements array where the current front and rear elements, respectively, of the queue are stored. Which of the following code sequences could be used to correctly enqueue element into the queue, assuming that enqueue is called on a non-full queue and that the code also correctly increments numElements?
a. numElements++; elements[rear) - element:
b. front++; elements(front) - element:
c. rear = (rear + 1) % elements.length; elements[rear) - element;
d. front = (front + 1) % elements.length; elements[front) - element;
Answer:
c. rear = (rear + 1) % elements.length; elements[rear] = element;
Explanation:
In the above statement:
Name of the array is elements.
rear holds current index of elements array where current rear element of queue is stored. Front are rear are two open ends of the queue and the end from which the element is inserted into the queue is called rear.
element is the element that is required to enqueue into the queue
Enqueue basically mean to add an element to a queue.
Here it is assumed that the queue is not full. This means an element can be added to the queue.
It is also assumed that code also correctly increments numElements.
rear = (rear + 1) % elements.length; This statement adds 1 to the rear and takes the modulus of rear+1 to the length of the array elements[]. This statement specifies the new position of the rear.
Now that the new position of rear is found using the above statement. Next the element can be enqueued to that new rear position using the following statement:
elements[rear] = element; this statement sets the element at the rear-th (new position) index of elements[] array.
For example we have a queue of length 5 and there are already 4 elements inserted into this queue. We have to add a new element i.e. 6 to the queue. There are four elements in elements[] array and length of the array is 5 so this means the queue is not full. Lets say that rear = 3
elements.length = 5
rear = 3
Using above two statements we get.
rear = (rear + 1) % elements.length;
= 3 + 1 % 5
= 4%5
= 4
This computes the new position of rear. So the new position of rear is the 4-th index of elements[]. Now next statement:
elements[rear] = element;
elements[4] = 6
This statement adds element 6 to the 4-th index of elements[] array.
Thus the above statement enqueues element (element 6 in above example) into the queue.
A large population of ALOHA users manages to generate 50 requests/sec, including both originals and retransmissions. Time is slotted in units of 40 msec.
Required:
a. What is the chance of success on the first attempt?
b. What is the probability of exactly k collisions and then a success?
c. What is the expected number of transmission attempts needed?
Answer:
The answer is below
Explanation:
Given that:
Frame transmission time (X) = 40 ms
Requests = 50 requests/sec, Therefore the arrival rate for frame (G) = 50 request * 40 ms = 2 request
a) Probability that there is success on the first attempt = [tex]e^{-G}G^k[/tex] but k = 0, therefore Probability that there is success on the first attempt = [tex]e^{-G}=e^{-2}=0.135[/tex]
b) probability of exactly k collisions and then a success = P(collisions in k attempts) × P(success in k+1 attempt)
P(collisions in k attempts) = [1-Probability that there is success on the first attempt]^k = [tex][1-e^{-G}]^k=[1-0.135]^k=0.865^k[/tex]
P(success in k+1 attempt) = [tex]e^{-G}=e^{-2}=0.135[/tex]
Probability of exactly k collisions and then a success = [tex]0.865^k0.135[/tex]
c) Expected number of transmission attempts needed = probability of success in k transmission = [tex]e^{G}=e^{2}=7.389[/tex]
When Windows deletes the driver package and driver files, in what situation might it not delete driver files used by the device that is being uninstalled?
Answer:
when there is no junk
Explanation:
If you choose the checkbox next to “Delete the driver software from this device,” your computer will no longer contain the driver or any associated registry keys. Either method will prevent you from using the device until you reinstall the device driver.
What is situation deletes driver files used by the device?To connect and communicate with particular devices, a computer needs device drivers.
It may be taken out without any trouble. However, it also comes with the installers for your PC's drivers. You will need to go to the manufacturer's website to download them again if you accidentally delete them.
Therefore, No, unless your new driver is broken and corrupts data. Install the driver if it comes from a reliable source. It is not intended to. Having a backup system that keeps your data safe in case of issues is a good idea.
Learn more about driver files here:
https://brainly.com/question/10608750
#SPJ5
A signal travels from point A to point B. At point A, the signal power is 100 W. At point B, the power is 90 W. What is the attenuation in decibels?
Answer:
[tex]Attenuation = 0.458\ db[/tex]
Explanation:
Given
Power at point A = 100W
Power at point B = 90W
Required
Determine the attenuation in decibels
Attenuation is calculated using the following formula
[tex]Attenuation = 10Log_{10}\frac{P_s}{P_d}[/tex]
Where [tex]P_s = Power\ Inpu[/tex]t and [tex]P_d = Power\ outpu[/tex]t
[tex]P_s = 100W[/tex]
[tex]P_d = 90W[/tex]
Substitute these values in the given formula
[tex]Attenuation = 10Log_{10}\frac{P_s}{P_d}[/tex]
[tex]Attenuation = 10Log_{10}\frac{100}{90}[/tex]
[tex]Attenuation = 10 * 0.04575749056[/tex]
[tex]Attenuation = 0.4575749056[/tex]
[tex]Attenuation = 0.458\ db[/tex] (Approximated)
Draw the BST where the data value at each node is an integer and the values are entered in the following order 36,22,10,44,42,16,25,3,23,24 solution
Answer and Explanation:
A BST is the short form for Binary Search Tree. It is a special type of binary tree data structure in which nodes are arranged in a particular order such that;
i. the left subtree of a particular node should always contain nodes whose key values are less than that of the key value of the node itself.
ii. the right subtree of a particular node should always contain nodes whose key values are greater than that of the key value of the node itself.
iii. the right and left subtrees should also be a binary search tree.
For the given set of data:
36,22,10,44,42,16,25,3,23,24;
The equivalent binary search tree is attached to this response.
As shown in the attachment:
i. the first data value (36) is the root node value.
ii. the second value (22) is less than the root node value (36), therefore, 22 goes to the left of the root node.
iii. the third value is 10. This is less than 36 and then also less than 22, so 10 goes to the left of 22.
iv. the fourth value is 44. This is greater than the root node value (36), therefore, 44 goes to the right of the root node.
v. the fifth value is 42. This is greater than the root value (36) so it is going to be positioned somewhere at the right of the root node. But it is less than the value (44) of the direct right node of the root node. Therefore, 42 goes to the left of the direct right (44) of the root node.
vi. the sixth value is 16. This is less than the root node value (36). So it is going to be positioned somewhere at the left of the root node. It is also less than the value (22) of the direct left node of the root node. So it is going to be positioned somewhere at the left of the node with 22. But it is greater than the node with 10. Therefore, 16 is going to be to the right of the node with 10.
This trend continues until all data values have been rightly positioned.
PS: A binary tree is a data structure in which each node cannot have more than two nodes directly attached to it.
A__________provides an easier way for people to communicate with a computer than a graphical user interface (GUI).
Answer:
Natural language processing
Explanation:
NLP, because many people can use a device better when they can talk to it just like it is another person. Some systems that use an NLP are voice assistants such as Alexa and Siri.
Start with the following Python code. alphabet = "abcdefghijklmnopqrstuvwxyz" test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"] test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"] # From Section 11.2 of: # Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press. def histogram(s): d = dict() for c in s: if c not in d: d[c] = 1 else: d[c] += 1 return d Copy the code above into your program but write all the other code for this assignment yourself. Do not copy any code from another source. Part 1 Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False. Implement has_duplicates by creating a histogram using the histogram function above. Do not use any of the implementations of has_duplicates that are given in your textbook. Instead, your implementation should use the counts in the histogram to decide if there are any duplicates. Write a loop over the strings in the provided test_dups list. Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string. For example, the output for "aaa" and "abc" would be the following. aaa has duplicates abc has no duplicates Print a line like one of the above for each of the strings in test_dups. Part 2 Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alphabet that are not in the argument string. The letters in the returned string should be in alphabetical order. Your implementation should use a histogram from the histogram function. It should also use the global variable alphabet. It should use this global variable directly, not through an argument or a local copy. It should loop over the letters in alphabet to determine which are missing from the input parameter. The function missing_letters should combine the list of missing letters into a string and return that string. Write a loop over the strings in list test_miss and call missing_letters with each string. Print a line for each string listing the missing letters. For example, for the string "aaa", the output should be the following. aaa is missing letters bcdefghijklmnopqrstuvwxyz If the string has all the letters in alphabet, the output should say it uses all the letters. For example, the output for the string alphabet itself would be the following. abcdefghijklmnopqrstuvwxyz uses all the letters Print a line like one of the above for each of the strings in test_miss. Submit your Python program. It should include the following. The provided code for alphabet, test_dups, test_miss, and histogram. Your implementation of the has_duplicates function. A loop that outputs duplicate information for each string in test_dups. Your implementation of the missing_letters function. A loop that outputs missing letters for each string in test_miss. Also submit the output from running your program. Your submission will be assessed using the following Aspects. Does the program include a function called has_duplicates that takes a string parameter and returns a boolean? Does the has_duplicates function call the histogram function? Does the program include a loop over the strings in test_dups that calls has_duplicate on each string? Does the program correctly identify whether each string in test_dups has duplicates? Does the program include a function called missing_letters that takes a string parameter and returns a string parameter? Does the missing_letters function call the histogram function? Does the missing_letters function use the alphabet global variable directly? Does the program include a loop over the strings in test_miss that calls missing_letters on each string? Does the program correctly identify the missing letters for each string in test_miss, including each string that "uses all the letters"?
Answer:
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]
# From Section 11.2 of: # Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
#Part 1 Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False.
def has_duplicates(stringP):
dic = histogram(stringP)
for key,value in dic.items():
if value>1:
return True
return False
# Implement has_duplicates by creating a histogram using the histogram function above. Write a loop over the strings in the provided test_dups list.
# Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string.
# For example, the output for "aaa" and "abc" would be the following. aaa has duplicates abc has no duplicates Print a line like one of the above for each of the strings in test_dups.
print("***Implementation of has_duplicates fuction***")
for sTr in test_dups:
if has_duplicates(sTr):
print(sTr+": has duplicates")
else:
print(sTr+": has no duplicates")
#Part 2 Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alphabet that are not in the argument string.
#The letters in the returned string should be in alphabetical order. Your implementation should use a histogram from the histogram function. It should also use the global variable alphabet.
#It should use this global variable directly, not through an argument or a local copy. It should loop over the letters in alphabet to determine which are missing from the input parameter.
#The function missing_letters should combine the list of missing letters into a string and return that string.
def missing_letters(sTr):
missingLettersList = []
dic = histogram(sTr)
for l in alphabet:
if l not in dic:
missingLettersList.append(l)
missingLettersList.sort()
return "".join(missingLettersList)
#Write a loop over the strings in list test_miss and call missing_letters with each string. Print a line for each string listing the missing letters.
#For example, for the string "aaa", the output should be the following. aaa is missing letters bcdefghijklmnopqrstuvwxyz
#If the string has all the letters in alphabet, the output should say it uses all the letters.
#For example, the output for the string alphabet itself would be the following. abcdefghijklmnopqrstuvwxyz uses all the letters
#Print a line like one of the above for each of the strings in test_miss.
print("\n***Implementation of missing_letters fuction***")
for lTm in test_miss:
sTr = missing_letters(lTm.replace(" ",""))
if sTr!="":
print(lTm+" is missing letters "+sTr)
else:
print(lTm +" uses all the letters")
C++ Fibonacci
Complete ComputeFibonacci() to return FN, where F0 is 0, F1 is 1, F2 is 1, F3 is 2, F4 is 3, and continuing: FN is FN-1 + FN-2. Hint: Base cases are N == 0 and N == 1.
#include
using namespace std;
int ComputeFibonacci(int N) {
cout << "FIXME: Complete this function." << endl;
cout << "Currently just returns 0." << endl;
return 0;
}
int main() {
int N = 4; // F_N, starts at 0
cout << "F_" << N << " is "
<< ComputeFibonacci(N) << endl;
return 0;
}
Answer:
int ComputeFibonacci(int N) {
if(N == 0)
return 0;
else if (N == 1)
return 1;
else
return ComputeFibonacci(N-1) + ComputeFibonacci(N-2);
}
Explanation:
Inside the function ComputeFibonacci that takes one parameter, N, check the base cases first. If N is eqaul to 0, return 0. If N is eqaul to 1, return 1. Otherwise, call the ComputeFibonacci function with parameter N-1 and N-2 and sum these and return the result.
For example,
If N = 4 as in the main part:
ComputeFibonacci(4) → ComputeFibonacci(3) + ComputeFibonacci(2) = 2 + 1 = 3
ComputeFibonacci(3) → ComputeFibonacci(2) + ComputeFibonacci(1) = 1 + 1 = 2
ComputeFibonacci(2) → ComputeFibonacci(1) + ComputeFibonacci(0) = 1 + 0 = 1
*Note that you need to insert values from the bottom. Insert the values for ComputeFibonacci(1) and ComputeFibonacci(0) to find ComputeFibonacci(2) and repeat the process.
Write a function wordcount() that takes the name of a text file as input and prints the number of occurrences of every word in the file. You function should be case-insensitive so 'Hello' and 'hello' are treated as the same word. You should ignore words of length 2 or less. Also, be sure to remove punctuation and digits.
>>>wordcount('frankenstein.txt')
artifice 1
resting 2
compact 1
service 3
Answer:
I am writing a Python program. Let me know if you want the program in some other programming language.
import string #to use string related functions
def wordcount(filename): # function that takes a text file name as parameter and returns the number of occurrences of every word in file
file = open(filename, "r") # open the file in read mode
wc = dict() # creates a dictionary
for sentence in file: # loop through each line of the file
sentence = sentence.strip() #returns the text, removing empty spaces
sentence=sentence.lower() #converts each line to lowercase to avoid case sensitivity
sentence = sentence.translate(sentence.maketrans("", "", string.punctuation)) #removes punctuation from every line of the text file
words = sentence.split(" ") # split the lines into a list of words
for word in words: #loops through each word of the file
if len(word)>2: #checks if the length of the word is greater than 2
if word in wc: # if the word is already in dictionary
wc[word] = wc[word] + 1 #if the word is already present in dict wc then add 1 to the count of that word
else: #if the word is not already present
wc[word] = 1 # word is added to the wc dict and assign 1 to the count of that word
for w in list(wc.keys()): #prints the list of words and their number of occurrences
print(w, wc[w]) #prints word: occurrences in key:value format of dict
wordcount("file.txt") #calls wordcount method and passes name of the file to that method
Explanation:
The program has a function wordcount that takes the name of a text file (filename) as parameter.
open() method is used to open the file in read mode. "r" represents the mode and it means read mode. Then a dictionary is created and named as wc. The first for loop, iterates through each line (sentence) of the text file. strip() method is used to remove extra empty spaces or new line character from each sentence of the file, then each sentence is converted to lower case using lower() method to avoid case sensitivity. Now the words "hello" and "Hello" are treated as the same word.
sentence = sentence.translate(sentence.maketrans("", "", string.punctuation)) statement uses two methods i.e. maketrans() and translate(). maketrans() specifies the punctuation characters that are to be deleted from the sentences and returns a translation table. translate() method uses the table that maketrans() returns in order to replace a character to its mapped character and returns the lines of text file after performing these translations.
Next the split() method is used to break these sentences into a list of words. Second for loop iterates through each word of the text file. As its given to ignore words of length 2 or less, so an IF statement is used to check if the length of word is greater than 2. If this statement evaluates to true then next statement: if word in wc: is executed which checks if the word is already present in dictionary. If this statement evaluates to true then 1 is added to the count of that word. If the word is not already present then the word is added to the wc dictionary and 1 s assigned to the count of that word.
Next the words along with their occurrences is printed. The program and its output are attached as screenshot. Since the frankenstein.txt' is not provided so I am using my own text file.
Write a program that extracts the last three items in the list sports and assigns it to the variable last. Make sure to write your code so that it works no matter how many items are in the list
Answer:
sports = ["football", "basketball", "volleyball", "baseball", "swimming"]
last = sports[-3:]
print(last)
Explanation:
*The code is in Python.
Create a list called sports
Create a variable called last and set it to the last three elements of the sports list using slicing
Print the last
Describe in detail how TCP packets flow in the case of TCP handoff, along with the information on source and destination addresses in the various headers.
Answer:
Following are the answer to this question:
Explanation:
There will be several ways to provide it, although it is simpler to let another front side Will work out a three-way handshake or transfer packages to there with a Server chosen. Its application responds TCP packets with both the destination node of the front end.
The very first packet was sent to a computer as an option. Mention, even so, that perhaps the end of the queue end remains in the loop in this scenario. Rather than obtaining this information from the front end like in the primary healthcare services, you have the advantage of this capability: its selected server helps to generate TCP state.
a software development management tool that easily integrates into his business’s enterprise software/information system
Answer:
Enterprise software/system
Explanation:
Enterprise software which is also known as Enterprise Application Software (EAS) is computer software that its primary function is to meet the needs of an organization rather than that of an individual.
EAS or Enterprise System is the software development management tool that easily integrates into a business' enterprise software system.
A printer is connected locally on Computer1 and is shared on the network. Computer2 installs the shared printer and connects to it. Computer1 considers the printer to be a(n) ________________ printer, and Computer2 considers the printer to be a(n) ________________ printer.
Answer:
A printer is connected locally on Computer1 and is shared on the network. Computer2 installs the shared printer and connects to it. Computer1 considers the printer to be a(n) _____local___________ printer, and Computer2 considers the printer to be a(n) _____network___________ printer.
Explanation:
Any printer installed directly to Computer 1 is a local printer. If this printer is then shared with computers 2 and 3 in a particular networked environment, it becomes a shared printer. For these other computers 2 and 3, the shared printer is a network printer, because it is not locally installed in each of them. There may be some features which network computers cannot use on a shared printer, especially if the printer can scan documents.
g Write a program that asks for the weight of a package and the distance it is to be shipped. This information should be passed to a calculateCharge function that computes and returns the shipping charge to be displayed . The main function should loop to handle multiple packages until a weight of 0 is entered.
Answer:
I am writing a C++ program:
#include <iostream> //to use input output functions
#include<iomanip> // to format the output
using namespace std; // to identify objects like cin cout
void calculateCharge(double weight, double distance); // function prototype
int main(){ //start of main() function body
double w = 0.0, t = 0.0; // w variable is for weight and t is for total
unsigned int d = 0; // d variable is to hold the value of distance
calculateCharge(w, d); } //calls calculateCharge method by passing weight and distance values to this method
void calculateCharge(double weight, double distance){ //method that takes weight and distance as parameters and compute the shipping charge
double charge = 0.0; //to store the value of shipping charges
do { // do while loop to handle multiple packages until a weight of 0 is entered
cout << "Enter weight: " << endl; //prompts user to enter weight
cin >> weight; //reads the input weight value
if (weight == 0){ // if the value of weight is equal to 0
break; } // the loop breaks if value of weight is 0
cout << "Enter distance: " << endl; // if value of weight is not zero then the program precedes by prompting user to enter the value of distance
cin >> distance; //reads the input distance value
cout << fixed << setprecision(2) << endl; //set the precision to 2 means the sets the number of digits of an output to 2 decimal places
if(weight <= 2) //if the value of weight is less than or equals to 2
charge = (distance/500) * 3.10; //compute the charge by this formula
else if(weight > 2 && weight <= 6) //if weight is over 2 kg but not more than 6 kg
charge = (distance/500) * 4.20; //charge is computed by multiplying value of distance to that of weight and if distance is greater than 500 then it is divided by 500 first
else if(weight > 6 && weight <= 10) // if weight is over 6 kg but not more than 10 kg
charge = (distance/500) * 5.30; //compute shipping charges by this formula
else //if weight is over 10 kg
charge = (distance/500) * 6.40; // compute shipping charge by multiplying value of distance to that of 6.40 weight value and if distance is greater than 500 then distance is divided by 500 first
cout << "Shipping charges: $" << charge << "\n"; //display the computed shipping charge
} while (weight != 0); //the loop continues to execute until weight 0 is entered
}
Explanation:
The program is explained in the comments mentioned above. The program has a main() function that declares variable for weight, distance and total and then calls calculateCharge() method passing weight and dsitance in order to compute and return the shipping charge.
In calculateCharge() the user is prompted to enter the values for weight and distance. Then the based on the value of weight , the shipping charge is computed. Shipping charge is computed by multiplying the weight with distance. The distance is assumed to be 500 but if the distance entered by user exceeds 500 then the distance value is divided by 500 and then multiplied by the specified weight (according to if or else if conditions) in order to compute shipping charge. The program has a do while loop that keeps taking input from user until the user enters 0 as the value of weight.
The screenshot of the program and its output is attached.