Questions
5.30 Develop the function many() that takes as input the name of a file in the...

5.30 Develop the function many() that takes as input the name of a file in the current directory (as a string) and outputs the number of words of length 1, 2, 3, and 4. Test your function on file sample.txt.

>>> many('sample.txt')

Words of length 1 : 2

Words of length 2 : 5

Words of length 3 : 1

Words of length 4 : 10

Coding language is python

In: Computer Science

HI, ANY PROGRAMMING LANGUAGE WOULD WORK, FROM PYTHON TO C++, MOST PREFERABLY OR ELSE ANY FOR...

HI, ANY PROGRAMMING LANGUAGE WOULD WORK, FROM PYTHON TO C++, MOST PREFERABLY OR ELSE ANY FOR YOUR CONVENIENCE.

Let f(x) = x6 + 7x5− 15x4− 70x3 + 75x2 + 175x − 125.

a.) Write a program that carries out the Secant Method on f(x). You do not need to make your program take arbitrary

input (i.e. you can tailor it to this specific f(x)). Your program should take as input the appropriate number of initial

guesses, an interval [a, b] and a desired error tolerance TOL. It should output a root r that is within the desired

tolerance and it should output N, the number of iterations it took to get to within the error tolerance. Make it clear

what procedure you are using to compute the error of your approximations.

b.)  Write a program that carries out Steffensen′s Method on f(x). You do not need to make your program take arbitrary

input (i.e. you can tailor it to this specific f(x)). Your program should take as input the appropriate number of

initial guesses, an interval [a, b] and a desired error tolerance TOL. It should output a root r that is within the

desired tolerance and it should output N, the number of iterations it took to get to within the error tolerance. Make

it clear what procedure you are using as your underlying recursion, and how you are computing the error of your

approximations.

c.) Write a program that carries out Aitken′s Method on f(x). You do not need to make your program take arbitrary input

(i.e. you can tailor it to this specific f(x)). Your program should take as input the appropriate number of initial guesses,

an interval [a, b] and a desired error tolerance TOL. It should output a root r that is within the desired tolerance and

it should output N, the number of iterations it took to get to within the error tolerance. Make it clear what procedure

you are using as your underlying recursion, and how you are computing the error of your approximations.

d.) Write a program that carries out Newton′s Method on f(x). You do not need to make your program take arbitrary

input (i.e. you can tailor it to this specific f(x)). Your program should take as input the appropriate number of initial

guesses, an interval [a, b], and a desired error tolerance TOL. It should output a root r that is within the desired

tolerance and it should output N, the number of iterations it took to get to within the error tolerance. Make it clear

what procedure you are using to compute the error of your approximations

In: Computer Science

Write a program in MIPS Assembly. This program will ask the user to enter 20 numbers....

Write a program in MIPS Assembly.

This program will ask the user to enter 20 numbers. The program will store these numbers in an array in memory (sequential memory locations). It will then print out the list of numbers in three different formats:

  1. The numbers will be printed each on a separate line.
  2. The numbers will be printed on a single line, with spaces between the numbers.
  3. The program will ask the user to enter a number n. The program will then print the list with n numbers on each line. For example, if the user enters '3', the program will print the first three numbers of the list on the first line, the second three numbers on the second line, and so on.

Also, check for any wrong inputs and handle the error.

In: Computer Science

Translate the code in translateMe.c to MIPS in a file called translated.asm.Make sure you run both...

Translate the code in translateMe.c to MIPS in a file called translated.asm.Make sure you run both versions of the programto see that they get the same result.

Code:

int main() {
// use $t0 for x
int x = 0xC0FFEE00;
  
// use $t1 for y
unsigned int y = 0xC0FFEE00;

// use $t2 for z
int z = (x >> 8) & 0xFF;

// use $t3 for w
int w = ((y | 0xFF000000) << 6) ^ 0xFF;
}

In: Computer Science

