Questions
Write a program that accepts a number of minutes and converts it to days and hours....

Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values.

Save the file as  MinuteConversionWithExceptionHandling.java

In: Computer Science

This problem is adapted from Exercise 37 of Langtangen’s “A Primer on Scientific Programming with Python”....

This problem is adapted from Exercise 37 of Langtangen’s “A Primer on Scientific Programming with Python”.

Simulating gas particles in a closed space is something you can do with a Monte Carlo type simulation – simulate a period of time (using a loop) and “move” particles around (change values for (x,y) coordinates) for each unit of time. This kind of simulation is called a “random walk”.

Download the file randomwalk.py(i posted it below). This implements a Monte Carlo simulation for a random 2-dimensional walk. It uses numpy arrays, but it does not use them idiomatically.

Your task for this exercise is to change this program to use numpy arrays idiomatically. That is, the block

for i in range(np):
    direction = random.randint(1, 4)
    if direction == NORTH:
        ypositions[i] += 1
    elif direction == SOUTH:
        ypositions[i] -= 1
    elif direction == EAST:
        xpositions[i] += 1
    elif direction == WEST:
        xpositions[i] -= 1

should be rewritten to use numpy arrays of random integers.

Below is randomwalk.py

import random
random.seed(10122019)
import numpy
import matplotlib.pyplot as plt

def random_walk_2D(np, ns):
# xpositions = numpy.zeros(size=np) #### part 1
# ypositions = numpy.zeros(size=np)
positions = numpy.zeros(size=(np, 2)) #### part 2
# extent of the axis in the plot:
xymax = 3*numpy.sqrt(ns); xymin = -xymax

for _ in range(ns):
for i in range(np):
direction = random.randint(1, 4)
if direction == NORTH:
ypositions[i] += 1
elif direction == SOUTH:
ypositions[i] -= 1
elif direction == EAST:
xpositions[i] += 1
elif direction == WEST:
xpositions[i] -= 1
# xpositions += numpy.random.randint(-1, 2, size=np) #### part 1
# ypositions += numpy.random.randint(-1, 2, size=np) #### part 1
positions += numpy.random.randint(-1, 2, size=(np, 2)) #### part 2

# plt.plot(xpositions, ypositions, 'ko') #### part 1
plt.plot(positions[:,0], positions[:,1], 'ko') #### part2
plt.axis([xymin, xymax, xymin, xymax])
plt.title('{particles} particles after {steps} steps'.format(particles=np, steps=ns))
plt.savefig('tmp_{steps}.pdf'.format(steps=ns))
  
return positions[:,0], positions[:,1]

np = 100 # number of particles
ns = 100 # number of steps
x, y = random_walk_2D(np, ns)

In: Computer Science

Question Objective: The purpose of this lab is for you to become familiar with Python’s built-in...

Question

Objective:

The purpose of this lab is for you to become familiar with Python’s built-in text container -- class str -- and lists containing multiple strings. One of the advantages of the str class is that, to the programmer, strings in your code may be treated in a manner that is similar to how numbers are treated. Just like ints, floats, a string object (i.e., variable) may be initialized with a literal value or the contents of another string object. String objects may also be added together (concatenation) and multiplied by an integer (replication). Strings may also be compared for “equality” and arranged into some order (e.g., alphabetical order, ordering by number of characters, etc.). Finally, strings may be placed in containers which can then be passed as arguments to functions for more complex manipulations.

Specifications:

Write an interactive Python program composed of several functions that manipulate strings in different ways. Your main() function prompts the user for a series of strings which are placed into a list container. The user should be able to input as many strings as they choose (i.e., a sentinel-controlled loop). Your main function will then pass this list of strings to a variety of functions for manipulation (see below).

The main logic of your program must be included within a loop that repeats until the user decides he/she does not want to continue processing lists of strings. The pseudo code for the body of your main() function might be something like this:

# Create the main function

def main():

# declare any necessary variable(s)

# // Loop: while the user wants to continue processing more lists of words

#

# // Loop: while the user want to enter more words (minimum of 8)

