Questions
Develop a program that asks a user to enter the number 10, and then it outputs...

Develop a program that asks a user to enter the number 10, and then it outputs COUNT-DOWN from 10 to 0.

In: Computer Science

During the semester we studied IT Project Management. List the five attributes of a project. [1...

During the semester we studied IT Project Management. List the five attributes of a project. [1 x 5 = 5] List and describe the four generic phases of a project life cycle of development. [ 2.5 x 4 = 10]

In: Computer Science

import math print("RSA ENCRYPTION/DECRYPTION") print("*****************************************************") #Input Prime Numbers print("PLEASE ENTER THE 'p' AND 'q' VALUES BELOW:")...

import math

print("RSA ENCRYPTION/DECRYPTION")
print("*****************************************************")

#Input Prime Numbers
print("PLEASE ENTER THE 'p' AND 'q' VALUES BELOW:")
p = int(input("Enter a prime number for p: "))
q = int(input("Enter a prime number for q: "))
print("*****************************************************")

#Check if Input's are Prime
'''THIS FUNCTION AND THE CODE IMMEDIATELY BELOW THE FUNCTION CHECKS WHETHER THE INPUTS ARE PRIME OR NOT.'''
def prime_check(a):
if(a==2):
return True
elif((a<2) or ((a%2)==0)):
return False
elif(a>2):
for i in range(2,a):
if not(a%i):
return false
return True

check_p = prime_check(p)
check_q = prime_check(q)
while(((check_p==False)or(check_q==False))):
p = int(input("Enter a prime number for p: "))
q = int(input("Enter a prime number for q: "))
check_p = prime_check(p)
check_q = prime_check(q)

#RSA Modulus
'''CALCULATION OF RSA MODULUS 'n'.'''
n = p * q
print("RSA Modulus(n) is:",n)

#Eulers Toitent
'''CALCULATION OF EULERS TOITENT 'r'.'''
r= (p-1)*(q-1)
print("Eulers Toitent(r) is:",r)
print("*****************************************************")

#GCD
'''CALCULATION OF GCD FOR 'e' CALCULATION.'''
def egcd(e,r):
while(r!=0):
e,r=r,e%r
return e

#Euclid's Algorithm
def eugcd(e,r):
for i in range(1,r):
while(e!=0):
a,b=r//e,r%e
if(b!=0):
print("%d = %d*(%d) + %d"%(r,a,e,b))
r=e
e=b

#Extended Euclidean Algorithm
def eea(a,b):
if(a%b==0):
return(b,0,1)
else:
gcd,s,t = eea(b,a%b)
s = s-((a//b) * t)
print("%d = %d*(%d) + (%d)*(%d)"%(gcd,a,t,s,b))
return(gcd,t,s)

#Multiplicative Inverse
def mult_inv(e,r):
gcd,s,_=eea(e,r)
if(gcd!=1):
return None
else:
if(s<0):
print("s=%d. Since %d is less than 0, s = s(modr), i.e., s=%d."%(s,s,s%r))
elif(s>0):
print("s=%d."%(s))
return s%r

#e Value Calculation
'''FINDS THE HIGHEST POSSIBLE VALUE OF 'e' BETWEEN 1 and 1000 THAT MAKES (e,r) COPRIME.'''
for i in range(1,1000):
if(egcd(i,r)==1):
e=i
print("The value of e is:",e)
print("*****************************************************")

#d, Private and Public Keys
'''CALCULATION OF 'd', PRIVATE KEY, AND PUBLIC KEY.'''
print("EUCLID'S ALGORITHM:")
eugcd(e,r)
print("END OF THE STEPS USED TO ACHIEVE EUCLID'S ALGORITHM.")
print("*****************************************************")
print("EUCLID'S EXTENDED ALGORITHM:")
d = mult_inv(e,r)
print("END OF THE STEPS USED TO ACHIEVE THE VALUE OF 'd'.")
print("The value of d is:",d)
print("*****************************************************")
public = (e,n)
private = (d,n)
print("Private Key is:",private)
print("Public Key is:",public)
print("*****************************************************")

#Encryption
'''ENCRYPTION ALGORITHM.'''
def encrypt(pub_key,n_text):
e,n=pub_key
x=[]
m=0
for i in n_text:
if(i.isupper()):
m = ord(i)-65
c=(m**e)%n
x.append(c)
elif(i.islower()):   
m= ord(i)-97
c=(m**e)%n
x.append(c)
elif(i.isspace()):
spc=400
x.append(400)
return x


#Decryption
'''DECRYPTION ALGORITHM'''
def decrypt(priv_key,c_text):
d,n=priv_key
txt=c_text.split(',')
x=''
m=0
for i in txt:
if(i=='400'):
x+=' '
else:
m=(int(i)**d)%n
m+=65
c=chr(m)
x+=c
return x

#Message
message = input("What would you like encrypted or decrypted?(Separate numbers with ',' for decryption):")
print("Your message is:",message)

#Choose Encrypt or Decrypt and Print
choose = input("Type '1' for encryption and '2' for decrytion.")
if(choose=='1'):
enc_msg=encrypt(public,message)
print("Your encrypted message is:",enc_msg)
print("Thank you for using the RSA Encryptor. Goodbye!")
elif(choose=='2'):
print("Your decrypted message is:",decrypt(private,message))
print("Thank you for using the RSA Encryptor. Goodbye!")
else:
print("You entered the wrong option.")
print("Thank you for using the RSA Encryptor. Goodbye!")

this answer is posted by one of the expert and the issue is:

#e Value Calculation
'''FINDS THE HIGHEST POSSIBLE VALUE OF 'e' BETWEEN 1 and 1000 THAT MAKES (e,r) COPRIME.'''
for i in range(1,1000):
if(egcd(i,r)==1):
e=i
print("The value of e is:",e)
print("*****************************************************")

this certain part doesn't execute as it shows the error that r is not defined. And Can you please provide the ans with indentation? im sure im making mistake in indentation. thanks

In: Computer Science

PYTHON PLEASE!! ALSO: if you can include an explanation of what the code means that would...

PYTHON PLEASE!!

ALSO: if you can include an explanation of what the code means that would be appreciated

8.19 LAB*: Program: Soccer team roster (Dictionaries)

This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.

(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers and the ratings in a dictionary. Output the dictionary's elements with the jersey numbers in ascending order (i.e., output the roster from smallest to largest jersey number). Hint: Dictionary keys can be stored in a sorted list. (3 pts)

Ex:

Enter player 1's jersey number:
84
Enter player 1's rating:
7

Enter player 2's jersey number:
23
Enter player 2's rating:
4

Enter player 3's jersey number:
4
Enter player 3's rating:
5

Enter player 4's jersey number:
30
Enter player 4's rating:
2

Enter player 5's jersey number:
66
Enter player 5's rating:
9

ROSTER
Jersey number: 4, Rating: 5
Jersey number: 23, Rating: 4
Jersey number 30, Rating: 2
...

(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pts)

Ex:

MENU
a - Add player
d - Remove player
u - Update player rating
r - Output players above a rating
o - Output roster
q - Quit

Choose an option:

(3) Implement the "Output roster" menu option. (1 pt)

Ex:

ROSTER
Jersey number: 4, Rating: 5
Jersey number: 23, Rating: 4
Jersey number 30, Rating: 2
...

(4) Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. Append the values to the two vectors. (1 pt)

Ex:

Enter a new player's jersey number:
49
Enter the player's rating:
8

(5) Implement the "Delete player" menu option. Prompt the user for a player's jersey number. Remove the player from the roster (delete the jersey number and rating). (1 pt)

Ex:

Enter a jersey number:
4

(6) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating. (1 pt)

Ex:

Enter a jersey number:
23
Enter a new rating for player:
6

(7) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts)

Ex:

Enter a rating:
5

ABOVE 5
Jersey number: 66, Rating: 9
Jersey number: 84, Rating: 7
...

In: Computer Science

What type of application programs are not suitable for multi-threading? Explain.

What type of application programs are not suitable for multi-threading? Explain.

In: Computer Science

Using Java with NO imports,    Method arrayOfSums returns an ArrayList of the same size as...

Using Java with NO imports,

   Method arrayOfSums returns an ArrayList of the same size as the largest ArrayList
       This method needs to be overloaded so that it works for 2 to 4 sent Arraylists.

       arrayOfSums([2,4,7], [3,7,14]) returns [5,11,21]
       arrayOfSums([6,13,4,8], [7,5,9], [2,5,8,3]) returns [15, 23, 21, 11]
       arrayOfSums([6,13,4,8], [7,5,9], [2,5,8,3], [3,5,4,1,2]) returns [18, 28, 25, 12, 2]
       arrayOfSums([8,6], [2,4,10]) returns [10,10,10]
       arrayOfSums([2,2,2,2,2], [3,2,5,2,3], [1,3,1,3,1]) returns [6, 7, 8, 7, 6]
       arrayOfSums([11,12,13,14], [14,13,12,11], [10,10,10,10], [5,6,7,6,5]) returns [40, 41, 42, 41, 5]
       @param nums1 ArrayList of integers of varying sizes
       @param nums2 ArrayList of integers of varying sizes
       @param nums3 ArrayList of integers of varying sizes
       @param nums4 ArrayList of integers of varying sizes
       @return an array of the sums of the corresponding elements from each array
   */
public static ArrayList<Integer> arrayOfSums(ArrayList<Integer> nums1, ArrayList<Integer> nums2, ArrayList<Integer> nums3, ArrayList<Integer> nums4 )
{
       ArrayList<Integer> numsSums = new ArrayList<Integer>();
       return numsSums;

}// end arrayOfSums

   /**
   * Do overloaded methods here.
   * to compile, I am adding the method line.
   */

       public static ArrayList<Integer> arrayOfSums(ArrayList<Integer> nums1, ArrayList<Integer> nums2, ArrayList<Integer> nums3)
{
           ArrayList<Integer> numsSums = new ArrayList<Integer>();
        return numsSums;

}// end arrayOfSums
       public static ArrayList<Integer> arrayOfSums(ArrayList<Integer> nums1, ArrayList<Integer> nums2)
       {
           ArrayList<Integer> numsSums = new ArrayList<Integer>();
       return numsSums;
       }// end arrayOfSums

In: Computer Science

JAVA WITH NO IMPORTS Method changeWords executes a find and replace like you would with ctrl+f...

JAVA WITH NO IMPORTS

Method changeWords executes a find and replace like you would with ctrl+f
           or command+f on here
           The first value provided is the text that you search
           Turn the text into an array of strings
           find the string that is sent in the second position (find) and
           replace it with the

          changeWords("never have I ever", "ever", "cheated") returns ["never", "have", "I", "cheated"]
           changeWords("Why why Why", "Why", "because") returns ["becasue", "because", "because"]
           changeWords("What is up bro", "hi", "hello") returns ["what", "is", "up", "bro"]
           changeWords("Hi nice to meet you", "hi", "hello") returns ["hello", "nice", "to", "meet", "you"]
           changeWords( "", "", "") returns []

          @param String text, String of multiple words
           @param String find, the string to be replaced
           @param String replace, the string to be inserted in place of find
          @return String array, where words is the array of words after the edit is made
      */
public static String[] changeWords(String text, String find, String replace)
{
       //your code here
       String[] words = new String[0];//you are free to edit this line
return words;
}//end changeWords

In: Computer Science

Write a short text based game using C++ were you can chose the gender of the...

Write a short text based game using C++ were you can chose the gender of the character, than choose between two location, desert or forest. If either location is chosen than you can choose to either stay at your spot or travel to find help. If player chose desert, than choosing either to stay or travel can be led to death by heat exhaustion or saved randomized, or if forest is chosen, than it can be either death of starvation or saved also randomized. Winner lives, loser dies.

In: Computer Science

In java P4.6 Following Section 4.9 develop a program that reads text and displays the average...

In java P4.6 Following Section 4.9 develop a program that reads text and displays the average number of words in each sentence. Assume words are separated by spaces, and a sentence ends when a word ends in a period. Start small and just print the first word. Then print the first two words. Then print all words in the first sentence. Then print the number of words in the first sentence. Then print the number of words in the first two sentences. Then print the average number of words in the first two sentences. At this time, you should have gathered enough experience that you can complete the program.

In: Computer Science

Part A: Simple array algorithms With your buddy, read through this problem statement. Be sure to...

Part A: Simple array algorithms

  1. With your buddy, read through this problem statement. Be sure to read the Javadoc comments for the evenOdd method.
  2. Scribe: What is the return type of the evenOdd method?
  3. Scribe: How do you create an int array that can hold two numbers?
  4. The problem of coding the evenOdd method decomposes into three simpler problems. Scribe: What are they?
  5. Scribe: Which algorithm in section 7.3 of your textbook will be helpful?
  6. Scribe: Assuming that you have the counts for the odds and evens (say in oddCount and evenCount), what is the Java code for creating an array of length 2 and returning both counts in the array?
  7. Scribe: You really do not have to compute two counts. How can you calculate one given the other?
  8. Solve the problem in BlueJ. Make sure your code passes the test cases in this tester. Driver: Paste your code into the lab report.Part B: Removing duplicate
    public class Numbers
    {
       /**
          Computes the number of even and odd values in a given array
          @param values an array of integer values
          @return an array of length 2 whose 0 entry contains the count
          of even elements and whose 1 entry contains the count of odd
          values
       */
       public static int[] evenOdds(int[] values)
       {
          // your work here
    
    
    
       }
    }
    
    Code tester
    
    public class NumbersTester
    {
       public static void main(String[] args)
       {
          int[] a = { 1, 2, 3 };
          int[] r = Numbers.evenOdds(a);
          System.out.println(r[0] + " " + r[1]);
          System.out.println("Expected: 1 2");
          a[1] = 5;
          r = Numbers.evenOdds(a);
          System.out.println(r[0] + " " + r[1]);
          System.out.println("Expected: 0 3");
          a = new int[0];
          r = Numbers.evenOdds(a);
          System.out.println(r[0] + " " + r[1]);
          System.out.println("Expected: 0 0");
       }
    }

    Part B: Removing duplicates

    Step1
    A common typo is to accidentally duplicate a word, which can be be rather embarrassing.

    Your task is to design and implement a program that removes adjacent duplicates. This class reads a file and puts all words into an ArrayList<String> called words. Your task is to complete the method removeAdjacentDuplicates to remove all adjacent duplicates in words. Develop a plan and write pseudocode for this task. Questions to think about. Scribe: How do you plan to find duplicates? Scribe: What will you do when you find them? Pay special attention to what happens at the beginning or end of the array list. Show your lab instructor your pseudocode before doing the next step.

    Step 2
    Implement your solution. To test, download and unzip this zip file. Copy each file into the same directory that contains your BlueJ project. Do not copy the folder.

    You must unzip the zip file. Don't simply move the zip into your BlueJ directory.

    Make a Text object on the BlueJ workbench. Right-click and call pick. Pick the file typo.txt. Right-click and call removeAdjacentDuplicates (i.e. your method). Right-click and call explore. . Scribe: Is the duplicate “be” removed?

    Step 3
    Run this tester. Scribe: Did you pass all tests? If not, what did you do to fix your code?

    Driver: In your lab report, paste the correct solution.

    Step 4
    Now suppose you want to remove all duplicates, whether adjacent or not. The result will be a list of unique words. For example, if the array list contains these immortal words

    Mary had a little lamb little lamb little lamb
    Mary had a little lamb whose fleece was white as snow
    And everywhere that Mary went Mary went Mary went
    And everywhere that Mary went the lamb was sure to go

    you should produce the array list

    Mary had a little lamb
    whose fleece was white as snow
    And everywhere that went
    the sure to go

    Decide upon an algorithm and write down the pseudocode.

    Scribe: Ask yourselves:

  9. How do we know when a word is duplicated?
  10. Should we first check for duplication, or should we proactively remove all duplicates of every word?
  11. How can we be sure to leave one copy of the word in place?
  12. How do we remove all those duplicates?
  13. When removing a word and traversing an array at the same time, how does that affect the array index?
  14. Step 5
    When you are satisfied that you can implement it, add a method removeAllDuplicates to the Text class.

    Implement the method and test it as described above.

    Step 6
    Run this tester.

    Scribe: Did you pass all tests? If not, what did you do to fix your code

    Step 7
    Driver: In your lab report, paste the correct solution.

    Part C: Swapping

    Step 1
    Run this program.

    The code on lines 20 to 24 is intended to swap neighboring elements. For example,

    1 4 9 16 25 36

    is supposed to turn into

    4 1 16 9 36 25

    But as you can see, it doesn't work. Now launch the BlueJ debugger. Put a breakpoint at line 20. Click Step. And then keep clicking Step and observe the program behavior until you can tell why it fails to swap the values.

    Tip: To see the contents of the array, double-click on it in the Local Variables pane.

    Step 2
    Discuss what you learned from observing the program

    How you can fix your program so that the swapping actually works? Scribe: What did you decide?

    Step 3
    Implement your fix and test it.

    Driver: Put the fixed code in your lab report.

    Part D: More Swapping with Pictures

    Step 1
    Unzip this file and open the project in BlueJ. Run the program.

    Look at the main method in the Lab11D class. Note that a VisualArrayList is exactly like an ArrayList, except it shows you in slow motion what goes on inside.

    Step 2
    Come up with an algorithm for the following task. We want to swap the first half and the second half of the array list.

    For example, A B C D E F should turn into D E F A B C.

    You should assume that the array list has an even number of elements (not necessarily 6).

    One solution is to keep removing the element at index 0 and adding it to the back.

    A B C D E F
    B C D E F A
    C D E F A B
    D E F A B C

    Write pseudocode for this algorithm.

    Ask yourselves:

  15. Which actions need to be carried out in each loop iteration?
  16. How many iterations are there (for arbitrary even lengths, not necessarily 6)
  17. Which actions need to be carried out in each loop iteration?
  18. How do you know the positions of the elements to be swapped?
  19. How many iterations are there (for arbitrary even lengths, not necessarily 6)
  20. Step 5
    Implement your pseudocode and run it.

    Driver: Paste the main method into your lab report. Watch how much faster it runs. (This should be pretty obvious since the movement of the array elements takes time.)

    Add four more letters and run the program again to double-check that it works with any even number of letters.

    Step 3
    Implement your pseudocode and run it.

    Driver: Paste the main method into your lab report.

    Step 4
    When you run the code, you will find that there is a lot of movement in the array. Each call to remove(0) causes n - 1 elements to move, where n is the length of the array. If n is 100, then you move 99 elements 50 times, (almost 5000 move operations). That's an inefficient way of swapping the first and second halves.

    Come up with a better way in which you swap the elements directly. Hint: How do you swap elements at index1 and index2?

    A B C D E F
    D B C A E F
    D E C A B F
    D E F A B C

    Write pseudocode for this algorithm.

    Ask yourselves (Scribe: record the answers):

In: Computer Science

Code with Java and no imports, Method sandwiched returns true if num is in the element...

Code with Java and no imports, Method sandwiched returns true if num is in the element before and after an element that is not equal to num

sandwiched([4,5,4,6,7,3], 4) returns true

sandwiched([2,1,2], 2) returns true

sandwiched([3,3,3], 3) returns false

sandwiched([4,5,6,4], 4) returns false

sandwiched([1,1,2,3,1,4,1], 1) returns true

@param nums Integer ArrayList

@param num integer

@return true if a single number is between elements equal to num

*/ public static boolean sandwiched(ArrayList nums, int num) {

return false;

}//end sandwiched

In: Computer Science

write a java program that implements the splay tree data structure for the dictionary abstract data...

write a java program that implements the splay tree data structure for the dictionary abstract data type.

Initially the program reads data from "in.dat", and establishes an ordinary binary search tree by inserting the data into the tree. The data file contains integers, one per line.

in.dat file contents:

3456
5678
1234
2369
7721
3354
1321
4946
3210
8765

Then the program starts an interactive mode. The commands are as follows.

S 1000 - splay the tree at 1000

F 2000 - search/find the node with key 2000

I 3000 - insert a node with key 3000

D 4000 - delete the node with key 4000

For each command,

1. Report appropriate message after the command is executed. Examples are:

Splay is done

Search is successful

Search is unsuccessful

The key is inserted into the tree

Duplicated keys

The key is deleted from the tree

The key is not in the tree

2. Display the new tree.

In: Computer Science

if this is considered more than one question then please explain part 'I' (Find the exact...

if this is considered more than one question then please explain part 'I' (Find the exact value of f100, f500, and f1000, where fn is the nth Fibonacci number. What are times taken to find out the exact values?). I am having trouble writing the code for both recursive and iterative functions without having the program crash. I assume its because the numbers are so high.

Goal: The main goal of the project is to let students use their prior knowledge, try to use the skills they have learnt to solve real world problems. Using this assignment students are required to learn to use the skills they have learned in their previous classes, solve the problems given and reflect on how they can apply it to solve real world issues.

Deliverables: The students are required to submit a written report along with the programs they have written. The report has to address all the prompts mentioned under the Report section. The report should be properly presented by using appropriate font (Time new roman, preferably font size 12 till 16) and grammar.

Tasks:

  1. Write an iterative C++ function that inputs a nonnegative integer n and returns the nth Fibonacci number.
  2. Write a recursive C++ function that inputs a nonnegative integer n and returns the nth Fibonacci number.
  3. Compare the number of operations and time taken to compute Fibonacci numbers recursively versus that needed to compute them iteratively.
  4. Use the above functions to write a C++ program for solving each of the following computational problems.
  1. Find the exact value of f100, f500, and f1000, where fn is the nth Fibonacci number. What are times taken to find out the exact values?
  2. Find the smallest Fibonacci number greater than 1,000,000 and greater than 1,000,000,000.
  3. Find as many prime Fibonacci numbers as you can. It is unknown whether there are infinitely many of these. Find out the times taken to find first 10, 20, 30, 40…up to 200 and draw a graph and see the pattern.

Report: Your report should address all of the below mentioned questions

  1. Describe the Fibonacci series and write briefly what you have done in the assignment.
  2. What are the different skills, programming techniques have you used in order to run the experiments?
  3. What did you observe when you did the comparisons in Task 3 and Task 4? Explain the graph that you have drawn from Task 4.III?
  4. List at least three different applications of the Fibonacci numbers to sciences and describe one of them in details. Think of situation or a real world problem where you can apply concept of Fibonacci numbers to solve it. Explain?
  5. Write a paragraph, explaining what you have done in this assignment. What were the challenges you have faced when solving these problems. How can you improve the programs you have written to solve these problems? How can you use what you have learned going forward?

In: Computer Science

Java, no imports: Given a list of integers, round each number to the nearest multiple of...

Java, no imports:

Given a list of integers, round each number to the nearest multiple of 5.
       2.5-7.49 round to 5. 7.5-12.49 round to 10. 12.5-17.49 round to 15. etc.
       return the sum of all the rounded elements.
       Implement this way for credit:
       Fill in the method directly below this one called helperRound() to round each number.

Call that method and use the sum of the returned values.

       helperSum({4.3, 16.7}) returns 20
       helperSum({25.7, 21.2, 27.5}) returns 75
       helperSum({2.5}) returns 5
       helperSum({2.49, 12.49, 40.2, 42.5}) returns 95
       @param nums is an arrayList of doubles
       @return the sum of the all elements after rounding
   */
public static int helperSum(ArrayList<Double> nums)
{
       int sum = 0;
       return sum;
}//end helperSum

   /**
        Method HelperRound will round a number up or down to the nearest 5.

        @param num double number,
        @return the rounded up or down number to the nearest multiple of 5.
    */
public static int helperRound(double n){
           int rounded = 0;

           return rounded;
}//end HelperRound

In: Computer Science

Write a brief summary describing any encryption method not already mentioned in this chapter. In this...

Write a brief summary describing any encryption method not already mentioned in this chapter. In this summary, describe the history and origin of the algorithm. Compare the efficacy of this algorithm to other well-known algorithms.

Blowfish, AES, RC4, Serpent,3DES, RSA, PGP, Hashing, SHA, MD5 These are the method are already mentioned in this chapter.

In: Computer Science