Questions
Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and...

Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and each thread will request a pid, sleep for a random period of time, and then release the pid. (Sleeping for a random period of time approximates the typical pid usage in which a pid is assigned to a new process, the process executes and then terminates, and the pid is released on the process's termination.) On UNIX and Linux systems, sleeping is accomplished through the sleep() COMP2004 Assignment 3 & Assignment 4 Fall 2020 function, which is passed an integer value representing the number of seconds to sleep.

HERE IS MY CODE:

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

#define MIN_PID 300
#define MAX_PID 5000

typedef struct node {
int pid;
struct node* next;
}Node;

int allocate_map(void);
int allocate_pid(void);
void release_pid(int pid);
int i;
Node *head;
/*
main function tests all three functions
*/
int main(){
allocate_map();
printf("allocated pid: %d\n",allocate_pid());
printf("allocated pid: %d\n",allocate_pid());
printf("allocated pid: %d\n",allocate_pid());
printf("allocated pid: %d\n",allocate_pid());
release_pid(301);
printf("allocated pid: %d\n",allocate_pid());
allocate_map();
printf("allocated pid: %d\n",allocate_pid());
printf("allocated pid: %d\n",allocate_pid());
printf("allocated pid: %d\n",allocate_pid());
printf("allocated pid: %d\n",allocate_pid());
release_pid(305);
release_pid(30);

}

int allocate_map(void){
if(i>0){
return -1;
}
head = malloc(sizeof(Node));
Node *curr = head;
for(i=0;i<MAX_PID-MIN_PID;i++){
curr->pid = 0;
curr->next = (i<(MAX_PID-MIN_PID)) ? malloc(sizeof(Node)):NULL;
curr = curr->next;
}

return 1;
}
int allocate_pid(void){
if(head->next == NULL){
return -1;
}

int i = MIN_PID +1 ;

Node *iter = head;
if(head->pid == 0){
head->pid = MIN_PID;
return head->pid;
}
while(iter ->next->pid !=0 && i<MAX_PID){
iter = iter->next;
i++;
}
if(i<MAX_PID ){

iter->next->pid = i;
return iter->next->pid;
}
else{return -1;}
}

void release_pid(int pid){
if(head->next == NULL && head->pid==0){
printf("Nothing to release\n");
return;
}
else if(pid<MIN_PID || pid>MAX_PID){
printf("invalid release\n");
return;
}
if(head->pid==pid){
head->pid=0;
}
Node *iter = head;
while(iter->next !=NULL){
if(iter->next->pid==pid){
iter->next->pid=0;
return;
}
iter = iter->next;
}
printf("Nothing to release\n");
}

In: Computer Science

4. Your uncle has had a standard 30-year FRM with a 5% interest rate for 2...

4. Your uncle has had a standard 30-year FRM with a 5% interest rate for 2 years (24 months); the original principal was $200,000. One day he calls you up, very excitedly: “My bank offered to refinance my mortgage to a new 30-year ARM with a 2.5% interest rate. This is awesome – since the interest rate is cut in half, my monthly payment will also be cut in half!”

A. Is the second part of his statement correct? By how much does his payment go down? In addition to showing a calculation, please try to briefly explain intuitively what is going on.

B. How would your answer to part (a) change if your uncle had had his old mortgage for 20 years (240 months) instead?

C. How would your answer to part (a) change if the new mortgage has an initial interest only period?

In: Finance

MATLAB: Matrix M = [ 0 2 3 5; 7 3 8 4 ] Write one...

MATLAB:

Matrix M = [ 0 2 3 5; 7 3 8 4 ]

Write one command that stores all of the rows of columns 1, 2, and 3 of M into a matrix named M2.

In: Computer Science

Write 4 multiple choice questions on Comparison of water and sport drinks 2   Discuss foodborne illness....

  1. Write 4 multiple choice questions on Comparison of water and sport drinks

2   Discuss foodborne illness. Research one of the pathogens that cause this type of illness. You can choose whatever pathogen you want to discuss as long as it is associated with foodborne illness, with references, Where the pathogen is found. How to maintain safety. Any special precautions.

In: Nursing

6.27 Ch 2 Program: Painting a wall (C++) (4)Calculate the cost of the paint. Paint comes...

6.27 Ch 2 Program: Painting a wall (C++)
(4)Calculate the cost of the paint. Paint comes in six colors (Red, Yellow, Green, Blue, Black,White) Assign numbers 0-5 to these paint colors ie Red =0 and White =5. The costs for each of these paints is as follows:(2 pts) Now your program will be submission ready.

Main.cpp

#include <iostream>
#include <cmath>
using namespace std;
#include "paint.h"

int main() {
   double wallHeight;
   double wallWidth;
   double wallArea;
   double gallonsPaintNeeded;
   int cansNeeded,colorNum;
   Color paintColor;
   double costArray[numOfColors];

   cout << "Enter wall height (feet): "<<endl;
   cin >> wallHeight;
   cout << "Enter wall width (feet): "<<endl;
   cin >> wallWidth;
   cout<< "Enter paint color as an integer"<<endl;
   cout<<"Red   - Enter 0"<<endl;
   cout<<"Blue - Enter 1"<<endl;
   cout<<"Green - Enter 2"<<endl;
   cout<<"Yellow- Enter 3"<<endl;
   cout<<"Black - Enter 4"<<endl;
   cout<<"White - Enter 5"<<endl;
   cout<<"Your color ?"<<endl;
   cin>>colorNum;
   paintColor= (Color)colorNum; // cast the integer to type Color

// Calculate and output wall area
// FIXME (1): Calculate the wall's area
   cout << "Wall area: " << wallArea << " square feet" << endl;   // FIXME (1): Finish the output statement


   // FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall

   cout << "Paint needed: " << gallonsPaintNeeded << " gallons" << endl;

   // FIXME (3): Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer

   cout << "Cans needed: " << cansNeeded <<" can(s)" << endl;
   //FIX ME (3) populate the cost Array and calculate the total cost of the paint

cout << "TotalCost: $" << totalCost<<" for "<<cansNeeded;
switch (paintColor){
case Red: cout<<" Red";
break;
case Blue: cout<<" Blue";
break;
case Green: cout<<" Green";
break;
case Yellow: cout<<" Yellow";
break;
case Black: cout<<" Black";
break;
case White: cout<<" White";
break;
}
cout<<" can(s)" << endl;
   return 0;
}

paint.h

#include<fstream>
const double squareFeetPerGallons = 350.0;
const double gallonsPerCan        = 1.0;
const int numOfColors =6;
enum Color {Red, Blue, Green, Yellow, Black,White};
double calculateWallArea(double height, double width){
// height times width
}
double calculatePaintAmount(double wallArea){
//wallarea divided by square feet per gallons
}
int calculateNumberOfCans(double paintAmount){
return ceil(paintAmount/gallonsPerCan); // round up the number of cans needed
}
void getColorCost(double costArray[]){
//open the data file and read into array
}
double calculateCost(Color paintColor, double costArray[],double numOfCans ){
// the cost of paint given the color and number of cans
}

cost.txt
1.99
2.99
0.99
2.99
0.49
0.99

In: Computer Science

Example #2: Write the following set of four linear equations with 4 unknowns x1, x2, x3,...

Example #2: Write the following set of four linear equations with 4 unknowns x1, x2, x3, and x4 in the matrix form. Solve the equations using MATLAB.

0.1 x1+ 2.3 x2 + 3x3 + 4x4 =1

x1+ 3x2 -7x3 +5x4 =2

3x1+2x2+7x3 =3

x1 +2x2 +x3 +10x4=0

(b)Roots of Polynomials:

In order to obtain the roots of a polynomial with the coefficients a1,a2,a3 ,... (where a1 is the coefficient of the highest power, and so on in a descending order) using MATLAB, organize the coefficients of the equation using the following format: p=[a1, a2, a3, a4]

Then the roots (all the roots - real and complex) can be obtain by the following command: r=roots(p)

In: Advanced Math

Problem 2: In Multi-Effects Desalination (MED) system composed of 4 effects, and 3 feed preheaters and...

Problem 2: In Multi-Effects Desalination (MED) system composed of 4 effects, and 3 feed preheaters and down condenser. List the following: a- The mass balance in the evaporator, feed preheater and down condenser b- The energy balance in the evaporator, feed preheater and down condenser c- The Material balance in the first effect d- The temperature profile of the feed if the intake temperature is 25ºC and temperature of last effect is 40ºC and the temperature of first effect is 60ºC e- What will happen to the transfer area of the evaporator if the motive steam temperature is increased to 100ºC where the rest is remaining constants.

In: Mechanical Engineering

How many mol Al2O3 made if: 4 Al (s) + 3 O2 (g) -> 2 Al2O3...

How many mol Al2O3 made if:

4 Al (s) + 3 O2 (g) -> 2 Al2O3 (s) ; 16 mol Al , 13 mol O2

* Al is limited reagent

In: Chemistry

4 Food and Beverage AB213-2: Determine required sanitary and safety procedures in food and beverage operations....

4 Food and Beverage

AB213-2: Determine required sanitary and safety procedures in food and beverage operations.

In a university dining hall and based on FDA, OSHA, and HACCP standards, address the concerns the new chef has when viewing current operations at the dining hall.

Scenario: As the Chef enters the restaurant kitchen she sees the following situation: One preparation person with long hair is grabbing several heads of lettuce from the refrigerator and placing them on a cutting board immediately after the chicken prep person has finished deboning the chicken breasts for lunch. The chicken preparation person throws the knife into a bin of cutlery sitting in tepid soapy water. Then the oven doors are all open on one end of the kitchen while the baker goes to the pantry. There are unlabeled and uncapped drink mixes for the bar located on the shelf with the milk in the refrigerator. A vendor has just left several crates of eggs at the back door and no one seems to be aware of this. An abandoned prep station has an open carton of cream sitting near the burners where someone was obviously sautéing something, but has left the station and there seems to be an open can of oil sitting on top of the ignited burners.

The chef is immediately alarmed and starts to make notes while moving rapidly towards the most urgent issues to prevent someone getting hurt.

Help the chef and write a 2–3 page paper with correct grammar and spelling, and an additional title and references page in APA format with proper citation that addresses the following:

Checklist:

  • Determine the sanitary and safety risks. Explain why.
  • Identify the agency or standards that have been neglected in the scenario.
  • As the chef, explain what steps you would take to correct this situation in the restaurant kitchen.

In: Operations Management

Regression Analysis (use Excel) Need to determine if there is a relationship in the amount a...

Regression Analysis (use Excel)

Need to determine if there is a relationship in the amount a household spends on prepared foods to family size and income. Need to be able to answer if the data is a good fit and what the exact relationship is between the dependent variable and the independent variables. Please use the below data and Excel to determine the equation that represents the relationship and explain the goodness of fit. Based on the data, how might this data be used?

Dollars spent on Prepared food Family size Gross monthly income
495.86 4 3126
642.77 5 3933
364.81 3 1925
619.3 5 3736
238.71 1 1453
378.94 2 2538
302.58 1 1798
231.74 2 1189
428.67 3 2247
286.99 3 1460
268.81 1 1567
329.81 2 1622
627.25 5 3828
421.52 3 2782
656.38 5 3978
400.64 3 2493
603.41 6 3753
560.69 4 3778
623 5 3609
416.12 2 2262
323.9 1 1966
418.78 3 2736
506.46 4 3274
552.53 2 3480
586.46 4 3741
637.18 8 3684
244.49 2 1476
507.19 5 2835
512.56 5 2873
312.89 1 1618
329.05 2 1565
243.49 2 1582
560.37 8 3380
599.9 5 3922
657.09 5 3845
394.82 2 2233
556.42 4 3098
596.05 8 3707
365.8 4 2071
489.08 3 3166

Please use excel when solving and provide steps. I'm working through the problem now, but am getting stuck on a few excel interpretations and would like to know what I am missing.

Keep in mind to show Ordinary Least Squares Method, minimizing error, individual y values and the Regression Line, measures of goodness of fit, correlation coefficient r, coefficient of determination, deriving r2 , and standard error of the estimate (se).

In: Statistics and Probability