Questions
please answer part 2 . the code for part 1 is provided at the end. Part...

please answer part 2 . the code for part 1 is provided at the end.

Part 1

There is a pair of functions in stdlib.h (make sure to include it) that are used for generating pseudo-random numbers. These are "srand" and "rand". Examples are on pages 686 and 687. E.g., function "srand(3)" provides the seed value of 3 to the srand function. (3 is just a number, and probably isn't even a good number for this purpose, but that's a discussion for another time). The reason that we use a seed value is so that we can reproduce the series of random numbers. Thus, we call them pseudo-random numbers. Being able to reproduce them is important to verify and debug code.

Write a C program to generate a set of random numbers for a given seed value (call it lab8_part1.c). Prompt the user for the seed value, or 0 to quit. Then print 5 random values. When you run your program, try a few different seed values, then try one that you've already tried. Verify that you get the same sequence.

Part 2

Copy the lab8_part1.c program to a new file, lab8_part2.c, to use in this part.

We will generate random values, but they should be limited to 0, 1, 2, or 3. To do this, think of a way to map the random value to a small value; there are many ways to do this, however, the way you choose must be reproducible. That is, if it maps value X to the value 2, it should do that every time the value is X. Create a function that accomplishes random number generation and mapping: the function should return a single integer that is a random value of 0, 1, 2, or 3. It does not need any inputs. To verify that it works, have your program print about 20 from it. If your program gives you values like -1 or 4, you know you have a problem. Also, if it never generates one of the values (0, 1, 2, or 3), then there is a problem.

Then create an array of 4 ints. Initialize that array to 0 values. Have your program prompt the user for an integer number, read it in, then generate that many random values (0, 1, 2, or 3). Do not show the random values. Instead, count them, i.e., every time the function produces a 0, the integer at array position 0 should be incremented. Once all the random numbers have been processed, display the counts. Verify that the numbers make sense; if your program says that there were 4 zero values, 6 ones, 5 twos, and 3 threes, but it was supposed to generate 20 values, you know there is a problem because 4+6+5+3 = 18, not 20. Also have your program report the percentages as well as the counts. The percentages should be shown with one digit after the decimal, and they should add up to 100% (neglecting any round-off error).

Test your program a few times, and note the relative number of each generated value. Assuming an even distribution, you would see the same counts for each value, i.e. 0 would be generated 25% of the time, 1 would be 25% of the time, etc. The more values the program generates, the closer to 25% each one should be.

Prepare the log like you normally do: use "cat" to show the C programs, use "gcc" to compile them, and show that the programs run.

code for part 1:

CODE -

#include<stdio.h>

#include<stdlib.h>

int main()

{

    int seed;

    // Taking seed value as input from the user

    printf("\nEnter a seed value (0 to quit): ");

    scanf("%d", &seed);

    // Running the loop until user enters 0 to quit

    while(seed != 0)

    {

        // Passing seed value to the function srand()

        srand(seed);

        // Printing 5 random values

        for(int i=0; i<5; i++)

            printf("%d ", rand());

        // Taking next seed value as input from the user

        printf("\nEnter a seed value (0 to quit): ");

        scanf("%d", &seed);

    }

    return 0;

}

In: Computer Science

C++ on randomly generated integers stored in vectors. you will use routines from STL <algorithm> to...

C++ on randomly generated integers stored in vectors. you will use routines from STL <algorithm> to implement these algorithms. Using the following functions with their description

const int DATA_SIZE = 200;

const int SEARCH_SIZE = 100;

const int DATA_SEED = 7;

const int SEARCH_SEED = 9;

void genRndNums( vector<int>& v, int seed )

{

This routine generates random integers in the range [ LOW = 1, HIGH =200 ] and puts them in vector v. Initializes the random number generator (RNG) by calling the function srand ( ) with the seed value seed, and generates random integers by calling the function rand (). To use srand and rand, you need the header <cstdlib>. The vector v is already allocated with space. Use vector’s member function to get the size of the vector

}

int linearSearch( const vector<int>& inputVec, int x)

{

int linearSearch ( const vector < int >& inputVec, int x ) : A linear search algorithm, where x is the searched item in vector inputVec. It simply starts searching for x from the beginning of vector v to the end, but it stops searching when there is a match. If the search is successful, it returns the position (starting at 0) of found item; otherwise, it returns -1. To implement this routine, simply call the find ( ) function from the STL <algorithm>.

}

int binarySearch( const vector<int>& inputVec, int x)

{

A binary search algorithm, where x is the searched item in vector inputVec. If the search is successful, it returns the position (starting at 0) of found item; otherwise, it returns -1. To implement this routine, simply call the equal_range ( ) function from the STL <algorithm>.

}

int search( const vector<int>& inputVec, const vector<int>& searchVec,

            int (*p)( const vector<int>&, int) )

