Make a python function that inputs f : a function whose root you wish to find, x0 : an initial guess for the root, x1 : an second guess for the root, and k : a number of iterations, and output and outputs a list of the results of performing the secant method k times starting from x0 and x1. Use your function to check if the secant method has the claimed rate of convergence when applied to f ( x ) = e x + x starting with x 0 = 3 and x 1 = 2
In: Computer Science
using Python
In: Computer Science
Express each of these statements using quantifiers. Then form the negation of the statement sothat no negation is to the left of a quantifier. Next, express the negation in simple English. In eachcase, identify the domain and specify the predicates.
•No one has lost more than one thousand dollars playing the lottery.
•There is a student in this class who has chatted with exactly one other student.
•No student in this class has sent e-mail to exactly two other students in this class.•
Some student has solved every exercise in this book.
•No student has solved at least one exercise in every section of this book.
In: Computer Science
1. Briefly explain the differences between a semaphore and a condition variable, and what problem in common these two synchronization primitives solve.
In: Computer Science
How to create a JS application using the code below that displays the lists of grades in their corresponding letter grade textbox and each grade being sorted from lowest to highest.
<!DOCTYPE>
<html>
<head>
<title>EXAM01_03</title>
<style type="text/css">
form{color:black;background-color:lightgray;border:6px solid
black;border-width:4px;width:450px;margin:1px;padding:1px;}
#ans1,#ans2,#ans3,#ans4,#ans5,#numbers{background-color:white;border:4px
solid black;}
input[type="button"]{color:black;background-color:red;border:4px
solid black;}
input[type="text"]{margin:2px;}
div.title{color:white;background-color:black;float: left; width:
450px; text-align:center;}
</style>
</head>
<body>
<form>
<div
class="title"><label>EXAM01_03</label></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>Enter Grade
List:</label></div><div
style="float:left;"><input type="text" id="numbers"
/></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>A:</label></div><div
style="float:left;"><input type="text" id="ans1"
/></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>B:</label></div><div
style="float:left;"><input type="text" id="ans2"
/></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>C:</label></div><div
style="float:left;"><input type="text" id="ans3"
/></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>D:</label></div><div
style="float:left;"><input type="text" id="ans4"
/></div>
<p style="clear:both;" />
<div
style="float:left;width:150px;"><label>F:</label></div><div
style="float:left;"><input type="text" id="ans5"
/></div>
<p style="clear:both;" />
<div style="text-align:center;">
<input type="button" value="Enter" />
<input type="button" value="Clear"
/>
</div>
</form>
</body>
</html>
In: Computer Science
Implement function noVowel() that takes a string s as input and returns True if no char- acter in s is a vowel, and False otherwise (i.e., some character in s is a vowel). >>> noVowel('crypt') True >>> noVowel('cwm') True >>> noVowel('car') False
Implement function allEven() that takes a list of integers and returns True if all integers in the list are even, and False otherwise.
>>> allEven([8, 0, -2, 4, -6, 10])
True
>>> allEven([8, 0, -1, 4, -6, 10])
False
In: Computer Science
I am using MIPS assembly with MARS. My question is about I/O Devices.
1) Research and read about SFRs. Explain the differences between TRISx, PORTx, LATx and ODCx ports. Specify the special function registers (SFRs) for the I/O device(s)
In: Computer Science
Evaluate the following ARM code line by line and show the state of each register and PC after execution.
Initial state: X1 = 0, X2 = 0, X3 = 0, X4 = 0x7, X5 = 0
If there are multiple values for a given register at a particular instruction list them in order
X1 |
X2 |
X3 |
X4 |
X5 |
PC after execution |
||
0x100 |
ADDI X1,X1,#4096 |
||||||
0x104 |
B #8 |
||||||
0x108 |
ADDI X3,X3,#1 |
||||||
0x10C |
CBNZ X3, #2 |
||||||
0x110 |
CBZ X2, #2 |
||||||
0x114 |
B #-1 |
||||||
0x118 |
AND X5,X3,X4 |
||||||
0x11C |
XOR X5,X3,X4 |
||||||
0x120 |
ORR X2,X3,X4 |
||||||
0x124 |
CBZ X2, #7 |
||||||
0x128 |
BREAK |
In: Computer Science
Write a pseudocode method to determine if a set of parentheses and brackets is balanced. For example, such a method should return true for the string, "[()]{}{[()()]()}" and false for the string "[(])". Discuss how the algorithm will perform and how much space in memory it will take if somebody passes a massive string as input.
In: Computer Science
IM GETTING A ERROR MESSAGE :
if rentalCode == 'W' and averageMiles <= 900:
mileCharge = weeksRented * 100.00
else:
Collect Customer Data - Part 2
Prompt: "Starting Odometer Reading:\n"
Variable: odoStart = ?
Prompt: "Ending Odometer Reading:\n"
Variable: odoEnd = ?
Add code to PRINT odoStart and odoEnd variables as well as the totalMiles to check your work.
The following data will be used as input in the test:
odoStart = 1234 odoEnd = 2222
Collect Customer Data - Part 2 - Feedback Link
IF you would like some constructive feedback on your assignment before you submit for a grade, press the Help Me! button below.
Help Me!
Customer Data Check 2
In your rental_car.py file, add code to print out the two new
variables you have collected input for:
odoStart
odoEnd
totalMiles
import sys
'''
Section 1: Collect customer input
'''
#Add customer input 1 here, rentalCode = ?
rentalCode = input("(B)udget, (D)aily, or (W)eekly
rental?\n")
print (rentalCode)
#Collect Customer Data - Part 2
#4)Collect Mileage information:
#a) Prompt the user to input the starting odometer
reading and store it as the variable odoStart
#Prompt -->"Starting Odometer Reading:\n"
# odoStart = ?
odoStart = input('Starting Odometer Reading: ')
#b) Prompt the user to input the ending odometer
reading and store it as the variable odoEnd
#Prompt -->"Ending Odometer Reading:"
# odoEnd = ?
odoEnd = input('Ending Odometer Reading: ')
#c) Calculate total miles
totalMiles = int(odoEnd) - int(odoStart)
#Print odoStart, odoEnd and totalMiles
print (odoStart)
print (odoEnd)
print (totalMiles)
# Calculate Charges 2
## Calculate the mileage charge and store it
as
# the variable mileCharge:
#a) Code 'B' (budget) mileage charge: $0.25 for each
mile driven
if rentalCode == "B":
mileCharge = totalMiles * 0.25
#b) Code 'D' (daily) mileage charge: no charge if the
average
# number of miles driven per day is 100 miles or less;
# i) Calculate the averageDayMiles
(totalMiles/rentalPeriod)
elif rentalCode == "D":
averageDayMiles = totalMiles/rentalPeriod
if averageDayMiles <= 100:
extraMiles == 0
# ii) If averageDayMiles is above the 100 mile per
day
# limit:
# (1) calculate extraMiles (averageDayMiles -
100)
if totalMiles >= 100 and rentalCode == 'D':
# (2) mileCharge is the charge for extraMiles,
mileCharge = totalMiles * int(rentalPeriod) *0.25
#c) Code 'W' (weekly) mileage charge: no charge if
the
# average number of miles driven per week is
# 900 miles or less;
if rentalCode == 'W' and averageMiles <= 900:
mileCharge = weeksRented * 100.00
else:
mileCharge = 0
# i) Calculate the averageWeekMiles (totalMiles/
rentalPeriod)
# ii) mileCharge is $100.00 per week if the average
number of miles driven per week exceeds 900 miles
if rentalCode == 'W' and averageMiles >= 900:
mileCharge = weeksRented * 100.00
else:
print('Charges : ${}'.format(mileCharge))
In: Computer Science
Write a class that maintains the scores for a game application. Implement the addition and removal function to update the database. The gamescore.txt contains player’ name and score data record fields separated by comma. For Removal function, uses the name field to select record to remove the game score record.
Use the List.java, LList.java, Dlink.java, GameEntry.java and gamescore.txt found below
Read gamescore.txt to initialize the Linked list in sorted order by score.
Provide Remove and Add function for user to update the sorted linked list.
Display “Name exist” when add an exist name to the list.
Display “Name does not exist” when remove a name not on the list.
List.java File:
/** Source code example for "A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
/** List ADT */
public interface List<E>
{
/**
* Remove all contents from the list, so it is once again empty. Client is
* responsible for reclaiming storage used by the list elements.
*/
public void clear();
/**
* Insert an element at the current location. The client must ensure that
* the list's capacity is not exceeded.
*
* @param item
* The element to be inserted.
*/
public void insert(E item);
/**
* Append an element at the end of the list. The client must ensure that
* the list's capacity is not exceeded.
*
* @param item
* The element to be appended.
*/
public void append(E item);
/**
* Remove and return the current element.
*
* @return The element that was removed.
*/
public E remove();
/** Set the current position to the start of the list */
public void moveToStart();
/** Set the current position to the end of the list */
public void moveToEnd();
/**
* Move the current position one step left. No change if already at
* beginning.
*/
public void prev();
/**
* Move the current position one step right. No change if already at end.
*/
public void next();
/** @return The number of elements in the list. */
public int length();
/** @return The position of the current element. */
public int currPos();
/**
* Set current position.
*
* @param pos
* The position to make current.
*/
public void moveToPos(int pos);
/** @return The current element. */
public E getValue();
}
LList.java File:
/**
* Source code example for "A Practical Introduction to Data Structures and
* Algorithm Analysis, 3rd Edition (Java)" by Clifford A. Shaffer Copyright
* 2008-2011 by Clifford A. Shaffer
*/
// Doubly linked list implementation
class LList<E> implements List<E>
{
private DLink<E> head; // Pointer to list header
private DLink<E> tail; // Pointer to last element in list
protected DLink<E> curr; // Pointer ahead of current element
int cnt; // Size of list
// Constructors
LList(int size)
{
this();
} // Ignore size
LList()
{
curr = head = new DLink<E>(null, null); // Create header node
tail = new DLink<E>(head, null);
head.setNext(tail);
cnt = 0;
}
public void clear()
{ // Remove all elements from list
head.setNext(null); // Drop access to rest of links
curr = head = new DLink<E>(null, null); // Create header node
tail = new DLink<E>(head, null);
head.setNext(tail);
cnt = 0;
}
public void moveToStart() // Set curr at list start
{
curr = head;
}
public void moveToEnd() // Set curr at list end
{
curr = tail.prev();
}
/** Insert "it" at current position */
public void insert(E it)
{
curr.setNext(new DLink<E>(it, curr, curr.next()));
curr.next().next().setPrev(curr.next());
cnt++;
}
/** Append "it" to list */
public void append(E it)
{
tail.setPrev(new DLink<E>(it, tail.prev(), tail));
tail.prev().prev().setNext(tail.prev());
cnt++;
}
/** Remove and return current element */
public E remove()
{
if (curr.next() == tail)
return null; // Nothing to remove
E it = curr.next().element(); // Remember value
curr.next().next().setPrev(curr);
curr.setNext(curr.next().next()); // Remove from list
cnt--; // Decrement the count
return it; // Return value removed
}
/** Move curr one step left; no change if at front */
public void prev()
{
if (curr != head) // Can't back up from list head
curr = curr.prev();
}
// Move curr one step right; no change if at end
public void next()
{
if (curr != tail.prev())
curr = curr.next();
}
public int length()
{
return cnt;
}
// Return the position of the current element
public int currPos()
{
DLink<E> temp = head;
int i;
for (i = 0; curr != temp; i++)
temp = temp.next();
return i;
}
// Move down list to "pos" position
public void moveToPos(int pos)
{
assert (pos >= 0) && (pos <= cnt) : "Position out of range";
curr = head;
for (int i = 0; i < pos; i++)
curr = curr.next();
}
public E getValue()
{
// Return current element
if (curr.next() == tail)
return null;
return curr.next().element();
}
// reverseList() method that reverses the LList
public void reverseList()
{
LList<E> revList = new LList<E>();
curr = tail.prev();
while (curr != head)
{
revList.append(curr.element());
curr = curr.prev();
}
head.setNext(revList.head.next());
}
// Extra stuff not printed in the book.
/**
* Generate a human-readable representation of this list's contents that
* looks something like this: < 1 2 3 | 4 5 6 >. The vertical bar
* represents the current location of the fence. This method uses
* toString() on the individual elements.
*
* @return The string representation of this list
*/
public String toString()
{
// Save the current position of the list
int oldPos = currPos();
int length = length();
StringBuffer out = new StringBuffer((length() + 1) * 4);
moveToStart();
out.append("< ");
for (int i = 0; i < oldPos; i++)
{
if (getValue() != null)
{
out.append(getValue());
out.append(" ");
}
next();
}
out.append("| ");
for (int i = oldPos; i < length; i++)
{
out.append(getValue());
out.append(" ");
next();
}
out.append(">");
moveToPos(oldPos); // Reset the fence to its original position
return out.toString();
}
}
DLink.java File:
/** Source code example for "A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/
/** Doubly linked list node */
class DLink<E>
{
private E element; // Value for this node
private DLink<E> next; // Pointer to next node in list
private DLink<E> prev; // Pointer to previous node
/** Constructors */
DLink(E it, DLink<E> p, DLink<E> n)
{
element = it;
prev = p;
next = n;
}
DLink(DLink<E> p, DLink<E> n)
{
prev = p;
next = n;
}
/** Get and set methods for the data members */
DLink<E> next()
{
return next;
}
DLink<E> setNext(DLink<E> nextval)
{
return next = nextval;
}
DLink<E> prev()
{
return prev;
}
DLink<E> setPrev(DLink<E> prevval)
{
return prev = prevval;
}
E element()
{
return element;
}
E setElement(E it)
{
return element = it;
}
}
GameEntry.java File:
public class GameEntry {
protected String name;
protected int score;
public GameEntry(String n, int s) {
name = n;
score = s;
}
public String getName() {return name;}
public int getScore() {return score;}
public String toString() {
return "("+name+","+score+")";
}
}
gamescore.txt File:
Mike,1105
Rob,750
Paul,720
Anna,660
Rose,590
Jack,510
In: Computer Science
what is the output?
int main ( )
{
int a = 3, b= 2, c= 1, d, e, f, g;
d = a&b; e = a | c; f = a >> 1, g = a << 1;
cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl;
}
In: Computer Science
Assignment 2 is on page 146, question 12. The assignment asks you to write a program to allow a user to enter a temperature in Celsius and convert it to Fahrenheit. Then display the new temperature on the screen. Consider using the fixed, showpoint, and setprecision stream manipulators with your output. (hint, probably points to what sort of numeric variables you should use) The formula to convert from C to F is in the book on page 146.
For extra credit, have your program then ask for the temperature in Fahrenheit and convert to Celsius and display in a similar manner.
In: Computer Science
Looking for some more simple pseudocode (examples in bold italicized font below) for this chunk of program? I have added some, but my professor prefers more than this, thank you and THUMBS UP always left for good answers!
---------------------------------------------------------------------------------------------------------------------------
VectorStack<Integer> lowerValues = new VectorStack<Integer>();
VectorStack<Integer> upperValues = new VectorStack<Integer>();
for (int i = 0; i < data.length; i++)
{
lowerValues.push(data[i]);
}
// While the lower values are not
empty
while (!lowerValues.isEmpty())
{
temp = lowerValues.pop();
while ((!upperValues.isEmpty() && temp < upperValues.peek()))
{
lowerValues.push(upperValues.pop());
// Push the pop of upper value
}
upperValues.push(temp);
}
while (!upperValues.isEmpty()) {
for (int b = 0; b < data.length; b++) {
result[b] = upperValues.pop();
System.out.println(result[b]);
}
}
return result;
}
In: Computer Science
In: Computer Science