Questions
/* complete javascript file according to the individual instructions given in the comments. */ // 1)...

/* complete javascript file according to the individual instructions
given in the comments. */

// 1) Prompt the user to enter their first name. 
// Display an alert with a personal greeting for the user 
// with their first name (example: Hello, Dave!)



// 2) Create a Try code block that will cause a ReferenceError.  
// Create a Catch code block that will display the error in the  
// console with console.error() 



// 3) Prompt the user to enter a number. If the user input is 
// not a number, throw a custom error to the console and alert 
// the user. 



// Solving a Problem!
// 4) Create a function named productOf() that accepts 
// two numbers as parameters: productOf(num1,num2)
// Create a Try block in the function that checks to see if 
// num1 and num2 are numbers.
// If both parameters are numbers, return the product of 
// the two numbers: num1 * num2
// If either num1 or num2 are not numbers, throw a custom 
// error to the console and alert the user.
// After defining the function, ask the user to enter a number. 
// Then ask the user to enter a second number.
// Call the function with the values entered by the user.



// Solving a Problem!
// 5) Create a loop that counts from 1 to 20. 
// If the current number is even, add it to this empty array:
var myArray = [];
// If the current number is odd, log an odd number warning to 
// the console.
// However, if the number equals 19, set a debug breakpoint.
// After the loop completes, print the array to the console.

In: Computer Science

I am needing to initialize a server socket and wait for incoming connections in C programming....

I am needing to initialize a server socket and wait for incoming connections in C programming. I am also required to create a thread to handle my client and able to pass messages between them asynchronously. I would ideally like to start my server with pthreads to allow for multiple connections.

I have 2 functions started:

int serverRun(){

this will be the meat of the server code with sockets

}

int serverStart()

{

This is where I want to initiate the server

}

In: Computer Science