{

int search ( const vector < int >& inputVec, const vector < int >& searchVec, int ( *p ) ( const vector < int >&, int ) ) : A generic search algorithm – takes a pointer to the search routine p( ), and then it calls p( ) for each element of vector searchVec in vector inputVec. It computes the total number of successful searches and returns that value to the main ( ) routine as an input argument to the print routine printStat ( ), which is used to print out the final statistics for a search algorithm.

}

void sortVector (vector<int>& inputVec)

{

A sort algorithm to sort the elements of vector inputVec in ascending order. To implement this routine, simply call the sort ( ) function from the STL.

}

void printStat (int totalSucCnt, int vec_size)

{

the percent of successful searches as floating-point numbers on stdout, where totalSucCnt is the total number of successful comparisons and vec_size is the size of the test vector

}

void print_vec( const vector<int>& vec )

{

This routine displays the contents of vector vec on standard output, printing exactly NO_ITEMS = 12 numbers on a single line, except perhaps the last line. The sorted numbers need to be properly aligned on the output. For each printed number, allocate ITEM_W = 5 spaces on standard output. You can re-use the implementation of this routine from Assignment 1, but remember to change the values of related constants.

  

}

int main() {

    vector<int> inputVec(DATA_SIZE);

    vector<int> searchVec(SEARCH_SIZE);

    genRndNums(inputVec, DATA_SEED);

    genRndNums(searchVec, SEARCH_SEED);

    cout << "----- Data source: " << inputVec.size() << " randomly generated numbers ------" << endl;

    print_vec( inputVec );

    cout << "----- " << searchVec.size() << " random numbers to be searched -------" << endl;

    print_vec( searchVec );

    cout << "\nConducting linear search on unsorted data source ..." << endl;

    int linear_search_count = search( inputVec, searchVec, linearSearch );

    printStat ( linear_search_count, SEARCH_SIZE );

    cout << "\nConducting binary search on unsorted data source ..." << endl;

    int binary_search_count = search( inputVec, searchVec, binarySearch );

    printStat ( binary_search_count, SEARCH_SIZE );

    sortVector( inputVec );

    cout << "\nConducting linear search on sorted data source ..." << endl;

    linear_search_count = search( inputVec, searchVec, linearSearch );

    printStat ( linear_search_count, SEARCH_SIZE );

    cout << "\nConducting binary search on sorted data source ..." << endl;

    binary_search_count = search( inputVec, searchVec, binarySearch );

    printStat ( binary_search_count, SEARCH_SIZE );

    return 0;

}

In: Computer Science

