Questions
select one of the below process synchronization problem and describe the problem and its solution 1)...

select one of the below process synchronization problem and describe the problem and its solution

1) producer - consumer problem
2) the dining - philosophers problem
3) reader - writer problem
4) sleeping barber problem

In: Computer Science

Write a program to swap mth and nth elements of a linked list. User should give...

Write a program to swap mth and nth elements of a linked list.

User should give input.

In: Computer Science

Count all nonzero elements, odd numbers and even numbers in a linked list. Code needed in...

Count all nonzero elements, odd numbers and even numbers in a linked list.

Code needed in java.

In: Computer Science

I want a unique c code for the following parts mentioned below: Please try to solve...

I want a unique c code for the following parts mentioned below: Please try to solve the following. I am not able to solve it.

I have already provideD the code for Part 1 and Part 2. You may only show their working output screenshots. You JUST need to *MODIFY PART 3* and upload the code for it

Please provide details too by highlighting what you modified,

PERFORM ALL THE PARTS SEPARATELY IN SHELL SERVER AND ATTACH CODE.

DO NOT SIMPLY PASTE THE CODE THAT I PROVIDED. PLEASE UPDATE THE PARTS THAT I MENTIONED BELOW

Details are provided to write code.

PART 1:

I have provided a file (threadhello.c that generates 10 threads, each of which simply prints out a "hello world" message before terminating. Examine this code carefully.

 
#include <pthread.h> 
#include <stdlib.h> 
#include <stdio.h> 

#define NUMBER_OF_THREADS 10

/* This is a structure that is used to pass parameters to the thread.
 * Currently, the only param is the thread id */
typedef struct
{
    int tid;
} paramListType;

/* *params should be pointing to a structure of paramListType */ 
void *print_hello_world(void *params)
{
    paramListType *paramPtr = params;

    printf("Hello World. Greetings from thread %d\n", paramPtr->tid) ;
    pthread_exit(NULL);
}

int main(int argc, char **argv)
{
    pthread_t threads[NUMBER_OF_THREADS];
    int status, i;
    
    /* parms will be a pointer to a parmListType structure that will
     * contain the thread id value */
    paramListType *params;
    
    for(i=0; itid = i;
        
        status = pthread_create(&threads[i], NULL, print_hello_world, (void *) params);
        
        if(status != 0)
        {
            printf("pthread_create returned error code %d\n", status);
            exit(-1);
        }
    }
/* if the program doesn't wait for all the threads to finish, 
     * you may not see the print message from some of them */
    for(i=0; i<NUMBER_OF_THREADS; i++)
    {
        status=pthread_join(threads[i], NULL);
    }
    exit(0);
}
    
Please also show how to Upload this file (you may use an ftp

client or, better yet, look up how to use the scp command (prefered))

Compile this code using the following command: clang threadhello.c -lpthread

Run this command several times. Submit at least 3 screenshots of different outputs that were all a result of running this code

DELIVERABLE #1: >=3 screenshots of this code correctly running

PART 2:

I have also provided a file threadarray.c Upload and run this program. Run the program several times where you have increased the size of the array.

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>  

#define ARRAY_SIZE 15

/* This is a structure that is used to pass parameters to the thread.
 * Currently, the only param is the thread id */
typedef struct
{
    int* arr;
    int tid;
} paramListType;

void* threadSum(void* p){
    paramListType* ptr = (paramListType*)p;
    int n = ptr->tid;
    
    // Declare sum dynamically to return to join:
    int* thread_sum = (int*) calloc(1, sizeof(int));
    
    //NOTE: uncomment the printf commands below to see behind the scenes
    if(n == 0){
        for(int i = 0; i < ARRAY_SIZE/2; i++){
                  //printf("Working in thread %d, at position: %d\n", ptr->tid , i );
            thread_sum[0] = thread_sum[0] + ptr->arr[i];
        }
    }
    else{
        for(int i = ARRAY_SIZE/2; i < ARRAY_SIZE; i++){
            //printf("Working in thread %d, at position: %d\n", ptr->tid , i );
            thread_sum[0] = thread_sum[0] + ptr->arr[i];
         }
    }
    
    pthread_exit(thread_sum);
}

int main(int argc, char **argv)
{
    // Declare integer array [1,2,3,4,5,6,7,8,9,10]:
    int* int_arr = (int*) calloc(ARRAY_SIZE, sizeof(int));
    for(int i = 0; i < ARRAY_SIZE; i++)
        int_arr[i] = i + 1;
        
    // Declare arguments for both threads:
    paramListType thread_params[2];
    thread_params[0].tid = 0;
    thread_params[0].arr = int_arr;
    thread_params[1].tid = 1;
    thread_params[1].arr = int_arr;
    
    // Declare thread IDs:
    pthread_t tids[2];
    
    // create threads:
    pthread_create(&tids[0], NULL, threadSum, &thread_params[0]);
    pthread_create(&tids[1], NULL, threadSum, &thread_params[1]);
    
    // declare sums:
    int* sum0;
    int* sum1;
    
    // retrieve sum of threads:
    pthread_join(tids[0], (void**)&sum0);
    pthread_join(tids[1], (void**)&sum1);
    
    printf("Sum of whole array = %i\n", *sum0 + *sum1);
    
    return 0;
}

DELIVERABLE #2: a screenshot of this code correctly running

PART 3: (REALLY IMPORTANT PART)

Change this program so that it fills the array values with (truly) random numbers between 1 and 100. Then, change the program so that it makes use of five (5) threads to sum the values in the array.   

Hint: you may want to check that your five thread version is correctly working on known totals before updating your code to run on random values.

DELIVERABLE #3: your new program file
DELIVERABLE #4: a screenshot of your program running

In: Computer Science

Find the largest and smallest element of a linked list, print total of all elements and...

Find the largest and smallest element of a linked list, print total of all elements and find out the average.

Code needed in java

In: Computer Science

Given lists L1, L2 and L3, delete all the nodes having even number in info part...

Given lists L1, L2 and L3, delete all the nodes having even number in info part from the list L1 and insert into list L2 and all the nodes having odd numbers into list L3.

Code needed in java.

In: Computer Science

Mortgage Calculator Create a form that allows you to enter in interest rate, monthly payment, principal...

Mortgage Calculator

Create a form that allows you to enter in interest rate, monthly payment, principal , and number of years. Your Java Servlet program then generates a table containing a row of output for each month of a mortgage. Your table should show Month number, New Principal, Interest Paid during the month. If the load is paid off, your table needs to properly stop.

*********************************** Sample Output *********************************

Interest Calculations

Calculating for:

interest rate/year =6

starting principal=10000

payment/month =1000

months =60

Month Number Principal Interest
1 9050.00 50.00
2 8095.25 45.25
3 7135.73 40.48
4 6171.40 35.68
5 5202.26 30.86
6 4228.27 26.01
7 3249.41 21.14
8 2265.66 16.25
9 1276.99 11.33
10 283.37 6.38

Last Payment = 284.79
This includes interest:1.42 **************************************************************************************

HINTS:

Take a look at the "RadioActive" servlet example in the notes. This application is similar to this homework. You can ignore the bar image part ... it's not part of this homework.

You will want to have a loop for the number of 12 * (Number of years). On each iteration of the loop, you will want to calculate the interest paid which is:

interestPaid = (newPrincipal * interest)/(12*100)

The 12 is because of 12 months in a year. The 100 is due to the fact that interest rates (like 6) are computed as 0.06 in interest calculations.

newPrincipal = newPrincipal + interestPaid - monthlyPayment

To get rid of the large number of decimal places that show up when you print a double, there is a format method in the String class that can help. Consider the following code (similar to the printf stuff in System.out):

String sPrinciple = String.format("%.2f", principal);

in Java Servlet

In: Computer Science

Given two sorted linked lists, merge them into a third sorted linked list. If an element...

Given two sorted linked lists, merge them into a third sorted linked list. If an element is present in both the lists, it should occur only once in the third list.

Code needed in java.

In: Computer Science

Write a program to multiply a polynomial with a given number. Code needed in java.

Write a program to multiply a polynomial with a given number.

Code needed in java.

In: Computer Science

Write a class GBP2HKD containing the following methods: (a) constructor : which builds the frame shown...

Write a class GBP2HKD containing the following methods:

(a) constructor : which builds the frame shown on the right side. The frame consists of

• a pull-down menu "Action" with menu items "Convert" and "Exit",

• a textfield to enter GBP amount. Some text is in the text field to provide information to the user on what to input. The user needs to delete the text before entering the numbers.

• a label to display the amount of HKD (please use the exchange rate of 1 GBP to exchange for 9.9 HKD).

Copy the class, including import statement(s), as the answers to this part.

(b) actionPerformed() : which perform necessary actions when each menu item is selected. When "Convert" is selected, the amount of HKD is calculated and displayed on the label. When "Exit" is selected, the program terminates.

(c) main() : which creates an GBP2HKD object and sets it visible for testing.

In: Computer Science

(JAVA) Repeated Class diagram: Repeated + repeatedDetector(ArrayList<Integer> a) : int For this exercise, you will have...

(JAVA)

Repeated

Class diagram:

Repeated

+ repeatedDetector(ArrayList<Integer> a) : int

For this exercise, you will have to implement the class diagram above. Basically, the objective of this exercise is to develop the class and the previous method, in such a way that it tells us the amount of "repeated" elements that are in the dynamic array.

When we speak of "repeated", we mean counting the number of numbers of the same value that are found in succession.

Example 1: The method receives a dynamic array ArrayList <Integer>, which internally has this data: [1,1,4,1,4,1,1]

The method returns 2 (since it found 2 sequences of equal numbers).

Example 2: the method receives a dynamic array ArrayList <Integer>, which internally has this data: [1,1,1,1,1]

The method returns 1 (since it found 1 sequence of equal numbers).

In: Computer Science

Java Ask the user to input a letter grade in either upper or lower case. You...

Java Ask the user to input a letter grade in either upper or lower case. You are to output a message depending on the grade. When the input is A or a, output the word "Excellent!" When the input is B or b, output "Very Good" When the input is C or c, output "Satisfactory" For any other input you must output the word "Fail".

In: Computer Science

SGX Why is the initial program loaded into an SGX enclave unencrypted? What does a client...

SGX

  1. Why is the initial program loaded into an SGX enclave unencrypted?
  2. What does a client program have to verify before passing secrets to an SGX enclave?
  3. What state must be encrypted to protect the contents of an SGX enclave from the operating system or virtual machine monitor?
  4. Suppose code in an SGX enclave is waiting for data to arrive and calls the read() system call. What conditions must it check after the read() call returns to make sure it executes correctly?

In: Computer Science

Explain how do you do indexing in a circular queue? (java programing)

Explain how do you do indexing in a circular queue? (java programing)

In: Computer Science

Using the C language: In the old days, data was stored on punched cards of 80...

Using the C language:

In the old days, data was stored on punched cards of 80 or 96 columns.

Presume your job is to update a database to include the newly found data in the file punchcard.txt
into a currently used data base. In order to do that, you must read in the data in columnar format
and convert it to comma separated fields so it can be imported.

Using buffered I/O functions (e.g. fopen, fclose, fprintf, fscanf, fread or fwrite, fgets, fgets, etc),
read the columnar data in punchcard.txt into your program. It has the following fields:

   unsigned int user_number 6 columns
   char name 32 columns
   char address 32 columns

Write the data out to a file called import.txt which is of the following CSV format for each line:

   user_number,name,address<carriage return>

If the data in name or address contains a comma, it must be delimited with double quotes around
it. Make sure you remove all extraneous spaces in front of, or behind the data so that the entry in
the import.txt file has no extraneous spaces which is not part of the data. This is often called
"trimming" the data.

punchcard.txt contains...

289383Estefana Lewey 9940 Ohio Drv, 85021
930886Burl Livermore 226 Amherst, 08330
692777Lannie Crisler 8143 Woods Drv, 20901
636915Zena Hoke 82 Roehampton St, 47905
747793Vicente Clevenger 9954 San Carlos St., 55016
238335Lidia Janes 348 Depot Ave, 29576
885386Claire Paladino 587 Front Ave, 32703
760492Leland Stillson 9793 Boston Lane, 08610
516649Wes Althouse 8597 Annadale Drive, 06514
641421Nadia Gard 218 George Street, 29150

Thank you in advance.

In: Computer Science