all python
Question One [2 * 2.5]
•The sum
•The difference
•The product
•The average
•The distance (absolute value of the difference)
•The maximum (the larger of the two)
•The minimum (the smaller of the two)
Hint: Python defines max and min functions that accept a sequence of values, each separated with a comma.
Example:
Enter a letter grade: B-
The numeric value is 2.7.
Grade = 99
if Grade>= 90: print("A") if Grade >=80 : print("B") if Grade >=70 : print("C") if Grade >=60: print("D") else: print("Failed")
In: Computer Science
A direct-mapped cache consists of 8 blocks. Byte-addressable
main memory contains 4K blocks of 8 bytes each. Access time for the
cache is 22ns, and the time required to fill a cache slot from main
memory is 300ns. (This time allows us to determine the block is
missing and bring it into cache.) Assume a request is always
started in parallel to both cache and to main memory(so if it is
not found in cache, we do not have to add this cache search time to
the memory access). If a block is missing from cache, the entire
block is brought into the cache and the access is restarted.
Initially, the cache is empty.
-Compute the hit rate for a program that loops 4 times from
locations 0x0 to 0x43 (address 0 hex to address 43 hex).
-Compute the effective access time for this program.
In: Computer Science
Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the requirements for trap.cpp:
Write a main program in a file called trap.cpp that solves the following scenario, using your Grid class:
Giant Mole People have risen from their underground lairs and are taking over the world. You have been taken prisoner and placed in an underground jail cell. Since the Mole People are blind and don't know how to build doors, your cell has one open exit (no door). Since you are deep underground, it is completely dark and you cannot see. Your task is to escape your prison to join the human resistance!
Your program should ask the user to input the number of rows, then columns, for the grid. (Note that this is the ONLY keyboard input for this program). Create a grid with the specified number of rows and columns, using the constructor with two parameters -- (this is the one that should automatically create a fenced-in grid containing one exit and a randomly placed mover). Display the initial grid. Since the placement of the exit and the mover is random, execution of this program will look a little different every time. Your task is to escape the trap! You will need to create an algorithm that will instruct the mover to find its way to the exit. (Hint: Think about how to use the Predicate functions before you move). Upon reaching the exit, you should print a message of success, like "We escaped!", and then output the final position of the mover. Keep the path toggled ON. You only need to display the initial setup grid and the final grid for this program.
Here is the header file grid.h:
#include <iostream>
using namespace std;
class Grid
{
public:
static const int NORTH = 0;
static const int WEST = 1;
static const int SOUTH = 2;
static const int EAST = 3;
Grid(); // build 1 x 1 grid with mover in only
// square, facing east
Grid(int r, int c); // build grid with r rows, c cols, blocks
around edge with random exit
// and random mover position and direction
Grid(int r, int c, int mr, int mc, int d); // build empty grid with r rows, c cols, and mover at row mr, col mc, and facing direction d
bool Move(int s); // move forward s spaces, if possible
void TogglePath(); // toggle whether or not moved path is shown
void TurnLeft(); // turn the mover to the left
void PutDown(); // put down an item at the mover's position
bool PutDown(int r, int c); // put down an item at (r,c), if possible
bool PickUp(); // pick up item at current position
bool PlaceBlock(int r, int c); // put a block at (r,c), if possible
void Grow(int gr, int gc); // grow the grid by gr rows, gc columns
void Display() const; // display the grid on screen. Accessors
bool FrontIsClear() const; // check to see if space in front of mover is clear
bool RightIsClear() const; // check to see if space to right of mover is clear
int GetRow() const; // return row of the mover
int GetCol() const; // return column of the mover
int GetNumRows() const; // return number of rows in the grid
int GetNumCols() const; // return number of columns in the grid
private:
char** grid;
int mover_r, mover_c, mover_d, maxRow, maxCol;
bool path;
};
Task
You will write a class called Grid, and test it with a couple of programs. A Grid object will be made up of a grid of positions, numbered with rows and columns. Row and column numbering start at 0, at the top left corner of the grid. A grid object also has a "mover", which can move around to different locations on the grid. Obstacles (which block the mover) and other objects (that can be placed or picked up) are also available. Here is a sample picture of a Grid object in its display format:
0 . . . This is a Grid object with 4 rows and 4 columns (numbered 0 - 3). . . > . The mover '>' is at row 1, column 2, facing east. . . . . The obstacle '#' is at row 3, column 1 . # . . The other item '0' is at row 0, column 0
The @ character indicates that the mover and an item (0) currently occupy the same position on the grid.
Program Details and Requirements
1) Grid class
Download this starter file: grid_starter.h and rename it as grid.h. Your member function prototypes are already given in this file. You will need to add appropriate member data. You will also need to define each of the member functions in the file grid.cpp. You may add whatever member data you need, but you must store the grid itself as a two-dimensional array. Maximum grid size will be 40 rows and 40 columns. (Note that this means dynamic allocation will NOT be needed for this assignment).
Meaning of Grid symbols
. empty spot on the grid 0 an item that can be placed, or picked up # a block (an obstacle). Mover cannot move through it < mover facing WEST > mover facing EAST ^ mover facing NORTH v mover facing SOUTH @ mover occupying same place as item (0)
A printed space ' ' in a grid position represents a spot that the mover has already moved through when the path display is toggled on
public Member function descriptions
You'll need the library cstdlib for the srand and rand functions. While it's not normally the best place to do it, you can go ahead and seed the random number generator here in the constructor in some appropriate way so that it's different for seperate program runs.
If you need a refresher on pseudo-random number generation, see this notes set from COP 3014: http://www.cs.fsu.edu/~myers/c++/notes/rand.html
In: Computer Science
package applications;
public class Matrix
{
private int[][] m;
public Matrix(int x, int y)
{
m = new int[x][y];
}
public Matrix(int x, int y, int z)
{
m = new int[x][y];
for(int i = 0; i < x; i++)
{
for(int j = 0; j < y; j++)
{
m[i][j] = z;
}
}
}
public int rowsum(int i) throws IndexOutOfBoundsException
{
if (i < 0 || i > m.length-1)
{
throw new IndexOutOfBoundsException("Invalid Row");
}
int sum = 0;
for(int j = 0; j < m[i].length; j++)
{
sum += m[i][j];
}
return sum;
}
public static void main(String[] args)
{
Matrix A = new Matrix(100, 100, 1);
System.out.println(A.rowsum(99));
System.out.println("Done!");
Matrix B = new Matrix(1000, 1000, 1);
System.out.println("Done!");
Matrix C = new Matrix(10000, 10000, 1);
System.out.println("Done!");
}
}
1)add method columnSum(j)
2)add method max() which returns the largest value that contain in the matrix
3)add method trace() i.e., if matrix is not square, then throw error otherwise compute the sum of the entries on the diagnol.
In: Computer Science
Fill in each blank with the correct answer/output. Assume each statement happens in order and that one statement may affect the next statement. Hand trace this code instead of using your IDE. String s = "abcdefghijklmnop"; ArrayList r = new ArrayList(); r.add("abc"); r.add("cde"); r.set(1,"789"); r.add("xyz"); r.add("123"); Collections.sort(r); r.remove(2); The first index position in an array is __________. System.out.print( s.substring(0,1) ); // LINE 2 System.out.print( s.substring(2,3) ); // LINE 3 System.out.print( s.substring(5,6) ); // LINE 4 System.out.print( r.get(0) ); // LINE 5 System.out.print(r.get(0).substring(0,1)); // LINE 6 System.out.print( r.get(2) ); // LINE 7 System.out.print( r.indexOf("123")); // LINE 8 System.out.print( r.contains("abc")); // LINE 9 System.out.print( r.isEmpty()); // LINE 10 r.set(1, "\\\\"); System.out.print(r); // LINE 11 r.remove(1); System.out.print(r); // LINE 12 r.add("one"); System.out.print(r); // LINE 13 r.add(0,"five"); System.out.print(r); // LINE 14 r.clear(); System.out.print(r); // LINE 15 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.
In: Computer Science
_______ are small central processing units chips.
in the expression 12.45 + 3.6, the values to the right and left of the + symbol are the______
python uses______ to categorize values in memory.
the% symbol is the remainder operator. also known as the______ operator.
when applying the .3f formatting specifier er to the number 76.15854, the result is____.
In: Computer Science
Assume a byte-addressable memory has 64K bytes. Blocks are 8 bytes in length and the cache consists of 4K bytes. Show the format for a main memory address assuming a 4-way set associative cache mapping scheme. Include the field names as well as their sizes.
In: Computer Science
Write a java script function that accepts integer array as input, and display a new array by
performing fol
lowing modifications,
•
The values in odd index positions must be incremented by 1
•
The values in even index positions must be decremented by 1.
•
Assume the array index starts from 0.
Input 1: arr = [1,2,3,4]
Output 1: arr = [0,3,2,5
it done html and javascript and plz do it in simple way
In: Computer Science
Create a class called triangle_area. The initializing inputs are numbers b and h. In addition to the initialization method, the class must have the area method, which calculates the area of a triangle (A = b x h / 2) and creates an attribute called Area with that value.
In: Computer Science
Instructions
Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1.
Your program should allow the user to buy as many items as the user desires.
Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience.
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING)
C++ CODE
Exercise 19
Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling is free; otherwise, the shipping and handling is $10 per item. Design an algorithm that prompts Jason to enter the number of items ordered and the price of each item. The algorithm then outputs the total shipping and handling fee, and the billing amount. Your algorithm must use a loop (repetition structure) to get the price of each item. (For simplicity, you may assume that Jason orders no more than five items at a time.)
An example of the program is shown below:
Enter the number of items ordered: 3 Enter the price of item no. 1: 79.00 Enter the price of item no. 2: 23.50 Enter the price of item no. 3: 1.99 The shipping and handling fee is: $30.00 The billing amount is: $134.49
Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.
In: Computer Science
10.5 LAB: Air-traffic control (queue using a linked list)
Given a partial main() and PlaneQueue class, write the push() and pop() methods for PlaneQueue. Then complete the main() to read in whether flights are arriving or have landed at an airport. An "arriving" flight is pushed onto the queue. A "landed" flight is popped from the front of the queue. Output the queue after each plane is pushed or popped. Entering -1 exits the program.
Ex: If the input is:
arriving AA213 arriving DAL23 arriving UA628 landed -1
the output is:
Air-traffic control queue Next to land: AA213 Air-traffic control queue Next to land: AA213 Arriving flights: DAL23 Air-traffic control queue Next to land: AA213 Arriving flights: DAL23 UA628 AA213 has landed. Air-traffic control queue Next to land: DAL23 Arriving flights: UA628
AirTrafficControl.java
import java.util.Scanner;
public class AirTrafficControl {
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
PlaneQueue planeQueue = new PlaneQueue();
PlaneNode curNode;
PlaneNode foundNode;
String arrivingOrLanded;
String flightCode;
// TODO: Complete main to read in arriving flight codes and
whether
// a flight has landed. Print the queue after every push() or
// pop() operation. If the user entered "landed", print which
// flight has landed. Continue until -1 is read.
}
}
PlaneQueue.javapublic class PlaneQueue
{
private PlaneList planeList; // Queue implemented using linked
list
int length;
public PlaneQueue() {
planeList = new PlaneList();
length = 0;
}
// TODO: Write push() and pop() methods. push() adds an item
to
// the queue and increases the length by 1. pop() removes and
// returns the first item in the queue and decreases the length by
1.
public boolean isEmpty() {
if (length == 0) {
return true;
}
return false;
}
public int getLength() {
return length;
}
public void printPlaneQueue() {
PlaneNode curNode;
curNode = planeList.headNode;
System.out.println("Air-traffic control queue");
if (!isEmpty()) {
System.out.print(" Next to land: ");
curNode.printNodeData();
System.out.println();
if (length > 1) {
System.out.println(" Arriving flights: ");
curNode = curNode.nextNode;
while (curNode != null) {
System.out.print(" ");
curNode.printNodeData();
System.out.println();
curNode = curNode.nextNode;
}
}
}
else {
System.out.println("Queue is empty.\n");
}
System.out.println();
}
}
PlaneList.java
public class PlaneList {
// Linked list nodes
public PlaneNode headNode;
public PlaneNode tailNode;
public PlaneList() {
// Front of nodes list
headNode = null;
tailNode = null;
}
// append
public void append(PlaneNode newNode) {
if (headNode == null) { // List empty
headNode = newNode;
tailNode = newNode;
}
else {
tailNode.nextNode = newNode;
tailNode = newNode;
}
}
// prepend
public void prepend(PlaneNode newNode) {
if (headNode == null) { // list empty
headNode = newNode;
tailNode = newNode;
}
else {
newNode.nextNode = headNode;
headNode = newNode;
}
}
// insertAfter
public void insertAfter(PlaneNode curNode, PlaneNode newNode)
{
if (headNode == null) { // List empty
headNode = newNode;
tailNode = newNode;
}
else if (curNode == tailNode) { // Insert after tail
tailNode.nextNode = newNode;
tailNode = newNode;
}
else {
newNode.nextNode = curNode.nextNode;
curNode.nextNode = newNode;
}
}
// removeAfter
public void removeAfter(PlaneNode curNode) {
PlaneNode sucNode;
// Special case, remove head
if (curNode == null && headNode != null) {
sucNode = headNode.nextNode;
headNode = sucNode;
if (sucNode == null) { // Removed last item
tailNode = null;
}
}
else if (curNode.nextNode != null) {
sucNode = curNode.nextNode.nextNode;
curNode.nextNode = sucNode;
if (sucNode == null) { // Removed tail
tailNode = curNode;
}
}
}
// search
public PlaneNode search(String key) {
PlaneNode curNode;
int position = 1;
curNode = headNode;
while (curNode != null) {
curNode.nodePos = position;
if (curNode.flightCode.equals(key)) {
return curNode;
}
curNode = curNode.nextNode;
++position;
}
return null;
}
public void printPlaneList() {
PlaneNode curNode;
curNode = headNode;
while (curNode != null) {
curNode.printNodeData();
System.out.println();
curNode = curNode.nextNode;
}
}
}
PlaneNode.java
public class PlaneNode {
public String flightCode;
public PlaneNode nextNode; // Reference to the next node
public int nodePos;
public PlaneNode() {
flightCode = "0";
nextNode = null;
}
// Constructor
public PlaneNode(String initFlightCode) {
this.flightCode = initFlightCode;
this.nextNode = null;
}
// Constructor
public PlaneNode(String initFlightCode, PlaneNode newNextNode)
{
this.flightCode = initFlightCode;
this.nextNode = newNextNode;
}
public void printNodeData() {
System.out.print(this.flightCode);
}
}
In: Computer Science
Thoroughly discuss and answer the following question. Do some research and find out whether Babbage’s Analytical Engine is a computer according to the von Neumann model. Post a complete answer to the best of your abilities and research and understanding. Reference your sources other than textbook.
In: Computer Science
Policy Drivers
The purpose of this assignment is to practice and demonstrate your ability to interpret detailed policy. We have chosen for you to take a look at two of the most well known policies; in real life, you will have government polices such as these as well as enterprise specific policies or regulations. As you build information systems, it is key to early on in the process to identify all relevant policy drivers and understand them.
In the module, we discussed how an organization's policies and regulations for data governance influence the nature and structure of IT/IS systems. For your assignment, research either HIPAA (for health care) or Sarbanes-Oxley (for financial data). In 1 page, describe at least two of the policies you find and explain how an IT/IS system would need to accommodate.
In: Computer Science
Create a Java method that does the following: 1) Ask the user for a dividend and a divisor both of "int" type. 2) Computes the remainder of the division. The quotient (answer) must be of the "int" type. Do NOT use the method " % " provided in Java in your code. Remember that it gives wrong answers when some of the inputs are negative. Please see the videos for the explanation. This is the code I have from the previous work that should be modified to fit this problem:
import java.util.Scanner;
public class DivisionAlgorithm {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n1, n2;
System.out.print("Enter dividend input: ");
n1 = scanner.nextInt();
System.out.print("Enter divisor input: ");
n2 = scanner.nextInt();
while(n1>=n2){
n1 = n1 - n2;
}
System.out.println("Quotient = "+n1);
}
}
-22 / 3 doesn't compute correctly, negative numbers return with errors.
In: Computer Science
For this assignment you will implememnt a number of Boolean functions, such as implies, nand, etc.
a) Boolean functions You are provided with a set of undefined functions.You will create the bodies for these 2 parameter functions, such that they return the appropriate Boolean value (True or False). The formal parameters are always p and q (in that order)
Notice the difference between npIMPnq and nqIMPnp: In npIMPnq you return not p implies not q (not first param implies not second param), for example npIMPnq(True,False) returns True.
In nqIMPnp you return not q implies not p (not second param implies not first param), for example nqIMPnp(True,False) returns False.
b) Truth-table inputs The function makettins(n) will
create a truth table for all combinations of n Boolean variables. A
truth table is an arrayList of 2**n arrayLists of n Booleans. For
example makettins(2) returns
[[False, False], [False, True], [True, False], [True, True]]
Notice the recursive nature of makettins(n): It consists of a truth-table(n-1), each row prefixed with False followed by the same truth-table(n-1), each row prefixed with True, with a base case for n==1: [[False], [True]]
Two functions are provided: run(f) and main, so that you can test your code.
'''
PA1: Boolean functions and truth-table inputs
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
For PA1 you will implememnt a number of Boolean functions,
such as implies, nand, etc.
a) Boolean functions
You are provided with a set of undefined functions.You will
create the bodies for these 2 parameter functions, such that
they return the appropriate Boolean value (True or False).
The formal parameters are always p and q (in that order)
Notice the difference between npIMPnq and nqIMPnp:
In npIMPnq you return not p implies not q (not first
param implies not second param), for example
npIMPnq(True,False) returns True.
In nqIMPnp you return not q implies not p (not second
param implies not first param), for example
nqIMPnp(True,False) returns False.
b) Truth-table inputs
The function make_tt_ins(n) will create a truth table for
all combinations of n Boolean variables. A truth table is
an arrayList of 2**n arrayLists of n Booleans. For example
make_tt_ins(2) returns
[[False, False], [False, True], [True, False], [True, True]]
Notice the recursive nature of make_tt_ins(n):
It consists of a truth-table(n-1), each row prefixed with
False
followed by the same truth-table(n-1), each row prefixed with
True,
with a base case for n==1: [[False], [True]]
Two functions are provided: run(f) and main, so that you can
test
your code.
python3 PA1.py tests your Boolean function
python3 PA1.p=y tt tests your function make_tt_ins()
'''
import sys
# p implies q
def implies(p, q):
return False
# not p implies not q
def npIMPnq(p,q):
return False
# not q implies not p
def nqIMPnp(p,q):
return False
# p if and only if q: (p implies q) and (q implies
p)
def iff(p, q):
return False
# not ( p and q )
def nand(p, q):
return False
# not p and not q
def npANDnq(p,q):
return False
# not ( p or q)
def nor(p, q):
return False
# not p or not q
def npORnq(p,q):
return False
def make_tt_ins(n):
return [[]]
#provided
def run(f):
print(" True,True : ", f(True,True))
print(" True,False : ", f(True,False))
print(" False,True : ", f(False,True))
print(" False,False: ", f(False,False))
print()
#provided
if __name__ == "__main__":
print("program", sys.argv[0])
f1 = sys.argv[1]
print(f1);
if(f1 == "implies"):
run(implies);
if(f1 == "iff"):
run(iff)
if(f1 == "npIMPnq"):
run(npIMPnq)
if(f1 == "nqIMPnp"):
run(nqIMPnp)
if(f1 == "nand"):
run(nand)
if(f1 == "nor"):
run(nor)
if(f1 == "npANDnq"):
run(npANDnq)
if(f1 == "npORnq"):
run(npORnq)
if(f1 == "tt"):
print(make_tt_ins(int(sys.argv[2])))
In: Computer Science