# // Prompt for, input and store a word (string) into a list # // Pass the list of words to following functions, and perform the manipulations

# // to produce and return a new, modified, copy of the list.

# // NOTE: None of the following functions can change the list parameter it

# // receives – the manipulated items must be returned as a new list.

#

# // SortByIncreasingLength(…)

# // SortByDecreasingLength(…)

# // SortByTheMostVowels(…)

# // SortByTheLeastVowels(…)

# // CapitalizeEveryOtherCharacter(…)

# // ReverseWordOrdering(…)

# // FoldWordsOnMiddleOfList(…)

# // Display the contents of the modified lists of words

#

# // Ask if the user wants to process another list of words

Deliverable(s):

Your deliverable should be a Word document with screenshots showing the sample code you have created, and discuss the issues that you had for this project related to AWS and/or Python IDE and how you solved them.

Submit the program you develop including captured output. Also turn in screen captures from running your program inputting, as a minimum, three (3) sets word lists (no fewer than 8 words per list).

In: Computer Science

Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...

Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the following sets of values:

18 6
16 5
5 11
21 4
2 16
17 2
0 10
10 0
20 5
6 6
0 0

Hand in the program with output.

In: Computer Science

Jojo is given N integers, A1, A2, ..., AN by his teacher. His teacher also give...

Jojo is given N integers, A1, A2, ..., AN by his teacher. His teacher also give him 2M integers, L1,L2,...,LM and R1,R2,...,RM. For each i from 1 to M, his teacher asked him to calculate the sum of odd index numbers from index Li to Ri. For example if Li = 3 and Ri = 7, then he has to calculate the value of (A3 + A5 + A7). Help him by making the program to calculate it quickly!

Format Input

The first line consist of two integers, N and M. The second line consist of N integers, A1, A2, ..., AN . The next M lines consist of two integers, Li and Ri.

Format Output

Output M lines, the answer for Li and Ri, where i is an integer from 1 to M. Constraints

• 1 ≤ N, M ≤ 105 • 1≤Ai ≤102
• 1≤Li ≤Ri ≤N

Sample Input 1 (standard input)

53
13 7 1 5 9 11
22
25

Sample Output 1 (standard output)

13 0 10

please use c/c++ language

In: Computer Science

In basic C++ Create a function that takes in a vector, sorts it, then outputs to...

In basic C++

Create a function that takes in a vector, sorts it, then outputs to the console the result.

In: Computer Science

#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int...

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int QUIZSIZE = 10;
const int LABSIZE = 10;
const int PROJSIZE = 3;
const int EXAMSIZE = 3;

float getAverage(float arr[], int size)
{
float total = 0;
for (int i = 0; i < size; i++)
{
total += arr[i];
}
return total/size;
}