What do these regular expressions mean in plain english? a) ba*b + (ab)* b) a*b* +...

What do these regular expressions mean in plain english?

a) ba*b + (ab)*

b) a*b* + b*ab

In: Computer Science

##You have received the phone bill. ##You have 4 phones on your family plan. ##You think...

##You have received the phone bill.

##You have 4 phones on your family plan.

##You think that some members of the

##family are using too much data.

##

##You would like to calculate the following

##for each of the family members:

##  lowest number of minutes used

##  highest number of minutes used

##  average number of minutes used

##

##The following list (named phonebill) consists

##of 4 lists, each detailing the name of the family

##member, the number of minutes that family member

##used during the week (7 days) and the phone

##number of that person

phonebill = [

  ["Kiera", [11,21,13,14,15,60,38], "508-111-1110"],

  ["Lorenzo", [20,12,33,26,37,62,70],"508-111-1111"],

  ["Mabel", [31,27,43,7,52,68,5],"508-111-1112"],

  ["Nikolai", [8,7,212,28,114,30,39],"508-111-1113"]

  ]

##you are to calculate the following for each family

##member and append it to the list of information

##for that family member:

##  lowest number of minutes used

##  highest number of minutes used

##  average number of minutes used

##The list phonebill will be as follows after your program executes

[['Kiera', [11, 21, 13, 14, 15, 60, 38], '508-111-1110', 11, 60, 24.571428571428573],

['Lorenzo', [20, 12, 33, 26, 37, 62, 70], '508-111-1111', 12, 70, 37.142857142857146],

['Mabel', [31, 27, 43, 7, 52, 68, 5], '508-111-1112', 5, 68, 33.285714285714285],

['Nikolai', [8, 7, 212, 28, 114, 30, 39], '508-111-1113', 7, 212, 62.57142857142857]

]

Please done in Python format

In: Computer Science

Question: Properly convert the solution to this problem from Java to C++ Problem Statement If you...

Question: Properly convert the solution to this problem from Java to C++

Problem Statement

If you want to write a message anonymously, one way to do it is to cut out letters from headlines in a newspaper and paste them onto a blank piece of paper to form the message you want to write. Given several headlines that you have cut out, determine how many messages from a list you can write using the letters from the headlines. You should only consider each message by itself and not in conjunction with the others, see example 2.

Write the function how_many which takes as parameters a vector<string> headlines containing the headlines which you have cut out as well as a vector<string> messages with the messages you may want to write, and returns an int which is the total number of messages you can write.

Constraints

  • All letters that you cut out can be used both as upper or lower case in a message.
  • Spaces should be ignored in elements in both headlines and messages.
  • headlines will contain between 1 and 50 elements, inclusive.
  • messages will contain between 1 and 50 elements, inclusive.
  • The length of each element in headlines will be between 1 and 50 characters, inclusive.
  • The length of each element in messages will be between 1 and 50 characters, inclusive.
  • Each element in headlines will only contain the letters 'A'-'Z', 'a'-'z' and space.
  • Each element in messages will only contain the letters 'A'-'Z', 'a'-'z' and space.

Examples

  1. headlines =
    
    {"Earthquake in San Francisco",
     "Burglary at musuem in Sweden",
     "Poverty"}
    
    messages =
    
    {"Give me my money back",
     "I am the best coder",
     "TOPCODER"}
    
    Returns: 2
    

    In the first message we have three 'm's, but there are only two 'm's among the headlines (both in the word "museum"), so this message can't be written.

    The second message can be written. Note that the first letter, 'I', only appears as lower case in the headlines, but that's allowed. The last message can also be written, so the method should return 2.

  2. headlines = 
    
            {"Programming is fun"}
    
    messages = 
    
            {"program","programmer","gaming","sing","NO FUN"}
    
    Returns: 4
    

    The messages "program", "gaming", "sing" and "NO FUN" can all be written but not "programmer" (no 'e's exist). The method should return 4.

  3. headlines = 
    
       {"abcdef","abcdef"}
    
    messages = 
    
       {"AaBbCc","aabbbcc","   ","FADE"}
    
    Returns: 3
    

    All messages except the second one can be written, because it contains three 'b's but there are only two 'b's available. Also note the message only containing spaces - such a message can of course always be written.

