Questions
Python create a program Danny works for the government and is making a change. The chsnge...

Python create a program
Danny works for the government and is making a change. The chsnge is to create a 4 - digit ID frim the Original 12 - digit ID currently used for carts. The algorith established by Danny is as follows:
Find the sum of all 12 digits.
Extract the last 3 digits and multiply by 10.
Finally, add the results of the first twiboperations
Note:
If in step 3, there are more than 4 digits (x> 9999) , you must choose the last 4.
For example : 98012345 => 2345
If contains lesd than 4 digits ( x < 999), you must add 1, 000 to it. For example: 99 => 1099
Input Format
The first line of input contsins an integer
T (<= T < =100) , the number of test cases that follow. For each test cases, it will contains the 12- digit ID
Constraints
T ( 1 <=T <=100)
Output format
Print a single line per case, where the result is the 4- digit ID with the established rules.
Sample Input 0
3
465467984123
168198708712
620689713546
Sample Output

1289
7178
5519
Sample Input 1

two
416315410123
978643112002
978643112002
Sample Output 1
1261
1063

In: Computer Science

Write a PHP script that checks a word or a phrase (stored in a string variable)...

Write a PHP script that checks a word or a phrase (stored in a string variable) to determine if it is a standard palindrome, a perfect palindrome, or not a palindrome at all. Also, for each letter that the word/phrase contains, count and print the number of times that each consonant and vowel is encountered. Your output will look as follows:

Word/phrase: racecar

Perfect palindrome

Contains consonants:

r - 2

c - 2

Contains vowels:

a - 2

e - 1

In: Computer Science

Write a C++ program that solves a quadratic equation to find its roots. The roots of...

Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula (–b ± sqrt(b2 – 4ac)) / 2a *Use #include for the use of sqrt. The value of the discriminant (b2 – 4ac) determines the nature of roots. If the value of the discriminant is zero, then the equation has a single real root. If the value of the discriminant is positive then the equation has two real roots. If the value of the discriminant is negative, then the equation has two complex roots. The program takes values of a, b, and c as input and outputs the roots. Be creative in how you output complex roots. Include a loop that allows the user to repeat this calculation for new input values until the user says she or he wants to end the program.

In: Computer Science

Complete the function, MycountWords in C++, which will count the number of words in a string....

Complete the function, MycountWords in C++, which will count the number of words in a string. We will have different word separators(such as newline(\n), spaces, special symbols(? | \ , . : ;) ) That will separate the words in the giving istringstream. Remember if a words is separated by a hyphen and followed by a new line, they're still one word. The function has an option to be sensitive to case and also avoid duplicates. for duplicates, this is a boolean value that checks whether a word is repeated or not if its set to true and sensitive case is if the word count is sensitive to case and differentiates two words based on their case. even though they have different cases, they are the same word hence duplicates.

complete this function based on the description above.

unsigned int MycountWords(istringstream & iss, bool Duplicate=false, bool SenstiveCase =false) {

}

In: Computer Science

Questions about logic. Please Solve them ALL! (I have the right to ask the last question.)...

Questions about logic.

Please Solve them ALL! (I have the right to ask the last question.)

Please write in a legible and annotated way, thank you.

Q1A)
Let P(x) be the statement “x can swim” and let Q(x) be the statement “x can play the guitar.” Express each of these sentences in terms of P(x), Q(x), quantifiers, and logical connectives. The domain for quantifiers consists of all students in your school.
a) No student in your school can swim or can play the guitar.
b) Every student in your school either can swim or can play the guitar.
c) There is a student in your school who can swim and who play the guitar.
d) There is a student in your school who can swim but who cannot play the guitar.


Q1B)
Translate in two ways each of these statements into logical expressions using predicates, quantifiers, and logical connectives. First, let the domain consist of the students in your class and second, let it consist of all people.
a) Everyone in your class has a computer.
b) Somebody in your class has seen a foreign movie.
c) There is a person in your class who cannot play the guitar.
d) All students in your class can program.
e) Nobody in your class wants to have the flu.

In: Computer Science

UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array)...

UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array)

