Write and test a python program to demonstrate TCP server and client connections. The client sends a Message containing the 10 float numbers (FloatNumber[]) , and then server replies with a message containing maximum, minimum, and average of these numbers.
In: Computer Science
I need this code translated to C code. Thank you.
public class FourColorTheorem {
public static boolean isPrime(int num) {
// Corner case
if (num <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i < num; i++)
if (num % i == 0)
return false;
return true;
}
public static void main(String[] args) {
int squares[] = new int[100];
for (int i = 1; i < squares.length; i++) squares[i-1] = i *
i;
int n = 5;
while (true) {
boolean flag = false;
for (int i = 0; i < squares.length; i++) {
int difference = n - 2 * squares[i];
if (isPrime(difference)) {
flag = true;
// you can comment the below line
System.out.println(n + " = " + difference + " + 2*" +
Math.sqrt(squares[i]) + "*" + Math.sqrt(squares[i]));
break;
}
}
if (!flag) {
break;
}
n += 2;
}
System.out.println("Smallest counter example = " + n);
}
}
In: Computer Science
In the PDF file that will contain your screen shots, explain what is wrong with the code below. Do not just state thing like “line 3 should come after line 7,” you must explain why it needs to be changed. This shows that you are fully understanding what we are going over.
// This program uses a switch-case statement to assign a
// letter grade (A, B, C, D, or F) to a numeric test score.
#include <iostream>
using namespace std;
int main()
{
double testScore;
cout<< "Enter your test score and I will tell you\n";
cout<<"the letter grade you earned: ";
cin>> testScore;
switch (testScore)
{
case (testScore < 60.0):
cout << "Your grade is F. \n";
break;
case (testScore < 70.0):
cout << "Your grade is D. \n";
break;
case (testScore < 80.0):
cout << "Your grade is C. \n";
break;
case (testScore < 90.0):
cout << "Your grade is B. \n";
break;
case (testScore < 100.0):
cout << "Your grade is A. \n";
break;
default:
cout << "That score isn't valid\n";
return 0;
}
In: Computer Science
(PYTHON) Write a program:
This assignment will give you more experience on the use of:
1. integers (int)
2. floats (float)
3. conditionals
4. iteration
The goal of this project is to make a fictitious comparison of the federal income. You will ask the user to input their taxable income. Use the income brackets given below to calculate the new and old income tax. For the sake of simplicity of the project we will only consider individuals and not married users. We will also ignore any tax deductions while calculating income tax they can significantly alter the tax, but add too much complexity for our programming project.
New income tax brackets (2018 and newer)
Rate Income range
10% Up to $9,525
12% $9,526 to $38,700
22% $38,701 to $82,500
24% $82,501 to $157,500
32% $157,501 to $200,000
35% $200,001 to $500,000
37% over $500,000
Old income tax brackets (2017 and older)
Rate Income range
10% Up to $9,325
15% $9,326 to $37,950
25% $37,951 to $91,900
28% $91,901 to $191,650
33% $191,651 to $416,700
35% $416,701 to $418,400
39.6% over $418,401
Assignment Background
Being in the 25% tax bracket doesn’t mean you pay 25% on everything you make. The progressive tax system means that people with higher taxable incomes are subject to higher tax rates, and people with lower taxable incomes are subject to lower tax rates.
For example, let’s say you’re a filer with $32,000 in taxable income. That puts you in the 15% tax bracket in 2017. But do you pay 15% on all $32,000? No. Actually, you pay only 10% on the first $9,325; you pay 15% on the rest. (Look at the tax brackets above to see the breakout.) If you had $50,000 of taxable income, you’d pay 10% on that first $9,325 and 15% on the chunk of income between $9,326 and $37,950. And then you’d pay 25% on the rest, because some of your $50,000 of taxable income falls into the 25% tax bracket. The total bill would be $8,238.75 — about 16% of your taxable income, even though you’re in the 25% bracket.
Project Description
Your program must meet the following specifications:
1. At program start, prompt the user for their income
2. Repeatedly prompt the user for new income until a negative income is entered.
3. Calculate the income tax using the 2017 and 2018 tax bracket tables above.
4. For each income entered:
a. Calculate the 2017 income tax and store it in a variable.
b. Next calculate the 2018 income tax and store it in a variable
c. Print
i. The income
ii. The 2017 tax
iii. The 2018 tax
iv. The difference between the 2018 and 2017 tax rounded to cents.
v. The difference between the 2018 and 2017 tax as a percentage of the 2017 tax rounded to cents
Assignment Notes
1. To clarify the project specifications, sample output is appended to the end of this document.
2. Use a while loop with a Boolean that keeps looping as long as the income is greater than or equal to zero. Prompt for income before the loop and remember to convert the input string to an int (so you are comparing an int in your Boolean expression). Remember to prompt again at the end (aka “bottom”) of the loop.
4. There will be no error checking in this assignment. If a float or a string is entered at the prompt, the program will crash.
In: Computer Science
In: Computer Science
C++
For this assignment, you will write a C++ program to either add (A), subtract (S), multiply (M), and (N), or (O) two matrices if possible. You will read in the dimensions (rows, then columns) of the first matrix, then read the first matrix, then the dimensions (rows then columns) of the second matrix, then the second matrix, then a character (A, S, M, N, O) to determine which operation they want to do.
The program will then perform the operation, print the answer,
and quit. The program should have five functions in addition to
main - one for add, one for subtract, one for multiply, one for
add, and one for or, but main should do all the input and output.
Matrices will be no bigger than 10x10 and will be ints. You cannot
assume the matrices will be square.
SAMPLE:
$ ./a.out
input the row size and col size of A
3 2
input matrix A
2 1
-1 0
3 4
input the row size and col size of B
3 2
input matrix B
12 -18
3 9
6 -3
Choose your operation: A for add, S for subtract, M for multiply
N for and, O for or
A
The answer is:
14 -17
2 9
9 1 In: Computer Science
In: Computer Science
Hint: Use my files “threadSlides.xml”, “slideshow.xsd” and “slideHTML.xsl” as reference or starting point, and modify them for your project.
In: Computer Science
Write a Java program (name it InputSum) that prompts the user to enter positive integer numbers using a sentinel while loop. The program should accept integer inputs until the user enters the value -1 (negative one is the sentinel value that stops the while loop). After the user enters -1, the program should display the entered numbers followed by their sum as shown below. Notice that -1 is not part of the output. The program should ignore any other negative input and should continue to run.
Hint: to remember/save the entered (good) positive values, you can concatenate them into a string (separated by comas) that you can output later on.
The following are sample runs showing the input prompt and the outputs: (Notice the user may enter one value per line. DO NOT read inputs as String type)
Enter positive integers (-1 to quit): 10 -5 2 -1
Entered Numbers: 10, 2
The Sum: 12
Enter positive integers (-1 to quit): 1 2 3 4 5 6 -1
Entered Numbers: 1, 2, 3, 4, 5, 6
The Sum: 21
Enter positive integers (-1 to quit): 1 1 -7 1 1 -9 100 -1
Entered Numbers: 1, 1, 1, 1, 100
The Sum: 104
Make sure the program validates each entered number before processing it as the user may enter negative numbers (other than the sentinel value -1).
Design your program such that it allows the user to re-run the program with a different set of inputs in the same run.
Document your code, and organize and space out your outputs as shown above.
In: Computer Science
JAVA programming Classwork- please answer all prompts as apart of one java programming project
Part A
Add to your project this class Position, which has x and y coordinates.
Create an abstract class GameElt, which has a String name, an int health (keep it in the range 0 to 100) and a Position pos.
For GameElt, include a default constructor that starts pos at (0, 0), and a parameterized constructor that takes x and y coordinates and a name. health should always start at 100.
Create a class BigDarnHero which inherits from GameElt. Override toString so that when we print a hero, we see something like "Thondar the Hero (3, 17)" based on the name and the position. Other than toString and two constructors taking the same parameters as in GameElt, you do not need to add anything else for this class at this time.
Part B
☑ Create an interface MoveStrategy which requires methods
The idea is that moving in a given direction will change the given position, and chanceToFall will return true if a fall happened or false otherwise. How this happens will depend on the implementation in the actual classes.
Moving North or South will change the Y coordinate (vertical movement) moving East or West will change the X coordinate (horizontal movement). Direction will be passed as "N", "S", "E", or "W".
☑ Write a class WalkMoveStrategy which implements MoveStrategy. When walking, the position changes by 1 in the direction chosen, and a message like "Walking from (7,1) to (7, 2)." should also be printed out.
People who are walking have a 1 in 20 chance of falling. In chanceToFall choose a random number and use it to determine if chanceToFall returns true.
You do not need to add anything other than the methods to implement the strategy, not even a constructor
☑ Change GameElt so that it also has an instance variable moveStrat of type MoveStrategy.
Add to GameElt a method move(direction) which calls moveStrat's move method, passing it the direction given and GameElt's pos instance variable. Then call chanceToFall and if the GameElt fell while moving, print a statement about this and reduce health by 5.
☑ In all constructors for BigDarnHero, set the MoveStrategy to a new instance of WalkMoveStrategy.
☑ In a main program, create a BigDarnHero named "Mighty Thog" at (5, 3) and have them walk three moves north and one west. Print the hero before they move, and again after they have moved.
Part C
☑ Add another class RunMoveStrategy which implements MoveStrategy, and whose move method changes the position by 5 in the direction given, as well as printing something like "Running from (9, 3) to (4, 3). Boy my mighty thews are tired."
People who run have a 1 in 10 chance of falling.
☑ To BigDarnHero, add a method speedUp() which changes the hero's MoveStrategy to a RunMoveStrategy, and a method slowDown which changes the MoveStrategy to a WalkMoveStrategy.
☑ In the main program, have Mighty Thog move around, speed up, move around, slow down, and move around again.
Part D
☑ Add another strategy for movement, RandomCursedMoveStrategy, which changes the position by a random amount in a random direction, no matter what direction is passed in, and prints out something like "Truly, I am accursed and shall never get to class on time".
People moving by this strategy have a 50/50 chance of falling and hurting themselves.
In the main program, create a hero, set this as their movement strategy, and add some movement for them.
In: Computer Science
Professor Al Gorithum has the following grading policy:
Al likes to round each student's grade according to these rules:
For example, grade=84 will be rounded to 85 but grade=29 will not be rounded because the rounding would result in a number that is less than 40.
Given the initial grade value for each of Al's students, write code to automate the rounding process.
Detailed Description
What to submit:
In: Computer Science
def main():
print('This program determines whether you have hypertension.')
systolic_pressure = float(input('Enter your systolic pressure: '))
diastolic_pressure = float(input('Enter your diastolic pressure: '))
# insert statement here to call the hypertension_tester function
def hypertension_tester(dp, sp):
if sp >= 140 or dp >= 90:
print('You have hypertension')
else:
print('You do not have hypertension')
main()
A person has hypertension if systolic pressure is 140 or above or diastolic pressure is 90 or above. Which of the following statements correctly calls the hypertension_tester function?
| A. |
hypertension_tester(diastolic_pressure, systolic_pressure, ) |
|
| B. |
hypertension_tester(sp=systolic_pressure, dp=diastolic_pressure) |
|
| C. |
Both (A) and (B) are correct |
|
| D. |
Both (A) and (B) are incorrect |
def main():
num1 = float(input('Enter a number: '))
num2 = float(input('Enter another number: '))
difference, total = sum_diff(num1, num2)
print('Their total is', total)
print('Their difference is', difference)
# Insert definition of the sum_diff function here
main()
Which of the following definitions of the sum_diff function is correct?
| A. |
def sum_diff(x, y): sum = x + y diff = x - y return sum return diff |
|
| B. |
def sum_diff(x, y): sum = x + y diff = x - y return diff, sum |
|
| C. |
def sum_diff(x, y): sum = x + y diff = x - y |
|
| D. |
def sum_diff(x, y): sum = x + y diff = x - y return sum, diff |
my_dict = {21 : 'Amy', 45 : 'Bob', 62 : 'Connie', 57 : 'Dave'}
Which of the following statements will display the string 'Bob'?
| A. |
print(my_dict[1]) |
|
| B. |
print(my_dict[45]) |
|
| C. |
print(my_dict['45']) |
|
| D. |
None of the above |
Which of the following statements creates an empty set in Python?
| A. |
my_set = ( ) |
|
| B. |
my_set = set() |
|
| C. |
Both (A) and (B) create an empty set |
|
| D. |
None of the above |
Suppose all elements in the set my_set are integers. Which of the following Python program fragments selects all even numbers from my_set and stores them in my_set2?
| A. |
my_set2 = {x for x in my_set if x % 2 == 1} |
|
| B. |
my_set2 = [x for x in my_set if x % 2 != 0] |
|
| C. |
my_set2 = {x for x in my_set if x % 2 == 0} |
|
| D. |
none of the above |
In: Computer Science
Suppose that you have a list containing the following 10 letters: A C E G L M P S T Y. Binary search is applied for the following questions.
A) What is the maximum number of comparisons needed
to find if any letter in the alphabet is in the list?
B) How many comparisons would it take to find if A is
in the list? If K is in the list?
In: Computer Science
In: Computer Science
Consider the three following pieces of pseudocodes. In each case,
- Give the number of times "Hello" will be printed,
- Generalize, giving the number of times as a function of n
- Express this in theta notation in terms of n.
a) set n = 32
set i = 1
while i<= n
print "Hello"
i=i*2
endwhile
b) set n = 4
set i = 1
while i not equal to n
print "Hello"
i=i+2
endwhile
c) set n = 4
set i = 1
while i<= n
set j = 1
while j <= i
print "Hello"
j=j+1
endwhile
i=i+1
endwhile
In: Computer Science