This document contains Python code that defines functions for performing various mathematical calculations. It includes functions for basic calculations like addition and subtraction, advanced calculations like trigonometric functions and logarithms, and area calculations for shapes like triangles, squares and circles. The main function allows the user to select the type of calculation and then calls the appropriate sub-function.
Mylib.py
def allInOne(n1, n2):
return {"add":plus(n1, n2),
"sub":subtract(n1, n2),
"mult":multiply(n1, n2),
"div": divide(n1, n2)}
def IsInRange(lr, hr, n):
return lr < n and n < hr
#add 2 numbers
def plus(n1,n2):
add = n1 + n2
return add
#subtract 2 numbers
def subtract(n1, n2):
sub = n1 - n2
return sub
#multiply 2 numbers
def multiply(n1, n2):
mult = n1 * n2
return mult
#division, n2 should not be zero
def divide(n1, n2):
try:
div = n1/(n2 + 0.0)
return div
except ZeroDivisionError as e:
print("The result of %s/%s = %s" % (n1, n2,"You cannot divide by Zero"))
except Exception :
print("Invalid input" , n1, n2)
#expression calculator
def scalc(val):
try:
#the epression is assumed to be comma separated
ns = val.split(",")
#split it into 3 parts
#remove whitespaces in the components
n1 = int(ns[0].strip())
n2 = int(ns[1].strip())
op = ns[2].strip()
#check if operator is one of the supported
if op == "*":
return multiply(n1, n2)
elif op == "/":
return divide(n1, n2)
elif op == "+":
return plus(n1, n2)
elif op == "-":
return subtract(n1, n2)
else:
print("Unknown operator", op)
#in case of invalid input catch the error
except Exception :
print("Invalid input:" , val)
W6_first_last.py
# Program name :
# Student Name :
# Course : ENTD220
# Instructor :
# Date : 02/12/2020
# Description : Expression & Arithmetic Calculator
# Copy Wrong : This is my work
import Mylib
def doScalc():
print("---------Expression calculator------------------")
print("Enter the expression with format N1,N2,operator:")
print("Supported operator * , /, -, +")
print("E.g 5, 4, *)")
val = input()
res = Mylib.scalc(val)
print('The result of "' + val + '" is', res)
def showList():
print("1) Add two numbers")
print("2) Multiply two numbers")
print("3) Subtract two numbers")
print("4) Divide two numbers")
print("5) Scalc")
print("6) All in one")
print("7) Exit")
def getUserInput():
low = int(input("Enter Lower range:"))
high = int(input("Enter Higher range:"))
n1 = int(input("Enter first number:"))
n2 = int(input("Enter second number:"))
return [low, high, n1 , n2]
def doCalculation(op):
user = getUserInput()
low = user[0]
high = user[1]
n1 = user[2]
n2 = user[3]
if Mylib.IsInRange(low , high, n1) and \
Mylib.IsInRange(low , high, n2):
if op == "+":
res = Mylib.plus(n1, n2)
elif op == "*":
res = Mylib.multiply(n1, n2)
elif op == "-":
res = Mylib.subtract(n1, n2)
elif op == "/":
res = M ...
Mylib.py
def allInOne(n1, n2):
return {"add":plus(n1, n2),
"sub":subtract(n1, n2),
"mult":multiply(n1, n2),
"div": divide(n1, n2)}
def IsInRange(lr, hr, n):
return lr < n and n < hr
#add 2 numbers
def plus(n1,n2):
add = n1 + n2
return add
#subtract 2 numbers
def subtract(n1, n2):
sub = n1 - n2
return sub
#multiply 2 numbers
def multiply(n1, n2):
mult = n1 * n2
return mult
#division, n2 should not be zero
def divide(n1, n2):
try:
div = n1/(n2 + 0.0)
return div
except ZeroDivisionError as e:
print("The result of %s/%s = %s" % (n1, n2,"You cannot divide by Zero"))
except Exception :
print("Invalid input" , n1, n2)
#expression calculator
def scalc(val):
try:
#the epression is assumed to be comma separated
ns = val.split(",")
#split it into 3 parts
#remove whitespaces in the components
n1 = int(ns[0].strip())
n2 = int(ns[1].strip())
op = ns[2].strip()
#check if operator is one of the supported
if op == "*":
return multiply(n1, n2)
elif op == "/":
return divide(n1, n2)
elif op == "+":
return plus(n1, n2)
elif op == "-":
return subtract(n1, n2)
else:
print("Unknown operator", op)
#in case of invalid input catch the error
except Exception :
print("Invalid input:" , val)
W6_first_last.py
# Program name :
# Student Name :
# Course : ENTD220
# Instructor :
# Date : 02/12/2020
# Description : Expression & Arithmetic Calculator
# Copy Wrong : This is my work
import Mylib
def doScalc():
print("---------Expression calculator------------------")
print("Enter the expression with format N1,N2,operator:")
print("Supported operator * , /, -, +")
print("E.g 5, 4, *)")
val = input()
res = Mylib.scalc(val)
print('The result of "' + val + '" is', res)
def showList():
print("1) Add two numbers")
print("2) Multiply two numbers")
print("3) Subtract two numbers")
print("4) Divide two numbers")
print("5) Scalc")
print("6) All in one")
print("7) Exit")
def getUserInput():
low = int(input("Enter Lower range:"))
high = int(input("Enter Higher range:"))
n1 = int(input("Enter first number:"))
n2 = int(input("Enter second number:"))
return [low, high, n1 , n2]
def doCalculation(op):
user = getUserInput()
low = user[0]
high = user[1]
n1 = user[2]
n2 = user[3]
if Mylib.IsInRange(low , high, n1) and \
Mylib.IsInRange(low , high, n2):
if op == "+":
res = Mylib.plus(n1, n2)
elif op == "*":
res = Mylib.multiply(n1, n2)
elif op == "-":
res = Mylib.subtract(n1, n2)
elif op == "/":
res = M.
Mylib.py
def allInOne(n1, n2):
return {"add":plus(n1, n2),
"sub":subtract(n1, n2),
"mult":multiply(n1, n2),
"div": divide(n1, n2)}
def IsInRange(lr, hr, n):
return lr < n and n < hr
#add 2 numbers
def plus(n1,n2):
add = n1 + n2
return add
#subtract 2 numbers
def subtract(n1, n2):
sub = n1 - n2
return sub
#multiply 2 numbers
def multiply(n1, n2):
mult = n1 * n2
return mult
#division, n2 should not be zero
def divide(n1, n2):
try:
div = n1/(n2 + 0.0)
return div
except ZeroDivisionError as e:
print("The result of %s/%s = %s" % (n1, n2,"You cannot divide by Zero"))
except Exception :
print("Invalid input" , n1, n2)
#expression calculator
def scalc(val):
try:
#the epression is assumed to be comma separated
ns = val.split(",")
#split it into 3 parts
#remove whitespaces in the components
n1 = int(ns[0].strip())
n2 = int(ns[1].strip())
op = ns[2].strip()
#check if operator is one of the supported
if op == "*":
return multiply(n1, n2)
elif op == "/":
return divide(n1, n2)
elif op == "+":
return plus(n1, n2)
elif op == "-":
return subtract(n1, n2)
else:
print("Unknown operator", op)
#in case of invalid input catch the error
except Exception :
print("Invalid input:" , val)
W6_first_last.py
# Program name :
# Student Name :
# Course : ENTD220
# Instructor :
# Date : 02/12/2020
# Description : Expression & Arithmetic Calculator
# Copy Wrong : This is my work
import Mylib
def doScalc():
print("---------Expression calculator------------------")
print("Enter the expression with format N1,N2,operator:")
print("Supported operator * , /, -, +")
print("E.g 5, 4, *)")
val = input()
res = Mylib.scalc(val)
print('The result of "' + val + '" is', res)
def showList():
print("1) Add two numbers")
print("2) Multiply two numbers")
print("3) Subtract two numbers")
print("4) Divide two numbers")
print("5) Scalc")
print("6) All in one")
print("7) Exit")
def getUserInput():
low = int(input("Enter Lower range:"))
high = int(input("Enter Higher range:"))
n1 = int(input("Enter first number:"))
n2 = int(input("Enter second number:"))
return [low, high, n1 , n2]
def doCalculation(op):
user = getUserInput()
low = user[0]
high = user[1]
n1 = user[2]
n2 = user[3]
if Mylib.IsInRange(low , high, n1) and \
Mylib.IsInRange(low , high, n2):
if op == "+":
res = Mylib.plus(n1, n2)
elif op == "*":
res = Mylib.multiply(n1, n2)
elif op == "-":
res = Mylib.subtract(n1, n2)
elif op == "/":
res = M ...
Mylib.py
def allInOne(n1, n2):
return {"add":plus(n1, n2),
"sub":subtract(n1, n2),
"mult":multiply(n1, n2),
"div": divide(n1, n2)}
def IsInRange(lr, hr, n):
return lr < n and n < hr
#add 2 numbers
def plus(n1,n2):
add = n1 + n2
return add
#subtract 2 numbers
def subtract(n1, n2):
sub = n1 - n2
return sub
#multiply 2 numbers
def multiply(n1, n2):
mult = n1 * n2
return mult
#division, n2 should not be zero
def divide(n1, n2):
try:
div = n1/(n2 + 0.0)
return div
except ZeroDivisionError as e:
print("The result of %s/%s = %s" % (n1, n2,"You cannot divide by Zero"))
except Exception :
print("Invalid input" , n1, n2)
#expression calculator
def scalc(val):
try:
#the epression is assumed to be comma separated
ns = val.split(",")
#split it into 3 parts
#remove whitespaces in the components
n1 = int(ns[0].strip())
n2 = int(ns[1].strip())
op = ns[2].strip()
#check if operator is one of the supported
if op == "*":
return multiply(n1, n2)
elif op == "/":
return divide(n1, n2)
elif op == "+":
return plus(n1, n2)
elif op == "-":
return subtract(n1, n2)
else:
print("Unknown operator", op)
#in case of invalid input catch the error
except Exception :
print("Invalid input:" , val)
W6_first_last.py
# Program name :
# Student Name :
# Course : ENTD220
# Instructor :
# Date : 02/12/2020
# Description : Expression & Arithmetic Calculator
# Copy Wrong : This is my work
import Mylib
def doScalc():
print("---------Expression calculator------------------")
print("Enter the expression with format N1,N2,operator:")
print("Supported operator * , /, -, +")
print("E.g 5, 4, *)")
val = input()
res = Mylib.scalc(val)
print('The result of "' + val + '" is', res)
def showList():
print("1) Add two numbers")
print("2) Multiply two numbers")
print("3) Subtract two numbers")
print("4) Divide two numbers")
print("5) Scalc")
print("6) All in one")
print("7) Exit")
def getUserInput():
low = int(input("Enter Lower range:"))
high = int(input("Enter Higher range:"))
n1 = int(input("Enter first number:"))
n2 = int(input("Enter second number:"))
return [low, high, n1 , n2]
def doCalculation(op):
user = getUserInput()
low = user[0]
high = user[1]
n1 = user[2]
n2 = user[3]
if Mylib.IsInRange(low , high, n1) and \
Mylib.IsInRange(low , high, n2):
if op == "+":
res = Mylib.plus(n1, n2)
elif op == "*":
res = Mylib.multiply(n1, n2)
elif op == "-":
res = Mylib.subtract(n1, n2)
elif op == "/":
res = M.
Hello, I need some assistance in writing a java program THAT MUST US.pdfFashionColZone
Hello, I need some assistance in writing a java program THAT MUST USE STACKS (LIFO).
Create a Calculator w/ GUI
Write a program that graphically displays a working calculator for simple infix expressions that
consist of: single-digit operands, the operators: +, -, *, and /, and parentheses.
Make the following assumptions:
unary operators (e.g. -2) are illegal
all operations, including division, are integer operations (and results are integers)
the input expression contains no embedded spaces and no illegal characters
the input expression is a syntactically correct infix expression
division by zero will not occur (consider how you can remove this restriction)
Create a GUI application, the calculator has a display and a keypad of 20 keys, which are
arranged as follows:
C
<
Q
/
7
8
9
*
4
5
6
-
1
2
3
+
0
(
)
=
As the user presses keys to enter an infix expression, the corresponding characters appear in the
display. The C (Clear) key erases all input entered so far; the < (Backspace) key erases the last
character entered. When the user presses the = key, the expression is evaluated and the result
appended to the right end of the expression in the display window. The user can then press C and
enter another expression. If the user presses the Q (Quit) key, the calculator ceases operation and
is erased from the screen.
C
<
Q
/
7
8
9
*
4
5
6
-
1
2
3
+
0
(
)
=
Solution
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Calculator extends JFrame implements ActionListener {
JPanel[] row = new JPanel[5];
JButton[] button = new JButton[19];
String[] buttonString = {\"7\", \"8\", \"9\", \"+\",
\"4\", \"5\", \"6\", \"-\",
\"1\", \"2\", \"3\", \"*\",
\".\", \"/\", \"C\", \"\",
\"+/-\", \"=\", \"0\"};
int[] dimW = {300,45,100,90};
int[] dimH = {35, 40};
Dimension displayDimension = new Dimension(dimW[0], dimH[0]);
Dimension regularDimension = new Dimension(dimW[1], dimH[1]);
Dimension rColumnDimension = new Dimension(dimW[2], dimH[1]);
Dimension zeroButDimension = new Dimension(dimW[3], dimH[1]);
boolean[] function = new boolean[4];
double[] temporary = {0, 0};
JTextArea display = new JTextArea(1,20);
Font font = new Font(\"Times new Roman\", Font.BOLD, 14);
Calculator() {
super(\"Calculator\");
setDesign();
setSize(380, 250);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(5,5);
setLayout(grid);
for(int i = 0; i < 4; i++)
function[i] = false;
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
FlowLayout f2 = new FlowLayout(FlowLayout.CENTER,1,1);
for(int i = 0; i < 5; i++)
row[i] = new JPanel();
row[0].setLayout(f1);
for(int i = 1; i < 5; i++)
row[i].setLayout(f2);
for(int i = 0; i < 19; i++) {
button[i] = new JButton();
button[i].setText(buttonString[i]);
button[i].setFont(font);
button[i].addActionListener(this);
}
display.setFont(font);
display.setEditable(false);
display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
display.setPreferredSize(displayDimension);
for(int.
Implement the following sorting algorithms Bubble Sort Insertion S.pdfkesav24
Implement the following sorting algorithms: Bubble Sort Insertion Sort. Selection Sort.
Merge Sort. Heap Sort. Quick Sort. For each of the above algorithms, measure the execution
time based on input sizes n, n + 10(i), n + 20(i), n + 30(i), .. ., n + 100(i) for n = 50000 and i =
100. Let the array to be sorted be randomly initialized. Use the same machine to measure all the
algorithms. Plot a graph to compare the execution times you collected in part(2).
Solution
This code wil create a graph for each plots comparing time for different sorting methods and also
save those plots in the current directory.
from random import shuffle
from time import time
import numpy as np
import matplotlib.pyplot as plt
def bubblesort(arr):
for i in range(len(arr)):
for k in range(len(arr)-1, i, -1):
if (arr[k] < arr[k-1]):
tmp = arr[k]
arr[k] = arr[k-1]
arr[k-1] = tmp
return arr
def selectionsort(arr):
for fillslot in range(len(arr)-1,0,-1):
positionOfMax=0
for location in range(1,fillslot+1):
if arr[location]>arr[positionOfMax]:
positionOfMax = location
temp = arr[fillslot]
arr[fillslot] = arr[positionOfMax]
arr[positionOfMax] = temp
return arr
def insertionsort(arr):
for i in range( 1, len( arr ) ):
tmp = arr[i]
k = i
while k > 0 and tmp < arr[k - 1]:
arr[k] = arr[k-1]
k -= 1
arr[k] = tmp
return arr
# def mergesort(arr):
#
# if len(arr)>1:
# mid = len(arr)//2
# lefthalf = arr[:mid]
# righthalf = arr[mid:]
#
# mergesort(lefthalf)
# mergesort(righthalf)
#
# i=0
# j=0
# k=0
# while i < len(lefthalf) and j < len(righthalf):
# if lefthalf[i] < righthalf[j]:
# arr[k]=lefthalf[i]
# i=i+1
# else:
# arr[k]=righthalf[j]
# j=j+1
# k=k+1
#
# while i < len(lefthalf):
# arr[k]=lefthalf[i]
# i=i+1
# k=k+1
#
# while j < len(righthalf):
# arr[k]=righthalf[j]
# j=j+1
# k=k+1
#
# return arr
def mergesort(x):
result = []
if len(x) < 2:
return x
mid = int(len(x)/2)
y = mergesort(x[:mid])
z = mergesort(x[mid:])
i = 0
j = 0
while i < len(y) and j < len(z):
if y[i] > z[j]:
result.append(z[j])
j += 1
else:
result.append(y[i])
i += 1
result += y[i:]
result += z[j:]
return result
def quicksort(arr):
less = []
equal = []
greater = []
if len(arr) > 1:
pivot = arr[0]
for x in arr:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
return quicksort(less)+equal+quicksort(greater) # Just use the + operator to join lists
else:
return arr
#### Heap sort
def heapsort(arr): #convert arr to heap
length = len(arr) - 1
leastParent = length / 2
for i in range(leastParent, -1, -1):
moveDown(arr, i, length)
# flatten heap into sorted array
for i in range(length, 0, -1):
if arr[0] > arr[i]:
swap(arr, 0, i)
moveDown(arr, 0, i - 1)
def moveDown(arr, first, last):
largest = 2 * first + 1
while largest <= last: #right child exists and is larger than left child
if (largest < last) and(arr[largest] < arr[largest + 1]):
largest += 1
# right child is larger than parent
if arr[largest] > arr[first]:
swap(arr, largest, first)# move down to largest child
first = largest
lar.
The following is my code for a connectn program. When I run my code .pdfeyelineoptics
The following is my code for a connectn program. When I run my code in the tester, I failed two
out 10 tests. I was hoping for some help in finding what causes these errors. I have included the
homework prompt and test failed results. Thank you so much!
#include
#include
#include
void read_args(int argc, char *argv[], int* num_rows, int* num_cols, int *num_pieces_to_win);
void create_board(int num_rows, int num_cols, char*** board, int* turn);
void print_board(int num_rows, int num_cols, char** board);
void destroy_board(int num_rows, char*** board);
void play_game(int num_rows, int num_cols, int num_pieces_to_win, int turn, char** board);
void check_move();
void get_play(int num_rows, int num_cols, char** board, int* user_move);
void make_move(int num_rows, char**board, int user_move, char pieces);
bool play_is_valid(int num_cols, int num_rows, char** board, int user_move_num, int
user_move);
bool game_over(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool game_won(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool game_tied(int num_rows, int num_cols, int num_pieces_to_win, char**board);
bool row_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool col_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool diag_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool right_diag_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool left_diag_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
void read_args(int argc, char *argv[], int* num_rows, int* num_cols, int *num_pieces_to_win) {
//reads command input and ensures there are exactly three numbers
if (argc > 4) {
printf(\"Too many arguments entered\ \");
printf(\"Usage connectn.out num_rows num_columns
number_of_pieces_in_a_row_needed_to_win\");
exit(0);
}
else if (argc < 4) {
printf(\"Not enough arguments entered\ \");
printf(\"Usage connectn.out num_rows num_columns
number_of_pieces_in_a_row_needed_to_win\");
exit(0);
}
else { //puts user input into variables
sscanf(argv[1], \"%d\", &*num_rows);
sscanf(argv[2], \"%d\", &*num_cols);
sscanf(argv[3], \"%d\", &*num_pieces_to_win);
}
return;
}
void create_board (int num_rows, int num_cols, char*** board, int* turn) {
//set up the connect-n board
const char BLANK_SPACE = \'*\';
int i, j;
*turn = 0; //player 1 always goes first
*board = (char**)malloc(num_rows * sizeof(char*)); //creates pointers to the rows
for (i = 0; i < num_rows; ++i){ //for each row
(*board)[i] = (char*)malloc(num_cols * sizeof(char)); //create it
for (j = 0; j < num_cols; j++) { //fill in the row with blanks
(*board)[i][j] = BLANK_SPACE;
}
}
}
void print_board (int num_rows, int num_cols, char** board) {
//displays connect-n board
int i, j;
int k = 0;
for(i = 0; i < num_rows; i++){
printf(\"%d \", ((num_rows- i) - 1));
for(j = 0; j < num_cols; ++j){
printf(\"%c \", board[i][j]);
}
printf(\"\ \");
}
printf(\" %d \", k);
for(j = 1; j <.
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAMSaraswathiRamalingam
Fundamental Algorithms, Exchanging the values of Two Variables,Counting,Summation of a Set of Numbers,Factorial Computation ,Sine Function Computation ,Generation of the Fibonacci Sequence,Reversing the Digits of an Integer,Base Conversion , Character to Number Conversion , Factoring Methods: Finding the square Root of a Number ,The Smallest Divisor of an Integer,The Greatest Common Divisor of the two integers,Generating Prime Numbers,Computing the Prime Factors of an integer ,Generation of Pseudo,random Numbers,Raising a Number to a Large Power,Computing the nth Fibonacci Number,thiruvalluvar university syllabus,unit 5,computer science basics,new syllabus,programming in c,example program in c,
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Hello, I need some assistance in writing a java program THAT MUST US.pdfFashionColZone
Hello, I need some assistance in writing a java program THAT MUST USE STACKS (LIFO).
Create a Calculator w/ GUI
Write a program that graphically displays a working calculator for simple infix expressions that
consist of: single-digit operands, the operators: +, -, *, and /, and parentheses.
Make the following assumptions:
unary operators (e.g. -2) are illegal
all operations, including division, are integer operations (and results are integers)
the input expression contains no embedded spaces and no illegal characters
the input expression is a syntactically correct infix expression
division by zero will not occur (consider how you can remove this restriction)
Create a GUI application, the calculator has a display and a keypad of 20 keys, which are
arranged as follows:
C
<
Q
/
7
8
9
*
4
5
6
-
1
2
3
+
0
(
)
=
As the user presses keys to enter an infix expression, the corresponding characters appear in the
display. The C (Clear) key erases all input entered so far; the < (Backspace) key erases the last
character entered. When the user presses the = key, the expression is evaluated and the result
appended to the right end of the expression in the display window. The user can then press C and
enter another expression. If the user presses the Q (Quit) key, the calculator ceases operation and
is erased from the screen.
C
<
Q
/
7
8
9
*
4
5
6
-
1
2
3
+
0
(
)
=
Solution
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Calculator extends JFrame implements ActionListener {
JPanel[] row = new JPanel[5];
JButton[] button = new JButton[19];
String[] buttonString = {\"7\", \"8\", \"9\", \"+\",
\"4\", \"5\", \"6\", \"-\",
\"1\", \"2\", \"3\", \"*\",
\".\", \"/\", \"C\", \"\",
\"+/-\", \"=\", \"0\"};
int[] dimW = {300,45,100,90};
int[] dimH = {35, 40};
Dimension displayDimension = new Dimension(dimW[0], dimH[0]);
Dimension regularDimension = new Dimension(dimW[1], dimH[1]);
Dimension rColumnDimension = new Dimension(dimW[2], dimH[1]);
Dimension zeroButDimension = new Dimension(dimW[3], dimH[1]);
boolean[] function = new boolean[4];
double[] temporary = {0, 0};
JTextArea display = new JTextArea(1,20);
Font font = new Font(\"Times new Roman\", Font.BOLD, 14);
Calculator() {
super(\"Calculator\");
setDesign();
setSize(380, 250);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(5,5);
setLayout(grid);
for(int i = 0; i < 4; i++)
function[i] = false;
FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
FlowLayout f2 = new FlowLayout(FlowLayout.CENTER,1,1);
for(int i = 0; i < 5; i++)
row[i] = new JPanel();
row[0].setLayout(f1);
for(int i = 1; i < 5; i++)
row[i].setLayout(f2);
for(int i = 0; i < 19; i++) {
button[i] = new JButton();
button[i].setText(buttonString[i]);
button[i].setFont(font);
button[i].addActionListener(this);
}
display.setFont(font);
display.setEditable(false);
display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
display.setPreferredSize(displayDimension);
for(int.
Implement the following sorting algorithms Bubble Sort Insertion S.pdfkesav24
Implement the following sorting algorithms: Bubble Sort Insertion Sort. Selection Sort.
Merge Sort. Heap Sort. Quick Sort. For each of the above algorithms, measure the execution
time based on input sizes n, n + 10(i), n + 20(i), n + 30(i), .. ., n + 100(i) for n = 50000 and i =
100. Let the array to be sorted be randomly initialized. Use the same machine to measure all the
algorithms. Plot a graph to compare the execution times you collected in part(2).
Solution
This code wil create a graph for each plots comparing time for different sorting methods and also
save those plots in the current directory.
from random import shuffle
from time import time
import numpy as np
import matplotlib.pyplot as plt
def bubblesort(arr):
for i in range(len(arr)):
for k in range(len(arr)-1, i, -1):
if (arr[k] < arr[k-1]):
tmp = arr[k]
arr[k] = arr[k-1]
arr[k-1] = tmp
return arr
def selectionsort(arr):
for fillslot in range(len(arr)-1,0,-1):
positionOfMax=0
for location in range(1,fillslot+1):
if arr[location]>arr[positionOfMax]:
positionOfMax = location
temp = arr[fillslot]
arr[fillslot] = arr[positionOfMax]
arr[positionOfMax] = temp
return arr
def insertionsort(arr):
for i in range( 1, len( arr ) ):
tmp = arr[i]
k = i
while k > 0 and tmp < arr[k - 1]:
arr[k] = arr[k-1]
k -= 1
arr[k] = tmp
return arr
# def mergesort(arr):
#
# if len(arr)>1:
# mid = len(arr)//2
# lefthalf = arr[:mid]
# righthalf = arr[mid:]
#
# mergesort(lefthalf)
# mergesort(righthalf)
#
# i=0
# j=0
# k=0
# while i < len(lefthalf) and j < len(righthalf):
# if lefthalf[i] < righthalf[j]:
# arr[k]=lefthalf[i]
# i=i+1
# else:
# arr[k]=righthalf[j]
# j=j+1
# k=k+1
#
# while i < len(lefthalf):
# arr[k]=lefthalf[i]
# i=i+1
# k=k+1
#
# while j < len(righthalf):
# arr[k]=righthalf[j]
# j=j+1
# k=k+1
#
# return arr
def mergesort(x):
result = []
if len(x) < 2:
return x
mid = int(len(x)/2)
y = mergesort(x[:mid])
z = mergesort(x[mid:])
i = 0
j = 0
while i < len(y) and j < len(z):
if y[i] > z[j]:
result.append(z[j])
j += 1
else:
result.append(y[i])
i += 1
result += y[i:]
result += z[j:]
return result
def quicksort(arr):
less = []
equal = []
greater = []
if len(arr) > 1:
pivot = arr[0]
for x in arr:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
return quicksort(less)+equal+quicksort(greater) # Just use the + operator to join lists
else:
return arr
#### Heap sort
def heapsort(arr): #convert arr to heap
length = len(arr) - 1
leastParent = length / 2
for i in range(leastParent, -1, -1):
moveDown(arr, i, length)
# flatten heap into sorted array
for i in range(length, 0, -1):
if arr[0] > arr[i]:
swap(arr, 0, i)
moveDown(arr, 0, i - 1)
def moveDown(arr, first, last):
largest = 2 * first + 1
while largest <= last: #right child exists and is larger than left child
if (largest < last) and(arr[largest] < arr[largest + 1]):
largest += 1
# right child is larger than parent
if arr[largest] > arr[first]:
swap(arr, largest, first)# move down to largest child
first = largest
lar.
The following is my code for a connectn program. When I run my code .pdfeyelineoptics
The following is my code for a connectn program. When I run my code in the tester, I failed two
out 10 tests. I was hoping for some help in finding what causes these errors. I have included the
homework prompt and test failed results. Thank you so much!
#include
#include
#include
void read_args(int argc, char *argv[], int* num_rows, int* num_cols, int *num_pieces_to_win);
void create_board(int num_rows, int num_cols, char*** board, int* turn);
void print_board(int num_rows, int num_cols, char** board);
void destroy_board(int num_rows, char*** board);
void play_game(int num_rows, int num_cols, int num_pieces_to_win, int turn, char** board);
void check_move();
void get_play(int num_rows, int num_cols, char** board, int* user_move);
void make_move(int num_rows, char**board, int user_move, char pieces);
bool play_is_valid(int num_cols, int num_rows, char** board, int user_move_num, int
user_move);
bool game_over(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool game_won(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool game_tied(int num_rows, int num_cols, int num_pieces_to_win, char**board);
bool row_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool col_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool diag_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool right_diag_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
bool left_diag_win(int num_rows, int num_cols, int num_pieces_to_win, char** board);
void read_args(int argc, char *argv[], int* num_rows, int* num_cols, int *num_pieces_to_win) {
//reads command input and ensures there are exactly three numbers
if (argc > 4) {
printf(\"Too many arguments entered\ \");
printf(\"Usage connectn.out num_rows num_columns
number_of_pieces_in_a_row_needed_to_win\");
exit(0);
}
else if (argc < 4) {
printf(\"Not enough arguments entered\ \");
printf(\"Usage connectn.out num_rows num_columns
number_of_pieces_in_a_row_needed_to_win\");
exit(0);
}
else { //puts user input into variables
sscanf(argv[1], \"%d\", &*num_rows);
sscanf(argv[2], \"%d\", &*num_cols);
sscanf(argv[3], \"%d\", &*num_pieces_to_win);
}
return;
}
void create_board (int num_rows, int num_cols, char*** board, int* turn) {
//set up the connect-n board
const char BLANK_SPACE = \'*\';
int i, j;
*turn = 0; //player 1 always goes first
*board = (char**)malloc(num_rows * sizeof(char*)); //creates pointers to the rows
for (i = 0; i < num_rows; ++i){ //for each row
(*board)[i] = (char*)malloc(num_cols * sizeof(char)); //create it
for (j = 0; j < num_cols; j++) { //fill in the row with blanks
(*board)[i][j] = BLANK_SPACE;
}
}
}
void print_board (int num_rows, int num_cols, char** board) {
//displays connect-n board
int i, j;
int k = 0;
for(i = 0; i < num_rows; i++){
printf(\"%d \", ((num_rows- i) - 1));
for(j = 0; j < num_cols; ++j){
printf(\"%c \", board[i][j]);
}
printf(\"\ \");
}
printf(\" %d \", k);
for(j = 1; j <.
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAMSaraswathiRamalingam
Fundamental Algorithms, Exchanging the values of Two Variables,Counting,Summation of a Set of Numbers,Factorial Computation ,Sine Function Computation ,Generation of the Fibonacci Sequence,Reversing the Digits of an Integer,Base Conversion , Character to Number Conversion , Factoring Methods: Finding the square Root of a Number ,The Smallest Divisor of an Integer,The Greatest Common Divisor of the two integers,Generating Prime Numbers,Computing the Prime Factors of an integer ,Generation of Pseudo,random Numbers,Raising a Number to a Large Power,Computing the nth Fibonacci Number,thiruvalluvar university syllabus,unit 5,computer science basics,new syllabus,programming in c,example program in c,
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
May Marketo Masterclass, London MUG May 22 2024.pdfAdele Miller
Can't make Adobe Summit in Vegas? No sweat because the EMEA Marketo Engage Champions are coming to London to share their Summit sessions, insights and more!
This is a MUG with a twist you don't want to miss.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
18. basic_calculation = input("Enter Your Choice : ")
print("")
#Conditions in Basic Calculations
if basic_calculation == "1":
num1=float(input("Enter First Number : "))
num2=float(input("Enter Second Number : "))
print("")
addf(num1,num2)
elif basic_calculation == "2":
num1=float(input("Enter First Number : "))
num2=float(input("Enter Second Number : "))
print("")
differencef(num1,num2)
elif basic_calculation == "3":
num1=float(input("Enter First Number : "))
num2=float(input("Enter Second Number : "))
print("")
18
19. productf(num1,num2)
elif basic_calculation == "4":
num1=float(input("Enter First Number : "))
num2=float(input("Enter Second Number : "))
print("")
divisionf(num1,num2)
elif basic_calculation == "5":
num1=float(input("Enter First Number : "))
num2=float(input("Enter Second Number : "))
print("")
floatdivf(num1,num2)
elif basic_calculation == "0":
Main_Code()
else:
print("Wrong Input")
print("")
Basic_Code()
def Advanced_Code():
19
20. print("Enter (1) for sin")
print("Enter (2) for cos")
print("Enter (3) for tan")
print("Enter (4) for cosec")
print("Enter (5) for sec")
print("Enter (6) for cot")
print("Enter (7) for log")
print("Enter (8) for square root")
print("Enter (9) for factorial")
print("Enter (10) for raise to power")
print("Enter (0) to Go Back")
print("")
#Input in Advanced Calculations
print("")
print("----------------------------------------")
print("")
advanced_calculation = input("Enter Your Choice : ")
print("")
#Conditions in Advanced Calculations
20
21. if advanced_calculation == "1":
num1=float(input("Enter number in Radian : "))
print("")
sinf(num1)
elif advanced_calculation == "2":
num1=float(input("Enter number in Radian : "))
print("")
cosf(num1)
elif advanced_calculation == "3":
num1=float(input("Enter number in Radian : "))
print("")
tanf(num1)
elif advanced_calculation == "4":
num1=float(input("Enter number in Radian : "))
print("")
cosecf(num1)
21
22. elif advanced_calculation == "5":
num1=float(input("Enter number in Radian : "))
print("")
secf(num1)
elif advanced_calculation == "6":
num1=float(input("Enter number in Radian : "))
print("")
cotf(num1)
elif advanced_calculation == "7":
num1=float(input("Enter number : "))
print("")
logf(num1)
elif advanced_calculation == "8":
num1=float(input("Enter number : "))
print("")
sqrtf(num1)
22
23. elif advanced_calculation == "9":
num1=int(input("Enter number : "))
print("")
factorialf(num1)
elif advanced_calculation == "10":
num1=float(input("Enter number on base : "))
num2=float(input("Enter number on power : "))
print("")
powerf(num1,num2)
elif advanced_calculation == "0":
Main_Code()
else:
print("Wrong Input")
print("")
Advanced_Code()
def Area_Calculation_Code():
print("Enter (1) for Area of Triangle")
print("Enter (2) for Area of Square")
23
24. print("Enter (3) for Area of Rectangle")
print("Enter (4) for Area of Circle")
print("Enter (5) for Area of Semicircle")
print("Enter (0) to Go Back")
print("")
#Input in Area Calculation
print("")
print("----------------------------------------")
print("")
area_calculation = input("Enter Your Choice : ")
#Condition in Area Calculation
if area_calculation == "1":
base=float(input("Enter Base of the Triangle : "))
height=float(input("Enter Height of the Triangle : "))
area_of_triangle = 0.5*base*height
print("")
print("Area of Triangle is ",area_of_triangle," Sq. Unit")
24
25. input()
print("Enter e to exit")
print("")
print("Enter 0 to Continue")
print("")
choice_in_function = input("Enter Your Choice : ")
if choice_in_function == "e" or choice_in_function == "E":
exit
elif choice_in_function == "0":
Main_Code()
else:
print("")
print("Invalid Choice")
print("")
Main_Code()
elif area_calculation == "2":
side=float(input("Enter Side of the Square : "))
25
26. area_of_square = side*side
print("")
print("Area of Square is ",area_of_square," Sq. Unit")
elif area_calculation == "3":
length=float(input("Enter length of the Square : "))
breadth=float(input("Enter breadth of the Square : "))
area_of_rectangle = length*breadth
print("")
print("Area of Rectangle is ",area_of_rectangle," Sq. Unit")
elif area_calculation == "4":
radius=float(input("Enter Radius of the Circle : "))
area_of_circle = 3.14*radius*radius
print("")
print("Area of Circle is ",area_of_circle," Sq. Unit")
elif area_calculation == "5":
radius =float(input("Enter Radius of the Semi-Circle : "))
area_of_semicircle = 0.5*3.14*radius*radius
print("")
print("Area of Semi-Circle is ",area_of_semicircle," Sq. Unit")
elif area_calculation == "0":
26