Fitting a linear model using R a. Read the Toluca.txt dataset into R (this dataset can...

Fitting a linear model using R a. Read the Toluca.txt dataset into R (this dataset can be found on Canvas). Now fit a simple linear regression model with X = lotSize and Y = workHrs. Summarize the output from the model: the least square estimators, their standard errors, and corresponding p-values. b. Draw the scatterplot of Y versus X and add the least squares line to the scatterplot. c. Obtain the fitted values ˆyi and residuals ei . Print the first 5 fitted values and the corresponding residuals.

lotSize workHrs

80 399

30 121

50 221

90 376

70 361

60 224

120 546

80 352

100 353

50 157

40 160

70 252

90 389

20 113

110 435

100 420

30 212

50 268

90 377

110 421

30 273

90 468

40 244

80 342

70 323

In: Statistics and Probability

Pears PLC adheres to IFRS. It recently imported inventory for $100 million, paid import tax of...

  1. Pears PLC adheres to IFRS. It recently imported inventory for $100 million, paid import tax of $ 2milion, carrying in cost of $5 million and spent $5 million for storage prior to selling the goods. The amount it charged to inventory expense ($ millions) was closest to:
  1. $100
  2. $105
  3. $107
  4. $115
  1. In an inflationary environment, a LIFO liquidation will most likely result in an increase in:
  1. Inventory.
  2. Accounts payable.
  3. Operating profit margin.
  4. None of them.

3. The CFO of APEX, S.A. is selecting the depreciation method to use for a new machine. The machine has an expected useful life of six years. Production is expected to be low initially but to increase over time. The method chosen for tax reporting must be the same as the method used for financial reporting. If the CFO wants to maximize tax payments in the first year of the machine’s life, which of the following depreciation methods is the CFO most likely to use?

  1. Units-of-production method.
  2. Straight-line method.
  3. Double-declining balance method.
  4. None of the above.

In: Accounting

Submit the following graphs. May be done in Excel and then paste them. Hospital A has...

  1. Submit the following graphs. May be done in Excel and then paste them.
  1. Hospital A has 100 employees. Samples are as follows: Person 1 makes $1000 per week, Person 2 makes $2000 per week, Person 3 makes $3000 per week, person 4 makes $4000 per week and person 5 makes $5000 per week. Identify the type of graph and graph your results.
  2. Hospital B has 100 employees. All employees make $5,000 per week. Identify the type of graph and graph your results.
  3. Hospital C has 500 residents. The first floor dispenses 500 medications per week. The second floor dispenses 250 medications per week. The third floor dispenses 310 medications per week. The fourth floor dispenses 650 medications per week and the 5th floor dispenses 822 medications per week. Identify the type of graph and graph your results.

In: Statistics and Probability

During the current COVID-19 crisis, there have been several news polls regarding how well the President...

During the current COVID-19 crisis, there have been several news polls regarding how well the President is handling the situation. A news poll happens when a news agency solicits responses through their news programs on televisions (or through the internet). A recent poll had the following results: Positive 43%, Negative 53%. However, broken down by political party, the results were as follows:

Political Party

Positive

Negative

Republican

85%

15%

Democrat

13%

85%

First note that the numbers do not add up to 100%.

Explain why this type of poll is not statistically sound. You should give at least three reasons. Explain possible reasons why the results do not add to 100%. If you average the results across the parties, you do not get numbers that match the overall results. Considering the positive results, (85% + 13%) / 2 = 49%, not 43%. Similarly, the average of 15% and 85% is 50%, not 53%. Give a sound mathematical explanation of how that could happen?

In: Statistics and Probability

You have the following buffer recipe and decide to make up some concentrated solutions first so...

You have the following buffer recipe and decide to make up some concentrated solutions first so that you won't have to weigh out dry ingredients, wait for them to dissolve, and correct the pH every time you make it. How much dry ingredients do you use for each of the following 4 stock solutions? Show you work and include units in your calculations.

The Buffer Recipe is:

150 mM NaCl (formula weight 58.44 g)

10 mM Tris pH 8.0 (formula weight 121 g)

2 mM EDTA (formula weight 292 g)

0.2% bovine serum albumin

-Stock 1 of 4: 3 M NaCl, 100 mL ________ ?

-Stock 2 of 4: 1 M Tris, pH 8.0, 100 ml ________ ?

-Stock 3 of 4: 0.5 M EDTA, 500 mL ________ ?

-Stock 4 of 4: 10% bovine serum albumin, 10 mL ________ ?

In: Biology

(a) One of the first "pure" Bose Einstein condensates was created with a low density (1020...

(a) One of the first "pure" Bose Einstein condensates was created with a low density (1020 molecules per cubic meter) gas of lithium with an atomic mass of 7.02 u. What is the critical temperature for the transition to a Bose Einstein condensate for lithium? Assume the spin for the atom is 1. The temperatures actually achieved in these experiments were below 100 nK. What fraction of the lithium molecules are in the Bose Einstein Condensate phase at 100 nK?

________K, critical temperature

______ fratction of atoms in BEC phase

(b) A spectral line of wavelength 382 nm is known to split into three lines in the presence of strong magnetic fields due to the Zeeman effect. In a magnetic field of 4 T, what is the minimum resolution needed on a spectrometer to observe the splitting of this spectral line?

_______ nm

(c) What are the energy and wavelength of photons emitted in a J=3 to J=2 transition in the rotational spectrum of an O2 molecule? The bond length is 0.121 nm. Give your answer in millielectron volts (meV) and in millimeters (mm).

_____ meV

_____mm

In: Physics

A. For the last question, suppose you hear some information that leads you to believe that...

A.

For the last question, suppose you hear some information that leads you to believe that the stock is more risky than you first assumed.  You still think that your assumption about the value of the stock in three years is the best estimate, but you are concerned that the variance in that estimate is larger than you expected.  How might you adjust your calculations to account for the greater risk?

B.

You are considering two potential investments.  One is an established company with a history of consistent earnings growth, while the other is a new IPO with a short track record.  You think that the stock of both companies will be worth $100 in three years.  How would a risk-averse investor differ in his or her value calculations for each of the investments?

C.

  1. What is the future value of $100 invested at 7% for five years?

D

  1. The CAPM principles assume that most investors exhibit which of the following behaviors?
    1. Risk loving
    2. Risk neutrality
    3. Risk aversion

In: Finance

1. A regular deposit of $100 is made at the beginning of each year for 20...

1. A regular deposit of $100 is made at the beginning of each year for 20 years. Simple interest is calculated at i%per year for the 20 years. At the end of the 20-year period, the total interest in the account is $840. Suppose that interest of i% compounded annually had been paid instead. How much interest would have been in the account at the end of the 20 years?

2. Herman has agreed to repay a debt by using the following repayment schedule. Starting today, he will make $100 payments at the beginning of each month for the next two-and-a-half years. He will then pay nothing for the next two years. Finally, after four-and-a-half years, he will make $200 payments at the beginning of each month for one year, which will pay off his debt completely. For the first four-and-a-half years, the interest on the debt is 9% compounded monthly. For the final year, the interest is lowered to 8.5% compounded monthly. Find the size of Herman’s debt. Round your answer to the nearest dollar.

In: Finance