Given Function

#include <vector>
#include <string>

int how_many(vector<string> headlines, vector<string> messages) {
// fill in code here
}

Solution (Convert the Java code below to C++).

import java.util.*;

public class Anonymous {
      public int howMany(String[] headlines, String[] messages) {
          
    
          HashMap<Character, Integer> lettersAvailable = countLetters(headlines);

          int wordsWeCanMake = 0; 
          for(String message : messages){
                  String[] oneMessage = {message}; 
                  HashMap<Character, Integer> lettersNeeded = countLetters(oneMessage);
                  boolean canMakeMessage = true;
                  Iterator it = lettersNeeded.entrySet().iterator(); 
                  while (it.hasNext()){
                          Map.Entry pairs = (Map.Entry)it.next();
                          char key = (Character) pairs.getKey(); 
                          if(!(key==' ')){
                                  int numNeeded = (Integer) pairs.getValue();
                                  if(lettersAvailable.containsKey(key)){
                                          int numAvailable = lettersAvailable.get(key); 
                                          canMakeMessage = (numNeeded <= numAvailable) && canMakeMessage;
                                  }
                                  else{
                                          canMakeMessage = false ; 
                                          break;
                                  }
                          }
                          
                      it.remove();
                  }
                  if(canMakeMessage){
                          wordsWeCanMake += 1; 
                  }
          }
          return wordsWeCanMake; 
      }
      
      public HashMap<Character, Integer> countLetters(String[] words){
          HashMap<Character, Integer> counts = new HashMap<Character, Integer>();
          int currentCountOfLetter = 0;
          
          for(String word : words){  
                  for(int i=0; i<word.length(); i++){
                          char letter = Character.toLowerCase(word.charAt(i));
                          if (counts.containsKey(letter)){
                                  currentCountOfLetter = counts.get(letter);
                                  currentCountOfLetter +=1; 
                          }
                          else {
                                  currentCountOfLetter = 1;
                          }
                          counts.put(letter, currentCountOfLetter); 
                  }
          }
          
          return counts; 
      }
      }
}

In: Computer Science

You have a theory that certain days of the week are most likely to be the...

You have a theory that certain days of the week are most likely to be the highest sales You are to write a program that will test that theory.

Write a program that will have a list of 52 lists, each of those 52 lists must be of length 7 (that is they will each accommodate 7 items). Think of 52 weeks with 7 days in each week. Save a random value from 70 - 100 (inclusive of 70, exclusive of 100) in each of the days of each of the weeks.

Your code should analyze the list above and print a list of the number of times each day of the week had the highest sales. If more than one day had the highest sales of the week I do not care which of those days is recorded as the highest sales day.

Here is an example of the expected output: note that in the example below I generated and analyzed 5 weeks, you are to generate and analyze 52 weeks:

My code generated and output the following list of lists:

[[93, 98, 95, 75, 81, 88, 97], [91, 76, 81, 84, 72, 97, 83], [91, 81, 75, 72, 92, 95, 79], [98, 93, 88, 74, 93, 97, 82], [77, 86, 90, 87, 75, 84, 95]]

And output the following list after analysis of the above list:

[1, 1, 0, 0, 0, 2, 1]

The actual output from running my code was:

RESTART: /Users/janetbrownsederberg/Stonehill/Stonehill_Fall2020/HighestSales.py

[[93, 98, 95, 75, 81, 88, 97], [91, 76, 81, 84, 72, 97, 83], [91, 81, 75, 72, 92, 95, 79], [98, 93, 88, 74, 93, 97, 82], [77, 86, 90, 87, 75, 84, 95]]