// the following main function do....
int main()
{
ifstream dataIn;
string headingLine;
string firstName, lastName;
float quiz[QUIZSIZE];
float lab[LABSIZE];
float project[PROJSIZE];
float midExam[EXAMSIZE];
float finalExam;
float attendance;

// open the file
dataIn.open("grade120.dat");

//exception for file open
if (dataIn.fail())
{
cout << "File open error!" << endl;
return 0;
}

// read the first two lines
for (int i = 1; i <= 2; i++)
{
getline(dataIn,headingLine);
cout << headingLine << endl;
}

while (!dataIn.eof())
{

//read student's score from the file
dataIn >> firstName;
dataIn >> lastName;

for (int i = 0; i < QUIZSIZE; i++)
{
dataIn >> quiz[i];
}
for (int i = 0; i < LABSIZE; i++)
{
dataIn >> lab[i];
}
for (int i = 0; i < PROJSIZE; i++)
{
dataIn >> project[i];
}
for (int i = 0; i < EXAMSIZE; i++)
{
dataIn >> midExam[i];
}
dataIn >> finalExam;
dataIn >> attendance;
cout << "Average quiz is " << getAverage(quiz,QUIZSIZE) << endl;
cout << "Average lab is " << getAverage(lab,LABSIZE) << endl;

// call another function to calculate the final greade letter

//write the name + letter to a file

dataIn.close();
return 0;
}

Finish the C++ program below based on

(0 <= F < 60, 60 <= D < 70, 70 <= C< 80, 80 <= B < 90, 90 <= A <= 100)

THE RULES: · You need to have a total grade >=90 and average in projects >= 90 to get an A; · You need to have a total grade >=80 and < 90, and average in projects >=80 to get a B; · You need to have a total grade is >=70 and < 80, and average in projects >=70 to get a C. Poor attendance will be penalized by up to 10% of the final total grade. The grades of all the students and attendance

penalty are stored in an external file called grade120.dat. which will be given

First Last Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 L0 L1 L2 L3 L4 L5 L6 L7 L8 L9 P0 P1 P2 E0 E1 E2 FI ATT

------------------------------------------------------------------------------------------------------------------------------------------

Kevin Smith 90 100 100 100 98 97 87 100 85 87 89 100 100 100 100 90 100 98 90 100 98 98 98 90 90 98 88 0.00

Morgan Kelly 80 100 65 67 69 71 100 100 100 67 95 85 87 89 100 65 67 69 71 100 98 98 98 65 67 69 71 0.10

Isaac Newton 100 90 100 90 100 90 100 90 100 100 100 100 100 100 100 100 100 100 100 100 98 98 98 90 90 98 88 0.00

Cole Jones 100 100 100 87 73 75 77 79 81 87 89 91 73 75 77 79 81 100 100 100 98 100 65 67 69 71 63 0.05

Angela Allen 100 100 100 87 89 91 93 95 100 100 100 100 100 100 100 95 97 100 98 98 98 90 73 75 77 79 81 0.02

David Cooper 56 58 60 62 64 100 100 100 87 73 75 77 100 100 77 79 81 100 100 100 98 70 72 74 76 78 88 0.00

Nancy Bailey 100 87 89 91 93 95 100 100 100 100 100 100 91 93 95 97 100 98 100 100 98 98 98 90 90 98 88 0.00

Emily Synder 65 67 69 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81 74 76 78 90 90 74 76 98 88 0.00

Lori Austin 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 98 98 90 90 98 88 0.02

Jenny Howard 56 58 60 62 71 62 64 73 100 66 68 70 72 74 76 78 100 100 100 60 62 79 66 68 70 68 70 0.03

Anne Lewis 100 86 58 60 100 71 62 64 73 94 66 68 90 72 74 76 78 67 68 69 70 71 98 88 76 78 68 0.04

Nick Johnson 100 100 89 91 73 75 77 79 81 100 100 100 98 100 100 95 85 87 89 100 98 98 98 80 76 78 98 0.01

Nick Spickler 100 93 95 97 100 98 98 98 90 100 89 91 93 95 97 100 100 89 91 93 95 97 98 98 90 90 98 0.00

Joy Williams 75 77 58 60 62 79 66 68 70 72 81 100 100 71 62 64 73 94 66 98 90 90 98 68 90 88 77 0.00

Barbara Hood 100 67 95 85 87 89 91 93 95 97 85 87 100 100 100 71 62 64 73 94 66 68 98 98 90 90 88 0.00

Joe Hoarn 62 63 64 65 66 67 68 69 70 71 100 81 100 100 71 62 64 73 100 100 98 98 64 73 94 66 68 0.08

Payton Bardzell 100 100 100 97 87 67 95 85 87 89 91 93 95 97 100 100 100 95 85 87 89 100 98 90 90 78 98 0.00

Kim Ludwig 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81 100 100 79 66 68 70 72 98 98 90 90 98 0.09

Susan Honks 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 90 90 88 100 100 100 100 0.00

The out put must be

First Name Last Name Final Grade

Nick Johnson A

Anne Lewis B

finish the program please

In: Computer Science

This is a python program. Put comments explaining the code, please. Suppose you have been tasked...

This is a python program. Put comments explaining the code, please.

Suppose you have been tasked with writing a Python program (using linked lists) to keep track of computer equipment. For each piece of equipment, we track its name, purchase date, purchase amount, and quantity on hand. Write a program that completes the following tasks:

allow the user to add a piece of equipment to the front of the list;

allow the user to update the quantity of a piece of equipment;

calculate and display (to the screen) the total value (in dollars) of ALL inventory

In: Computer Science

Computing A Raise File Salary.java contains most of a program that takes as input an employee’s...

Computing A Raise

File Salary.java contains most of a program that takes as input an employee’s salary and a rating of the employee’s performance and computes the raise for the employee. This is similar to question #3 in the pre-lab, except that the performance rating here is being entered as a String—the three possible ratings are “Excellent”, “Good”, and “Poor”. As in the pre-lab, an employee who is rated excellent will receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise.

Add the if... else... statements to program Salary to make it run as described above. Note that you will have to use the equals method of the String class (not the relational operator ==) to compare two strings (see Section 5.3, Comparing Data).

// ************************************************************
  • // Salary.java //

  • //    Computes the amount of a raise and the new
    
  • // salary for an employee. The current salary

  • //    and a performance rating (a String: "Excellent",
    
  • // "Good" or "Poor") are input.
    // ************************************************************

import java.util.Scanner; import java.text.NumberFormat;

public class Salary
{
public static void main (String[] args)
{

}

double currentSalary;
double raise;
double newSalary;
String rating;
// employee's current  salary
// amount of the raise
// new salary for the employee
// performance rating

Scanner scan = new Scanner(System.in);

System.out.print ("Enter the current salary: ");
currentSalary = scan.nextDouble();
System.out.print ("Enter the performance rating (Excellent, Good, or Poor): "); rating = scan.next();

// Compute the raise using if ... newSalary = currentSalary + raise;

// Print the results
NumberFormat money = NumberFormat.getCurrencyInstance(); System.out.println();
System.out.println("Current Salary: " + money.format(currentSalary)); System.out.println("Amount of your raise: " + money.format(raise)); System.out.println( "Your new salary: " + money. format (newSalary) ); System.out.println();

}

In: Computer Science

We want to improve program performance by %5, we can increase clock rate but doing so...

We want to improve program performance by %5, we can increase clock rate but doing so will require 1.25 times as many clock cycles. Calculate the new clock rate? Calculate what the new clock rate needs to be to accomplish this performance improvement. Current CPU Time is 18.8 and clock rate is 3.5 GHz. CPI = 1.4 and Instruction count = 47

My answer is:

New Clock Cycles = 0.357

New Clock Rate = 17.86/47*1.4 = 0.2712

Is my answer correct?

In: Computer Science

in unix(bash) Write a Makefile with a recipe which can be used to compile myprog.c into...

in unix(bash)

Write a Makefile with a recipe which can be used to compile myprog.c into myprog. Be sure to indicate that "myprog" depends on myprog.c!

In: Computer Science

As an engineer working for CableComm you are assigned to work on a project that involves...

As an engineer working for CableComm you are assigned to work on a project that involves moving 90 people to the 10th floor of a building (Schuylkill View) in Philadelphia. This space is overflow from another building in Philadelphia (CableComm1) that is completely full. The 10th floor will be on its own network segment. All 90 people will have desktop computers and IP phones. A DHCP server will be installed on the 10th floor. A network engineer provides you the following information about available networks (subnets) that can be used for this project.

Location

Subnet/mask

Gateway address

CableComm1 8th floor

10.10.0.0/23

10.10.0.1

CableComm1 9th floor

10.10.2.0/24

10.10.2.1

Available

10.10.3.0

10.10.4.1

CableComm1 10th floor

10.10.4.0/24

10.10.6.1

CableComm1 10th floor (Reserved)

10.10.5.0

CableComm1 11th floor

10.10.6.0/24­­­

Available

10.10.7.0

Available

10.10.8.0

Available

10.10.9.0

  1. (5) Define the network that suit the needs for the 90 people in the same format used above.

Schuylkill View 10th floor

  1. (5) Include the range of dynamic IP addresses that will be available to the 10th floor.
  1. (5) Explain how you arrived at your answer.

(5) Describe an additional role that could be configured on the DHCP server

In: Computer Science

The League with DMA Rewrite your League program from Assignment 8 so that it uses Dynamic...

The League with DMA

Rewrite your League program from Assignment 8 so that it uses Dynamic Memory Allocation (DMA) to create the team names and scores arrays.

This is a good test of the modularity of your program. You will only need to make slight modifications to your main() function if you wrote your original program using functions similar to the following:

void initializeData(string names[], int wins[], int size)
void sort(string names[], int wins[], int size)
void display(string names[], int wins[], int size)

Your modified league program should start out by asking the user how many teams will be entered. It should then dynamically allocate two appropriate arrays, and proceed just like the original League assignment, calling the above three functions. When your program is done using the arrays, don't forget to use delete [] to return their memory to the system.

Note: you must use dynamic memory allocation for your arrays, i.e. the new and delete [] operators, to receive credit.

The output from your program should look approximately like this (user input in orange bold):

How many teams will you enter?: 4
Enter team #1: Padres
Enter the wins for team #1: 75
Enter team #2: Dodgers
Enter the wins for team #2: 91
Enter team #3: Giants
Enter the wins for team #3: 92
Enter team #4: Cubs
Enter the wins for team #4: 65

League Standings:
Giants: 92
Dodgers: 91
Padres: 75
Cubs: 65

THE CODE FOR ASSIGNMENT 8:

#include <iostream>

using namespace std;

void initializeArrays(string names[],int wins[],int size){

int i=0;

while(i<5){

cout<<"Enter team #"<<i+1<<":";

cin>>names[i];

cout<<"Enter wins for team #"<<i+1<<":";

cin>>wins[i];

i++;

}

}

void sortData(string names[],int wins[],int size){

int max=0;

for(int i=0;i<size-1;i++){

for(int j=0;j<size-i-1;j++){

if(wins[j]<wins[j+1]){

int temp = wins[j];

wins[j] = wins[j+1];

wins[j+1] = temp;

string t = names[j];

names[j] = names[j+1];

names[j+1] = t;

}

}

}

}

void displayData(string names[],int wins[],int size){

cout<<"\nLeague Standings:\n";

int num=0;

while(num<size){

cout<<names[num]<<": "<<wins[num]<<"\n";

num++;

}

}

int main() {

string names[5];

int wins[5];

initializeArrays(names,wins,5);

sortData(names,wins,5);

displayData(names,wins,5);

}

In: Computer Science

PYTHON-- how do i change these linkedlist methods into doublylinkedlist methods? A doublylinked list is the...

PYTHON-- how do i change these linkedlist methods into doublylinkedlist methods? A doublylinked list is the same as a linked list, except that each node has a reference to the node after it(next) and the node before it(prev). 

#adds item to the head of list.
def add(self, item):
   
    node = Node(item, self.head)  
   
    self.head = node  
    if self.size == 0:  
        self.tail = node
    self.size += 1

#appends item to tail of list
def append(self, item):

    node = Node(item)
    tail = self.head
    node.next = None
    if self.size == 0:
        node.prev = None
        self.head = node
        return

    while tail.next is not None:
        tail = tail.next

    tail.next = node
    node.prev = tail
    self.size += 1   

#removes the node at position pos. returns node's data
 #make pop O(1)
def pop(self, pos=None):
    
    current = self.head
    previous = None

    i = 0
    while current != None and i != pos:
        previous = current
        current = current.next
        i += 1
if current == self.tail:
    previous.next = None
    self.tail = previous
    self.size -= 1
    return current.data
elif prev is None:
    if self.size == 1:
        self.tail = None
    self.head = current.next
    self.size -= 1
    return current.data
else:
    previous.next = current.next
    self.size -= 1
    return current.data

In: Computer Science

Could someone show me two different ways a hacker can get into a program by exploiting...

Could someone show me two different ways a hacker can get into a program by exploiting weaknesses in code? Also, could you show me examples that shows the potential vulnerability. Could you show me the website where you got those examples. Thank you.

In: Computer Science