Implement an algorithm to guess a random number that the computer generates. The random number must be an integer between 1 and 1000 (inclusive). For each unsuccessful attempt, the program must let the user know whether to deal with a higher number or more. low. There is no limit on the number of attempts, the game only ends when the user succeeds. The user starts the game with $ 1000 and for each unsuccessful attempt loses $ 100. If you repeat any number of those who had already entered, they lose $ 200 instead of $ 100. If you don't follow the immediate instruction, you lose $ 200 instead of $ 100 (for example, if the program says to try a higher number, but you enter a higher number low to the previous one). In each unsuccessful attempt the program must tell the user how much money he has left (the figure can be negative). If the user hits the number and still has money, the program should congratulate him and tell him how much he won. If the user hits the number and owes money, the program must “bully” him and charge him. If the user hits the number by closing at $ 0 (neither wins nor owes), the program must let them know. In your report present 4 "print screens" of the execution of your program that result in 4 different results and their respective desktop tests (note that this is a special case where you have to run the program before the desktop test as there is no way I can control the random number that will come out in each run).

In: Computer Science

QUESTION 1 Which of the following programming languages does NOT support parametric polymorphism? Java C++ Python...

QUESTION 1

  1. Which of the following programming languages does NOT support parametric polymorphism?

    Java

    C++

    Python

    C#

10 points   

QUESTION 2

  1. Which of the following programming languages does NOT support operator overloading?

    C#

    Python

    C

    C++

10 points   

QUESTION 3

  1. In a language that allows nested subprograms, the programming language has to choose a referencing environment for the executing the passed subprogram when a subprogram is passed as a parameter. Which of the following is NOT a choice?

    just in time binding

    shallow binding

    ad hoc binding

    deep binding

10 points   

QUESTION 4

  1. Which of the following is necessary for recursion to take place via subprogram calls?

    static local variables

    stack dynamic local variables

    type checking

    returning values from a function

10 points   

QUESTION 5

  1. Which of the following is NOT a concern when corresponding the actual parameters to the formal parameters?

    default parameters

    variable number of parameters

    return type

    positional parameters v. keyword parameter

10 points   

QUESTION 6

  1. Which of the following is NOT an inout mode of parameter passing?

    pass by reference

    pass by result

    pass by name

    pass by value-result

10 points   

QUESTION 7

  1. Which of the following is never used to distinguish between two subprograms in any programming language?

    return type

    subprogram name

    parameter names

    parameter profiles

10 points   

QUESTION 8

  1. Which of the following types of subprograms exhibit ad hoc polymorphism?

    OOP languages

    generic subprograms

    overloaded subprograms

    typeless languages

10 points   

QUESTION 9

  1. In which type of language is a closure never necessary?

    static scoped language that does NOT support nested subprograms

    dynamically scoped language that does NOT support nested subprograms

    static scoped language that does support nested subprograms

    dynamically scoped language that does support nested subprograms

10 points   

QUESTION 10

  1. In what way are coroutines the same as all other programs?

    only one coroutine is actually in execution at any given time

    multiple entry points

    have control statements which suspend execution of the subprogram

    maintain their status between executions

10 points   

Click Save and Submit to save and submit. Click Save All Answers to save all answers.

In: Computer Science

What is the complexity of the given code as a function of the problem size n?  Show...

What is the complexity of the given code as a function of the problem size n?  Show all of the details of your analysis.

for (int i = 0; i < 2*n; i++)

{

   if (i == n)

   {

      for (int j = 0; j < i; j++)

         for (int k = 0; k < i; k++)

            O(1)

   }

   else

   {

      for (int j = 0; j < i; j++)

         O(1)

   }

}

In: Computer Science

Part E (3 marks):  What is the shape of a BST that is O(n) to delete the...

Part E (3 marks):  What is the shape of a BST that is O(n) to delete the root?  Draw an example with at least 8 nodes.

In: Computer Science

Python create a program Dennis has always loved music, snd recently discovered a fascinating genre. Tautograms...

