Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Explore the dependence of the period of a pendulum's motion as a function of its initial amplitude. Complete tasks inside the TODO #



import numpy as np

from scipy import interpolate

from scipy import integrate

import matplotlib.pyplot as plt



class pendulum:

  ''' defines a simple pendulum '''


  def __init__(self, pendulum_length, mass):

    # TODO: Assignment Task 1: write method body

    # End of Task 1; proceed to task 2.



  def set_g(self, g):

    ''' small g to be used in calculations '''

    self._g = g



  def dydt(self, y, t):

    """ Calculate the derivatives for a pendulum


    Parameters

    ----------

    y: array-like

      vector of unknowns for the ode equation at time t


    t: float

      time t


    Returns

    -------

    ret: numpy array of float

      the derivatives of y

    """

    # TODO: Assignment Task 2: write method body

    # End of Task 2; proceed to task 3.



  def period(self, maximum_amplitude):

    ''' Calculate the period of the periodic motion.


    For amplitude=0 the small amplitude analytical solution is returned.

    Otherwise the period is calculated by integrating the ODE using

    scipy.integrate.odeint() and determining the time between release at

    maximum amplitude and the first angle=0 crossing. The exact zero

    crossing is determined using scipy.interpolate.interp1d().


    In the calculation it is assumed that the period has a value between

    90% and 150% of the small amplitude period.


    Parameters

    ----------

    maximum_amplitude: float

      maximum amplitude of the periodic motion


    Returns

    -------

    p: float

      the period

    '''

    # TODO: Assignment Task 3: write method body

    # End of Task 3; no further tasks.


if __name__ == '__main__':

  #some test code

  pen = pendulum(1, 1)

  pen.set_g(9.81)


  #generate data for figure

  angles = np.linspace(0, np.pi/2, 31)

  period_ode = [pen.period(a) for a in angles]


  # generate a plot

  fig = plt.figure()

  ax = fig.add_subplot(1, 1, 1)

  ax.plot(angles, period_ode, 'b', label='generated using ode')

  ax.set_title('Period of a 1m Pendulum as a Function of Amplitude')

  ax.set_xlabel('amplitude/rad')

  ax.set_ylabel('period/s')

  ax.legend(loc='upper left')

  plt.show()


After your program has prompted the user for how many values should be in the array, generated those values, and printed the whole list, create and call a new function named sumArray. In this method, accept the array as the parameter. Inside, you should sum together all values and then return that value back to the original method call. Finally, print that sum of values.

Sample Run

How many values to add to the array: 
8
[17, 99, 54, 88, 55, 47, 11, 97]
Total 468

Computer Science


Write a program to control a set of 10 motors; the motors are operating under load balancing mechanism as


follows:


• Motors operate in pairs as follows: 1,10 then 2, 9 then 3,8 then 4,7 then 5,6 then repeat.


• The operating duration for each pair is 10,000 milliseconds.


• After each operating cycle, all motors must be OFF for 10,000 milliseconds then a new cycle starts.


• The operating sequence is running 24/7.


The company XYZ is offering painting services.

The cost for painting each window is 200 Rs.

The cost for painting each door is 500 Rs.

The company charges 33 Rs per square feet.

Additional service charges are 500 Rs per room.

To calculate the square feet of a room that is rectangular or square,

simply multiply the length of the room by the width.

Write a C program to calculate the painting cost of your room.

Requirements:

1. Capture length and width of the room.

2. Capture number of windows in room from user

3. Capture number of doors in room from user

4. Compute area of room in square feet.

5. Display area of room(sqft).

5. Compute painting cost with suitable expression.

6. Display painting cost.


Square at Alternate Indices

Given an array


myArray of numbers, write a function to square the alternate numbers of the myArray, starting from index 0 using the array method map.Input

  • The input will be a single line containing an array myArray

Output

  • The output should be a single line containing an array with alternate numbers squared

Constraints

  • Each value in the array must be a number


Sample Input 1

[ 1, 2, 3, 4, 5 ]


Sample Output 1

[ 1, 2, 9, 4, 25 ]


Sample Input 2

[ 2, 4 ]


Sample Output 2

[ 4, 4 ]


Task Description

 

You are to present your findings in the form of a problem based report. This report should describe how you implemented the program (source code and screen shots).

 

Assignment Task

 

  1. How many seconds are in an hour? Use the interactive interpreter as a calculator and multiply the number of seconds in a minute (60) by the number of minutes in an