Use python 2.7 & plotly (dash) to draw bar/line graph for below data OrderedDict([('0K', 7.239253544865276), ('PK',...

Use python 2.7 & plotly (dash) to draw bar/line graph for below data

OrderedDict([('0K', 7.239253544865276), ('PK', 3.236322216916338), ('1', 6.415793586505012), ('2', 6.020145027564326), ('3', 5.658685936530415), ('4', 5.37435274038192), ('5', 5.1860079887723085), ('6', 5.035941053040876), ('7', 5.1264549715408), ('8', 5.553318856838249), ('9', 12.200551540951867), ('10', 11.195203964258715), ('11', 8.990680759944928), ('12', 12.767287811888968)])

Make sure all keys, especially the 0K & PK, are showing in the x-axis.

In: Computer Science

Please code the following, using the language java! Build a simple calculator that ignores order of...

Please code the following, using the language java!

Build a simple calculator that ignores order of operations. This “infix” calculator will read in a String from the user and calculate the results of that String from left to right. Consider the following left-to-right calculations:

"4 + 4 / 2"
"Answer is 4"   //not 6, since the addition occurs first when reading from left to right
“1 * -3 + 6 / 3”
“Answer is 1”   //and not -1Start by copying the driver code below.

Read this program and notice the comments before you proceed –your assignments in the lecture section will require you to comment accordingly, or they will drop a complete letter grade! Begin tracing the program in main, and your code will go in the calculate() function, so start writing code there. Hints:

  • Build the starter code using a snippet below.
  • Assume spaces between all numbers and operators.
  • If a number is negative (like -3), there will be no space between the sign and the number. Use Scanner and nextInt() to read each integer. Use Scanner and what operation to read a single character? (our operator?).
  • You can also use StringTokenizer to do these tasks as well.
  • Using the comments below, can you write the regular expression that would recognize this grammar?'
import ?; /*
 * InFixCalc, V0.0 (concept borrowed from Carol Zander's Infix Calculator)
 * Complete the calculate() function below to build a simple, infix
 * calculator that evaluates a compound expression from left to right,
 * regardless of operator precedence
 *
 * Example: " 1 * -3 + 6 / 3"
 * Execution: calculate 1 * -3 first, then -3 + 6 next, then 3 / 3
 * last to obtain the value 1
*
* Solution by 
*/
public class InFixCalc {
    //example pattern: "3 + 5"
    //general pattern: <lhs='3'> <operation='+'> <rhs='5'> //extended pattern:     ...  
    //special case: 
    //other special cases?

    public static void main(String[] args) { //String input = "4 + 4";
        //String input = "4 + 4 / 2";
        //String input ="1 * -3";
        String input ="1 * -3 + 6 / 3";
        //String input ="5";
        //String input ="-5";
        int answer = calculate(input);
        System.out.println("Answer is " + answer);
    }

//preconditions: all binary operations are separated via a space
//postconditions: returns the result of the processed string
    public static int calculate(String input) {
        int lhs,rhs; //short for left-hand & right-hand side
        char operation;
        /*todo: your name and code goes here*/
        /*You need a Scanner(or StringTokenizer) to get tokens
          *Then you need a loop, and switch inside that loop*/
        return lhs;
    }
}

In: Computer Science

Let’s give a formal proof that RadixSort works and give a bound on its runtime. We...

Let’s give a formal proof that RadixSort works and give a bound on its runtime.

We start with correctness:

Lemma RadixSort will properly sort any n natural numbers.
Prove this statement. You can use any strategy you want, but we recommend using induction on l (the number of digits that each value has).

In: Computer Science

Consider the following if statement, where doesSignificantWork​, ​makesBreakthrough​, and nobelPrizeCandidate​ are all boolean variables: if doesSignificantWork...

Consider the following if statement, where doesSignificantWork​, ​makesBreakthrough​, and nobelPrizeCandidate​ are all boolean variables:
if doesSignificantWork : if makesBreakthrough :
nobelPrizeCandidate = True else
nobelPrizeCandidate = False elif not doesSignificantWork:
nobelPrizeCandidate = False
(assume that ​doesSignificantWork and ​makesBreakthrough ​have been initialized, there is no error)
First, write a simpler ​if statement that is equivalent to this one. Then write a single assignment statement that does the same thing.
(Hint: Try to trace this piece of code with all possible initial values for makesBreakthrough and ​doesSignificantWork​. It helps you to understand the code and then you can simplify it and rewrite it).
CODE FOR PYTHON

In: Computer Science

CREATE TABLE campaign ( cmte_id             varchar(12), cand_id             varchar(12), cand_nm     &nbsp

CREATE TABLE campaign

(

cmte_id             varchar(12),

cand_id             varchar(12),

cand_nm             varchar(40),

contbr_nm           varchar(40),

contbr_city         varchar(40),

contbr_st           varchar(40),

contbr_zip          varchar(20),

contbr_employer     varchar(60),

contbr_occupation   varchar(40),

contb_receipt_amt   numeric(6,2),

contb_receipt_dt    varchar(20),

receipt_desc        varchar(40),

memo_cd             varchar(20),

memo_text           varchar(20),

form_tp               varchar(20),

file_num            varchar(20),

tran_id             varchar(20),

election_tp         varchar(20)

Write SQL queries using the campaign data table.

-- 4. show the candidate name and number of contributions, for each candidate

-- Order by decreasing number of contributions.

-- 5. show the candidate name and average contribution amount for each candidate,

-- looking at positive contributions only

-- Order by decreasing average contribution amount.

-- 6. show the candidate name and the total amount received by each candidate.

-- Order the output by total amount received.

In: Computer Science

Python Explain what happens when a user clicks a command button in a fully functioning GUI...

Python

Explain what happens when a user clicks a command button in a fully functioning GUI program.

In: Computer Science

Python 1.Explain what happens when a program receives a non-numeric string when a number is expected...

Python

1.Explain what happens when a program receives a non-numeric string when a number is expected as input, and explain how the try-except statement can be of use in this situation.

2.What is meant by the state of an object, and how does the programmer access and manipulate it?

3.Explain the differences between instance variables and temporary variables. Focus on their visibility in a class definition, and on their roles in managing data for an object of that class.

4.Explain the purpose of the variable self in a Python class definition.

In: Computer Science

You scan through a list of n elements, keeping track of the max. Every time you...

You scan through a list of n elements, keeping track of the max. Every time you encounter a new max, you update some variable. How many times do you expect to make such an update?

Define the answer as a random variable, break it into indicator random variables, use linearity of expectation, evaluate each IRV, and finally express the answer as best you can using O, Ω, or Θ.

In: Computer Science

You are given an array of arrays a. Your task is to group the arrays a[i]...

You are given an array of arrays a. Your task is to group the arrays a[i] by their mean values, so that arrays with equal mean values are in the same group, and arrays with different mean values are in different groups.

Each group should contain a set of indices (i, j, etc), such that the corresponding arrays (a[i], a[j], etc) all have the same mean. Return the set of groups as an array of arrays, where the indices within each group are sorted in ascending order, and the groups are sorted in ascending order of their minimum element.

Example

  • For
  • a = [[3, 3, 4, 2],
  •      [4, 4],
  •      [4, 0, 3, 3],
  •      [2, 3],
  •      [3, 3, 3]]

the output should be

meanGroups(a) = [[0, 4],

                 [1],

                 [2, 3]]

  • mean(a[0]) = (3 + 3 + 4 + 2) / 4 = 3;
  • mean(a[1]) = (4 + 4) / 2 = 4;
  • mean(a[2]) = (4 + 0 + 3 + 3) / 4 = 2.5;
  • mean(a[3]) = (2 + 3) / 2 = 2.5;
  • mean(a[4]) = (3 + 3 + 3) / 3 = 3.

There are three groups of means: those with mean 2.5, 3, and 4. And they form the following groups:

  • Arrays with indices 0and 4 form a group with mean 3;
  • Array with index 1 forms a group with mean 4;
  • Arrays with indices 2and 3 form a group with mean 2.5.

Note that neither

meanGroups(a) = [[0, 4],

                 [2, 3],

                 [1]]

nor

meanGroups(a) = [[0, 4],

                 [1],

                 [3, 2]]

will be considered as a correct answer:

    • In the first case, the minimal element in the array at index 2 is 1, and it is less then the minimal element in the array at index 1, which is 2.
    • In the second case, the array at index 2 is not sorted in ascending order.
  • For
  • a = [[-5, 2, 3],
  •      [0, 0],
  •      [0],
  •      [-100, 100]]

the output should be

meanGroups(a) = [[0, 1, 2, 3]]

The mean values of all of the arrays are 0, so all of them are in the same group.

Input/Output

  • [execution time limit] 3 seconds (java)
  • [input] array.array.integer a

An array of arrays of integers.

Guaranteed constraints:
1 ≤ a.length ≤ 100,
1 ≤ a[i].length ≤ 100,
-100 ≤ a[i][j] ≤ 100.

  • [output] array.array.integer

An array of arrays, representing the groups of indices

In: Computer Science

create table candidate ( cand_id   varchar(12) primary key,   -- cand_id name       varchar(40)           --...

create table candidate (
cand_id   varchar(12) primary key,   -- cand_id
name       varchar(40)           -- cand_nm
);

create table contributor (
contbr_id   integer primary key,
name       varchar(40),           -- contbr_nm
city     varchar(40),           -- contbr_city
state       varchar(40),           -- contbr_st
zip       varchar(20),           -- contbr_zip
employer   varchar(60),           -- contbr_employer
occupation   varchar(40)           -- contbr_occupation
);

create table contribution (
contb_id   integer primary key,
cand_id   varchar(12),           -- cand_id
contbr_id   varchar(12),           -- contbr_id
amount   numeric(6,2),           -- contb_receipt_amt
date       varchar(20),           -- contb_receipt_dt
election_type varchar(20),           -- election_tp
tran_id   varchar(20),           -- tran_id
foreign key (cand_id) references candidate,
foreign key (contbr_id) references contributor
);

___________________________________________________

All three tables will be written to a single SQL file.

___________________________________________________

-- 16. set the SQLite output to be a file named 'campaign-normal.sql'
.output 'campaign-normal.sql'

-- 17. output the candidate schema, and then all candidate rows as SQL
-- insert statements.
-- Hint: the SQLite .mode command allows you to select that you want
-- rows of a query to be output as SQL insert statements, and the
-- table name to be specified.


-- 18. output the contributor schema, and then all contributor rows as SQL
-- insert statements.


-- 19. output the contribution schema, and then all contribution rows as SQL
-- insert statements.


-- 20. set the SQL output so that it no longer goes to a file

In: Computer Science

Python. 1.Why is it a good idea to write and test the code for laying out...

Python.

1.Why is it a good idea to write and test the code for laying out a window's components before you add the methods that perform computations in response to events?

2.Explain why you would not use a text field to perform input and output of numbers.

3.Write a line of code that adds a FloatField to a window, at position (1, 1) in the grid, with an initial value of 0.0, a width of 15, and a precision of 2.

4.What happens when you enter a number with a decimal point into an IntegerField?

5.When would you make a data field read-only, and how would you do this?

In: Computer Science

i need code that uses javafx where the feauture are. 1. like with menubar that allows...

i need code that uses javafx where the feauture are.
1. like with menubar that allows to save and open file
2. when it has to save file it has own file type like for example s.suv
3. it should be able to open that file s.suv and lets add more icon into it

In: Computer Science

Python. Tuples and strings can also be sliced and concatenated.       Let x = ['F','l','o','r','i','d','a']. How...

Python. Tuples and strings can also be sliced and concatenated.

      Let x = ['F','l','o','r','i','d','a']. How does cotDel(x, 3) compare to del x[3]?

      Let y = ('F','l','o','r','i','d','a'). How does cotDel(y, 3) compare to del y[3]?

      Let z = 'Florida'. How does cotDel(z, 3) compare to del z[3]?

      Give an explanation about what you observed. This question refers to the following statement.

Define function cotDel(s,i) that deletes the ith item of list s, s[i]. In other words this function should do what the statement del s[i] does. Your function should use slicing and concatenation. Test your function with the list x of problem 1, deleting x[2]. Furthermore, your code should be written so that your program can be imported by other programs to make the function cotDel(s,i) available to them.

In: Computer Science