Problem Description: Game: Bean Machine or Galton Box
To figure out if the ball falls to Left or Right, you can generate a random number using Math.random(). If this random number is greater than or equal to 0.5 we assume the ball falls to the Right otherwise it falls to the Left (or vise versa).
If there are 8 slots, the ball should hit 7 nails (8 -1), thus you should run a loop 7 times to figure out the path for that ball. If you have N balls, this whole process should be repeated N times. Here is a basic algorithm.
# of balls = N
# of slots = K
array of K elements
for ( i = 0 to N) {
int R = 0;
for (j = 0 to K-1) {
if ( random number >= 0.5)
R++;
}//end loop j
array[R] ++;
}// end loop i
Output the array to show how many balls are in each slot.
Things to DO!!!!!
Analysis: (3 points)
(Describe the problem including inputs and outputs in your own words.)
Design: (3 points)
(Describe the major steps in your algorithm for solving the problem.)
Coding: Write a well documented and properly indented Java source program. Your program should have a block comment with your name and a statement of purpose at the very top. Use meaningful variable names. You must have proper labels and informative statements for all inputs and outputs. (10 points)
Testing: (Describe how you test this program, you should use your own input data to test not just the test cases given in sample runs.) (4 points)
Test your program according to following test schedule and generate output to show the number of balls in each slot.
| N | K |
| 10 | 8 |
| 50 | 10 |
| 100 | 20 |
| 500 | 30 |
What to Submit:
In: Computer Science
C Programming Assignment 4
Cache Simulation
Objective:
To write a C program that simulates reading and writing to a custom-sized direct-mapped cache, involving a custom-sized main memory.
The program will read all values from the ZyLab as Test Bench inputs.
Main Menu Options:
The program simulates reading from and writing to a cache based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:
Note that when you read from ZyLab, the input values are not displayed on the screen as they are in the sample run at the end of this document.
Inputs:
Input Value Checks:
Output Messages:
All messages should be display EXACTLY as shown in the sample run; that is, prefixed by three asterisks, a space and hyphen and one more space. The message should be followed by a blank line.
*** All Input Parameters Accepted.
Starting to Process Write/Read Requests
Note that one message has been deleted from previous versions of this Specification and three new ones have been added.
*** Error - Main Memory Size is not a Power of 2
*** Error - Block Size is not a Power of 2
*** Error - Cache Size is not a Power of 2
*** Error – Block size is larger than cache size
*** Error – Cache Size is not a multiple of Block Size
*** Error – Read Address Exceeds Memory Address Space
*** Error – Write Address Exceeds Memory Address Space (The write value following the invalid address value should be read and then discarded)
*** Error – Invalid Menu Option Selected (Until configuration data has been accepted, the only valid menu options that can be entered are “1” or “4.”)
Whenever any one of these errors occurs, the program should loop back to the Main Menu.
*** Word WW of Cache Line LL with Tag TT contains Value VV
This message should appear after all successful reads or writes
WW is the word number in the cache line, LL is the line number in the cache, TT is the line’s tag value and VV is the content value in the cache.
All values are in decimal.
*** Read Miss - First Load Block from Memory (followed on the next line by the Content Message above)
*** Cache Hit (followed on the next line by the Content Message above)
*** Write Miss - First Load Block from Memory (followed on the next line by the Content Message above)
*** Cache Hit (followed on the next line by the Content Message above)
*** Memory Freed Up – Program Terminated Normally
When option 4 is entered, the memory should be freed up and the message “Memory Freed Up – Program Terminated Normally”, followed by a blank line, should be displayed before exiting the program.
Program Requirements:
Each word i of main memory is initialized with the value M–i, where M is the size of main memory in words. So, memory location 0 will contain the address of the last memory location and the last memory location will contain the address of the first memory location (i.e. 0).
Prologue & Comments:
At the very beginning of your source code (the very first lines), please include a prologue which looks like the following:
/*
Dr. George Lazik (use your full name not mine)
Programming Assignment 4: Cache Simulation
Comp 222 – Fall 2019
Meeting Time: 0800-0915 (your meeting time)
*/
// Reading input values from ZyLab
// Determining the contents of memory
ZyLab Test Benches:
Make sure your full name appears on each page of the listing and that all pages are stapled together in their correct order BEFORE you come to class.
Failure to provide this listing will result in no grade for the assignment.
Sample Test Run
The following is a sample run of one of the tests in Assignment 4’s Test Bench on ZyBooks. Note: Some recently added error conditions are not included in this run.
1
65536
512
1024
1
65536
1027
16
1
65536
1024
15
1
65537
1026
4096
1
65536
1024
18
1
65536
1024
16
3
65535
14
2
65535
3
65534
512
2
1023
4
Your output
Programming Assignment 4: Cache Simulation
Comp 222 - Fall 2019
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Block Size is Larger than Cache Size
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Cache Size is not a Power of 2
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Block Size is not a Power of 2
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Main Memory Size is not a Power of 2
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** Error - Cache size is not a multiple of block size
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter main memory size (words):
Enter cache size (words):
Enter block size (words/block):
*** All Input Parameters Accepted. Starting to Process Write/Read Requests
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Write:
Enter Value to Write:
*** Write Miss - First load block from memory
*** Word 15 of Cache Line 63 with Tag 63 contains the Value 14
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Read:
*** Cache Hit
*** Word 15 of Cache Line 63 with Tag 63 contains the Value 14
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Write:
Enter Value to Write:
*** Cache Hit
*** Word 14 of Cache Line 63 with Tag 63 contains the Value 512
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
Enter Main Memory Address to Read:
Read Miss - First Load Block from Memory
*** Word 15 of Cache Line 63 with Tag 0 contains the Value 64513
Main Menu - Main Memory to Cache Memory Mapping
------------------------------------------------
1) Enter Configuration Parameters
2) Read from Cache
3) Write to Cache
4) Quit Program
Enter selection:
*** Memory Freed Up - Program Terminated Normally
In: Computer Science
Select 1 of the economic concentrations (clusters) below:
Write a 700- to 1,050-word paper evaluating economists’ assessments of the role the 4 factors of production played in determining how the economic concentration you selected has evolved. Complete the following in your paper:
In: Economics
A country experiences severe storms which destroys its main resource, oil rigs. Assume that the countries economy was in long-run equilibrium before this shock happens.
In: Economics
Prepare the answer to the following question by either entering text directly or uploading an Excel or Word file. Do NOT upload a .pdf or .jpg file or you will receive zero credit. Show computations. The prepaid insurance account has an unadjusted balance of $46,000 at December 31, 2018, the end of Hanson Company's accounting year. Insurance expense has an unadjusted $2,000 balance at the same point in time. Some policies that were in effect have expired. Some of those were renewed and some were not. The following policies are in effect at December 31, 2018: Policy Date Policy Total Premium Type Acquired Term Paid when acquired Liability 1-31-17 2 years $48,000 Auto 6-30-18 2 years 9,000 Business interruption 8-1-18 1 year 840 Determine the adjusted balance in prepaid insurance at December 31, 2018. 2.Determine the amount of total insurance expense (you need not separate the expense by policy type) to report on the income statement for the year ended December 31, 2018.
In: Accounting
Prepare the answer to the following question by either entering text directly or uploading an Excel or Word file. Do NOT upload a .pdf or .jpg file or you will receive zero credit. Show computations.
The prepaid insurance account has an unadjusted balance of $46,000 at December 31, 2018, the end of Hanson Company's accounting year. Insurance expense has an unadjusted $2,000 balance at the same point in time. Some policies that were in effect have expired. Some of those were renewed and some were not. The following policies are in effect at December 31, 2018:
Policy Date Policy Total Premium
Type Acquired Term Paid when acquired
Liability 1-31-17 2 years $48,000
Auto 6-30-18 2 years 9,000
Business interruption 8-1-18 1 year 840
2.Determine the amount of total insurance expense (you need not separate the expense by policy type) to report on the income statement for the year ended December 31, 2018.
In: Accounting
In a system employing a paging scheme for memory management; wasted space is due to:
|
External fragmentation |
|
|
Internal fragmentation |
|
|
Pages and frames of different specified sizes |
|
|
None of these are reasons for wasted space in a paging scheme |
The page table for each process maintains:
|
The frame location for each page of the process |
|
|
The page location for each frame of the process |
|
|
The physical memory location of the process |
|
|
None of these are what the page table maintains |
The real address of a word in memory is translated from the following portions of a virtual address:
|
Page number and frame number |
|
|
Page number and offset |
|
|
Frame number and offset |
|
|
None of these are how a virtual address is translated to a real address |
The replacement policy that can be implemented in practice and performs the best among the replacement policies that can be actually coded is:
|
Optimal Policy |
|
|
Least recently used (LRU) policy |
|
|
Clock policy |
|
|
None of these are the described replacement policy |
A reference to a memory location independent of the current assignment of data to memory is called a(n):
|
Special address |
|
|
Logical address |
|
|
Absolute address |
|
|
None of these are the name for this type of memory reference |
In: Computer Science
To obviate current beach erosion potentials and as a part of
beach re-nourishment, Research department’s Dr. Smith proposed a
construction of a series of submerged wave energy dissipation
structures (=submerged-plate breakwaters) at 110 ft from the
shoreline of the Beach. Based on design specifications of the
structure, the distribution of the number of waves dissipatable by
the proposed structure per hour could be approximated by a normal
distribution with a mean of 189 waves and a standard deviation of 7
waves.
1) Use the Empirical Rule to describe the 90% distribution/range of
X, i.e., the number
of waves dissipatable by the proposed structure per hour.
2) If the structure is built with dissipating a maximum 195
waves/hour capacity, what
fraction of an hour, i.e., minutes, might the structure be unable
to handle incoming
waves (or in other word, how many minutes per hour the structure
exceeds 195
waves/hour capacity)?
3) What wave dissipating capacity of the structure should be built
so that the
probability of the incoming waves exceeding the structure capacity
is equal to only
0.05 (or 5%)?
In: Statistics and Probability
Suppose patient demand for blood tests at a local hospital to screen for various illnesses is given by Q = 5,000 - 10P, where Q is the number of tests and P is the price of each test in dollars. It costs the hospital a constant $250 to run each test.
(a).Now suppose that all patients that visit the hospital have insurance that covers 80% of the cost of a blood test. In that case, the number of blood tests that will be run at the hospital is __________ . The deadweight loss that results from the hospital administering blood tests in this case is _________$ (enter only numbers in the blank, and please round to the nearest whole number if necessary).
(b)Consider the hospital from the previous problems. Continue to assume that patients have insurance that covers 80% of the cost of a blood test. However, suppose that, because it helps to detect communicable diseases, each blood test that is administered has a positive externality that can be valued at $25. The deadweight loss resulting from the hospital administering blood tests in this case will be [size] in size relative to if there were no positive externality associated with the tests (enter just the word larger, smaller, or identical in the blank). __________
In: Economics
Suppose patient demand for blood tests at a local hospital to screen for various illnesses is given by Q = 5,000 - 10P, where Q is the number of tests and P is the price of each test in dollars. It costs the hospital a constant $250 to run each test.
(a).Now suppose that all patients that visit the hospital have insurance that covers 80% of the cost of a blood test. In that case, the number of blood tests that will be run at the hospital is __________ . The deadweight loss that results from the hospital administering blood tests in this case is _________$ (enter only numbers in the blank, and please round to the nearest whole number if necessary).
(b)Consider the hospital from the previous problems. Continue to assume that patients have insurance that covers 80% of the cost of a blood test. However, suppose that, because it helps to detect communicable diseases, each blood test that is administered has a positive externality that can be valued at $25. The deadweight loss resulting from the hospital administering blood tests in this case will be [size] in size relative to if there were no positive externality associated with the tests (enter just the word larger, smaller, or identical in the blank). __________
In: Economics