Python create a program
Dennis has always loved music, snd recently discovered a fascinating genre. Tautograms genre.
Tautograns are a special case of aliteration, which is the appearance of the same letter at the beginning of adjacent words. In particular, a sentence is a tautogram if all its word begin with the following sentences are tautograms.
French flowers bloom, San Serrano whistles softly, Pedro ordered pizza.
Dennis wants to dazzle his wife with a romantic letter full of these kinds of prayers. Help Dennus check if each sentence he wrote is tautogram or not.
Input format
Each test case is made up of a single line that contains a sentence. A sentence consists of a sequence of up to 50 words separate by individual spaces. A word is a sequence of up to 20 contiguos uppercase and lowercase letters of the English alphabet. A word contains at least one letter and a sentence contains at least test case is followed by a line containing a single character "*"

Constraints
For each test case, generate a single line that contains an uppercase " Yes " if the sentence is a tautogram, or an uppercase "No" otherwise.
Output Format
"Yes or No"

Sample input 0
Sam Serrano whistles softly
French flowers bloom
Pedro ordered Pizza
This is not tautogram
*
Sample output 0
yes
yes
yes
Not

In: Computer Science

Using python programming language, compare the four tasks. 1. For the following exercises you will be...

Using python programming language, compare the four tasks.

1. For the following exercises you will be writing a program that implements Euler’s method (pronounced ‘oy-ler’). It may be the case that you have not yet encountered Euler’s method in the course. Euler’s method can be found in Chapter 10.2 of your notes, which gives a good description of why this algorithm works. But for our purposes, we only need to know the algorithm itself - so there’s no need to worry if you are yet to understand it.

Euler’s method is used to approximate a function when only the derivative and a particular value is known. Given an initial value y and a corresponding x value, a derivative f’(x), and a step size h, the next value for y is calculated using the following formula:

next y = current y + f'(x)*h

If you want to calculate more steps, just reuse the formula but with your new y value. The new x value is also updated to x+h.

Task: To start, write a function called fdash(x), that returns the value of the derivative at x. The formula for the derivative which we will be using as a placeholder is:

fdash = 0.05x * e^(0.05x)

Round the output to 5 decimal places. Do not print anything, call your function, or ask for any input.

2. Recall the formula for Euler’s method is:

next y = current y + f'(x)*h

Task: Write a function called onestep(x, y, h) that calculates the next y value using Euler’s method with the given x, y and h values. The derivative is the same as used in the previous exercise. Copy paste your function from the previous exercise and use it in your onestep function.

Round the output to 5 decimal places. Do not print anything, call your onestep function, or ask for any input. You should have two functions defined in your code (onestep and fdash).

3. Recall that after one step of Euler’s function is calculated, the new x value is also updated to x+h. Note that it happens in that orde.r First the next y value is found, then the corresponding x value is updated.

Task: Write a function called eulers(x, y, h, n) that uses euler’s method n times with the given x, y and h values. It will return the final y value. Remember to copy paste your onestep and fdash functions. You are encouraged to use them in your eulers function, but it is up to you.

The fdash and onestep functions already round their output, so you will not need to do any rounding inside the eulers function.

Hint: One way of implementing this function is to use a while loop.

If you need help with Euler’s method:

The following example of Euler’s method is given in case you do not understand how it works with multiple steps:

F dash: 2x + 2

Initial x: 1

Initial y: 4

Step size (h): 0.5

Number of steps (n): 3

Step 1:

Fdash = 2*1 + 2 = 2 + 2 = 4

Value of y at step 1: new y = 4 + 4*0.5 = 4 + 2 = 6

New x value = 1 + 0.5 = 1.5

Step 2:

Fdash = 2*1.5 + 2 = 3 + 2 = 5

Value of y at step 2: new y = 6 + 5*0.5 = 6 + 2.5 = 8.5

New x value = 1.5 + 0.5 = 2

Step 3:

Fdash = 2*2 + 2 = 4 + 2 = 6

Value of y at step 3: new y = 8.5 + 6*0.5 = 8.5 + 3 = 11.5

New x value = 2 + 0.5 = 2.5

So our final value for y is 11.5 after 3 steps (at x = 2.5). For interest, one function with this derivative is y = x**2+2*x+1. At x = 1, y is equal to 4, like in this example. At x = 2.5 (which is our final x value), the value of y is 12.25. This is pretty close to our approximated value of 11.5.