[1, 1, 0, 0, 0, 2, 1]

>>>

Please have your output in the form above.

Please done in Python format

In: Computer Science

Describe how the Hypertext Markup Language (HTML) and Extensible Markup Language (XML) would be utilized in...

Describe how the Hypertext Markup Language (HTML) and Extensible Markup Language (XML) would be utilized in relation to your e-business and the related user Web interfaces. Also indicate the relationship between XML and the Extensible Business Reporting Language (XBRL). How do you envision using XBRL in relation to your e-business? Finally, what role does XML play in the Semantic Web project discussed in this module?

In: Computer Science

An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum...

An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum = 4.

Consider the following set of processes in this OS, with the length of the CPU burst time given in milliseconds, and the shown priority.

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.

Process Burst Time Priority
P1 5 2
P2 10 5
P3 4 1
P4 6 4
P5 9 3

a) Draw a Gantt chart illustrating the order of execution of these processes, showing their completion times.

b) Calculate each process’ waiting time, and then compute the average waiting time for this set.

Note:  waiting time = completion time – arrival time – burst time

=> Write your answers on scratch paper (make sure it is visible) then take a picture of it and upload it here.

In: Computer Science

1. In R Studio create a plot with two subplots (2 rows, 1 column): a). Display...

1. In R Studio create a plot with two subplots (2 rows, 1 column):

a). Display five Gaussian pdf curves for the six mean/standard deviation pairs (0, 1), (0, 2), (0, 3), (1, 1), (1, 2), (1.3) in the upper subplot using distinct colors for each curve.
b). Repeat the same procedure for corresponding cdfs in the lower plot.

In: Computer Science

apply following to body of the page in css format 1. background color of rgb(145,215,170) 2....

apply following to body of the page in css format

1. background color of rgb(145,215,170)


2. width to 65% of the page

3. center the body using the margin property

4. assign a font family of Georgia, Times, serif

In: Computer Science

Should you be bought and sold or not.... a). What constraints should there be on the...

Should you be bought and sold or not....

a). What constraints should there be on the gathering of information on users? With or without their permission? If with their permission, opt-in or opt-opt? b). How about exchanging the information that has been gathered? Any constraints on the use of that data?

In: Computer Science

Apply following to header and footer sections of page in css center text background color rgb(254,198,179)...

Apply following to header and footer sections of page in css

center text

background color rgb(254,198,179)

padding should be 20px

In: Computer Science

The following program uses Pthreads to create two threads. They do some work for the process...

The following program uses Pthreads to create two threads. They do some work for the process and then exit. The process then outputs a result.

Assume all supporting libraries and other functions have been included.

=> Use the answer text field to describe what work (operations) the threads are doing, and what kind of result (what is it?) is output by the process.

#include <pthread.h>

#include <stdio.h>

#include <stdlib.h>

int res1, res2, a[100], b[100];

void *runner1(void *param);

void *runner2(void *param);

void readData(int []);


int main(int argc, char *argv[])

{

  pthread_t tid1, tid2;

  pthread_attr_t attr;


  readData(a);

  readData(b);

  pthread_attr_init(&attr);

  pthread_create(&tid1, &attr, runner1, argv[1]);

  pthread_create(&tid2, &attr, runner2, argv[1]);

  pthread_join(tid1,NULL);

  pthread_join(tid2,NULL);

  printf("result = %d\n", res1+res2);

}

void *runner1(void *param)

{

  int i, upper = atoi(param);

  res1 = 0;

  for (i = 0; i < upper; i++)

    res1 += a[i];

  pthread_exit(0);

}

void *runner2(void *param)

{

  int i, upper = atoi(param);

  res2 = 0;

  for (i = 0; i < upper; i++)

    res2 += b[i];

  pthread_exit(0);

}

In: Computer Science