hour (also 60).

 

  1. Assign the result from the previous task (seconds in an hour) to a variable called seconds_per_hour.

 

  1. How many seconds are in a day? Use your seconds_per_hour variable.

 

  1. Calculate seconds per day again, but this time save the result in a variable called seconds_per_day.

 

  1. Divide seconds_per_day by seconds_per_hour. Use floating-point (/) division.

 

  1. Divide seconds_per_day by seconds_per_hour, using integer (//) division. Did

this number agree with the floating-point value from the previous question, aside from the final .0?


  1. Create a list called years_list, starting with the year of your birth, and each year thereafter until the year of your fifth birthday. For example, if you were born in 1980 the list would be years_list = [1980, 1981, 1982, 1983, 1984, 1985].

 

  1. In which year in years_list was your third birthday? Remember, you were 0 years of age for your first year.

 

  1. In which year in years_list were you the oldest?

Objects with given Fruit

Given an array of objects

objectEntities in the prefilled code and fruit as an input, write a JS program to log the array of objects containing the given fruit.
Input

The input will be a single line containing a string

fruitOutput

The output should be the array of objects matching the given

fruit


Sample Input 1

apple


Sample Output 1

[

{ fruit: 'apple', vegetable: 'broccoli' },

{ fruit: 'apple', vegetable: 'cauliflower' }

]


Sample Input 2

orange


Sample Output 2

[ { fruit: 'orange', vegetable: 'mushrooms' } ]


i want code in between write your code here


"use strict";


process.stdin.resume();

process.stdin.setEncoding("utf-8");


let inputString = "";

let currentLine = 0;


process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});


process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});


function readLine() {

 return inputString[currentLine++];

}


/* Please do not modify anything above this line */


function main() {

 const fruit = readLine();

 const objectEntities = [

  {

   fruit: "apple",

   vegetable: "broccoli"

  },

  {

   fruit: "kiwi",

   vegetable: "broccoli"

  },

  {

   fruit: "apple", 

   vegetable: "cauliflower"

  },

  {

   fruit: "orange", 

   vegetable: "mushrooms"

  },

 ];

  

 /* Write your code here */


}


Unite Family


Given three objects

father, mother, and child, write a JS program to concatenate all the objects into the family object using the spread operator.
Input

  • The first line of input contains an object father
  • The second line of input contains an object mother
  • The third line of input contains an object child

Output

  • The output should be a single line string with the appropriate statement as shown in sample outputs

Constraints

  • Keys of the objects should be given in quotes


Sample Input

{'surname' : 'Jones', 'city': 'Los Angeles'}

{'dish': 'puddings'}

{'pet': 'Peter'}


Sample Output

Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"


i want code in between write your code here


"use strict";


process.stdin.resume();

process.stdin.setEncoding("utf-8");


let inputString = "";

let currentLine = 0;


process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});


process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});


function readLine() {

 return inputString[currentLine++];

}


/* Please do not modify anything above this line */


function main() {

 const father = JSON.parse(readLine().replace(/'/g, '"'));

 const mother = JSON.parse(readLine().replace(/'/g, '"'));

 const child = JSON.parse(readLine().replace(/'/g, '"'));

 

 /* Write your code here */ 


/* Please do not modify anything below this line */

 console.log(`Mr and Mrs ${family.surname} went to a picnic in ${family.city} with a boy and a pet ${family.pet}. Mrs ${family.surname} made a special dish "${family.dish}"`);

}



Update Pickup Point


Given a previous pickup point in the prefilled code, and updated pickup point

area, city as inputs, write a JS factory function with a method to update the pickup point.
Input

  • The first line of input contains a string area
  • The second line of input contains a string city

Output

  • The output should be a single line containing the updated pickup point area and city separated by a space


Sample Input 1

Kukatpally

Hyderabad

Sample Output 1

Kukatpally Hyderabad

Sample Input 2

Jubilee Hills

Hyderabad

Sample Output 2

Jubilee Hills Hyderabad


i want code in between write code here


"use strict";


process.stdin.resume();

process.stdin.setEncoding("utf-8");


let inputString = "";

let currentLine = 0;


process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});


process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});


function readLine() {

 return inputString[currentLine++];

}


/* Please do not modify anything above this line */


function createCabBooking(area, city) {


 /* Write your code here */


}


/* Please do not modify anything below this line */


function main() {

 const newArea = readLine();

 const newCity = readLine();

  

 const cabBooking1 = createCabBooking("Abids", "Hyderabad");

 cabBooking1.updatePickupPoint(newArea, newCity);


 console.log(`${cabBooking1.area} ${cabBooking1.city}`);

}



Hotel Bill

A Hotel is offering discounts to its customers.

Given charge per day

dayCharge based on category and numbers of days customer stayed days as inputs, write a JS arrow function to return the total bill with the discount.


Quick Tip

  • The formula for bill is,
  • bill = dayCharge * days
  • The formula to calculate the discounted bill,
  • bill - (bill * discount) / 100

Apply discounts on the following basis,

  • 5%, if the customer stays more than 2 days
  • 15%, if the customer stays more than 5 days

Input

  • The first line of input contains a number dayCharge
  • The second line of input contains a number days

Output

  • The output should be a single line containing the total bill with the discount



Sample Input 1

200

3

Sample Output 1

570

Sample Input 2

180

1

Sample Output 2

180


i want the code in between write code here


"use strict";


process.stdin.resume();

process.stdin.setEncoding("utf-8");


let inputString = "";

let currentLine = 0;


process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});


process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});


function readLine() {

 return inputString[currentLine++];

}


/* Please do not modify anything above this line */


function main() {

 const dayCharge = JSON.parse(readLine());

 const days = parseInt(readLine());

 

 /* Write your code here */

}


LATEST TUTORIALS
APPROVED BY CLIENTS