4. An asteroid has been spotted travelling through our solar system. One astrophysicist has predicted that it will collide with Earth in exactly 215 days, using a new method for modelling trajectories. The researcher has asked you and others to verify their claim using a variety of methods. You have been tasked with modelling the asteroid’s trajectory using Euler’s method.

For an asteroid to collide with Earth, it needs to have the same x, y, and z coordinates as the Earth in 215 days (x, y, and z represent the three dimensions. Because solar systems are three dimensional!). If any of the final predicted x, y, and z values are different to the Earth’s, then that will mean the asteroid will not collide with Earth in 215 days.

It has already been proven that the asteroid will have the same x and z coordinates as Earth in 215 days. So, you only need to worry about the y dimension.

The equation for the change in y at day t after the asteroid was discovered is:

y'(t) = (-0.05t+5)*exp(0.002t)*0.05

In other words, this equation is the derivative of y(t). The starting y position of the asteroid is 160.195 million kilometers, which occurs at t = 0. The y position of Earth in 215 days (t = 215) is 150 million kilometers.

Task: Write a function called will_it_hit(h), that returns the number 1 if the asteroid is going to hit Earth in 215 days, and 0 otherwise - along with the Euler’s method prediction of the asteroid’s y poistion.

The Earth will be considered ‘hit’ if the asteroid gets within 0.01 million kilometers of Earth (so abs(earthy - asteroidy)<=0.1). The input for the function is h, which indicates the step size in days. So h = 0.5 indicates that there are two steps of Euler’s method per day, resulting in 215/0.5 = 530 steps of Euler’s method.

As with the previous exercises, the output for the fdash and onestep functions should be rounded to 5 decimal places.

Use your code from the previous exercises. The only thing you will need to change is fdash. We have written tests for each of your functions (fdash, onestep, eulers, will_it_hit), to help you understand where errors might be. Good luck!

Note: All units for the y location of the asteroid should be in millions of kilometers. For example, will_it_hit(5) should give output (0, 151.72445).

In: Computer Science

please do it in C++, will up vote!! please add snap shots of result and explanation....

please do it in C++, will up vote!! please add snap shots of result and explanation.

You are to create a recursive function to perform a linear search through an array.

How Program Works

Program has array size of 5000

Load values into the array, equal to its index value. Index 5 has value 5, index 123 has value 123.

Pass array, key, and size to the recursive function:

int recursiveLinearSearch(int array[],int key, const int size, bool & methodStatus)

User enters key to search for, recursive function calls itself until the key is found (methodStatus is true), print out the key and number of function calls when control is returned to the main

Handle situation of key not found (return number of function calls AND methodStatus of false) – print not found message and number of calls in the main

Function returns a count of how many recursive calls were made

Value returned is the number of calls made to that point, that is, when item is found the value returned is 1 with preceding functions adding 1 to the return value until the actual number of recursive function calls are counted).

Determine smallest key value that causes stack-overflow to occur, even if you need to make array larger than 5000.

Test cases need to include, biggest possible key value, “not found” message, and a stack overflow condition.

In: Computer Science

in java Write a class named “Stock” to model a stock. The properties and methods of...

in java

Write a class named “Stock” to model a stock. The properties and methods of the class are shown in figure below. The method “ percentage ” computes the percentage of the change of the current price vs the previous closing price. Write a program to test the “Stock” class. In the program, create a Stock object with the stock symbol SUND, name Sun Microsystem V, previous closing price of 100. Set a new current price randomly and display the price percentage.

Stock

private String symbol
private String name
private double previousClosingPrice

private double currentPrice
public Stock()
public Stock(String symbol, String name)

public String getSymbol()
public String getName()
public double getPreviousClosingPrice()
public double getCurrentPrice()
public void setSymbol(String symbol)
public void setName(String name)
public void setPreviousClosingPrice(double price)
public void setCurrentPrice(double price)
public double percentage()

In: Computer Science

Cryptography- Run S-DES with key: 1000100111 and plaintext: 01010101

Cryptography-

Run S-DES with key: 1000100111 and plaintext: 01010101

In: Computer Science

Discuss some major problems and issues that can cause (a) network design in general, and (b)...

Discuss some major problems and issues that can cause (a) network design in general, and (b) LAN design in particular, to fail.

In: Computer Science