Question

In: Computer Science

Part 1 Recall from Chapter 1 that computer memory is comprised of individual bits of data....

Part 1

Recall from Chapter 1 that computer memory is comprised of individual bits of data. A bit (short for binary digit) can store one of only two values, commonly referred to as 0 and 1. However, using two bits, you can represent four different values through the bit patterns 00, 01, 10, and 11. With three bits, you can represent eight different values—via 000, 001, 010, 011, 100, 101, 110, and 111. In general, N bits of memory enable you to represent 2N different values.

Create a Web page named bits.html that contains a text box where the user can enter a number, call it N. At the click of a button, your page should compute and display 2N, the number of values that can be represented using the specified quantity of bits. For example, if the user entered 10 in the text box, the page would display the message:

With 10 bits, you can represent 1024 different values.

Once you have created your page, use it to determine the number of values that each of the following can represent (Test the following numbers to see if they give the correct results)

     8 bits (1 byte)

    16 bits (2 byte)

    32 bits (4 bytes)

    64 bits (8 bytes)

Part 2

Most lotteries select winning numbers by drawing numbered balls out of bins. For example, a typical Pick-4 lottery will utilize four bins, each containing balls with numbers starting at 0. If there are 10 balls to choose from in each of four bins, labeled 0 to 9, then 104 = 10,000 different number sequences can potentially be picked. Increasing the number of balls significantly increases the number of possible sequences, which significantly decreases a person’s odds of winning. For example, if there are 20 balls to choose from in each bin, labeled from 0 to 19, then 204 = 160,000 different number sequences could be selected.

Make a copy of the lucky1.html page from Figure 7.4 in your text and name it pick4.html. Then modify this new page so that it simulates a Pick-4 lottery. Your page should have one text box, where the user can enter the highest ball number (it is assumed that the lowest ball number is always 0). When a button is clicked, four random ball numbers should be selected and displayed in a message such as the following:

  The Pick-4 winners are: 5-0-8-2

Part 3

Modify your pick4.html page from above so that it makes use of a function in the HEAD. Your function should contain the code previously assigned to the button, and have a name descriptive of the task it performs, such as GeneratePicks or PickNumbers. You should then modify the button’s ONCLICK attribute to call that function.

Solutions

Expert Solution

I have provided the properly commented code in both text and image format so you can easily copy the code as well as check for correct indentation.
I have provided the output image of the code so you can easily cross-check for the correct output of the code.
Have a nice and healthy day!!

Part 1

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Bits.html</title>
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<!-- Bootstrap related files -->
</head>
<div class='container m-4 p-4'>
<label for="binary">Enter a no.</label>
<input type="number" class="form-control" id="binary" placeholder="Enter number of bits">
<!-- Takes input here -->
<button type="button" class="btn btn-primary" onclick='calculate()'>Calculate</button>
<p  class="font-weight-bold" id='output'></p>
</div>

<!-- Bootstrap related files -->
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

<script type='text/javascript'>
function calculate(){
    var n = $('#binary').val();
    // Get value of the number
    var output = Math.pow(2,n);
    // get total values by calculating 2^n
    $('#output').html('With '+ n +' bits, you can represent '+ output +' different values.');
    // Changing value of text
    }
</script>

</body>
</html>

Part 2

<!doctype html>

<html lang="en">
<head>
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">


  <meta charset="utf-8">
  <title>pick4.html</title>

</head>
<div class='container m-4 p-4'>
<label for="highest">Enter highest ball number</label>
<input type="number" class="form-control" id="highest" placeholder="Enter highest ball number">
<!-- Takes input here -->
<button type="button" class="btn btn-primary" onclick='GENERATEPICKS()'>Pick Balls</button>
<p  class="font-weight-bold" id='output'></p>
<!-- Prints output here -->
</div>


<!-- Bootstrap related files -->
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<script type='text/javascript'>
function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}
// This function is inside head tag
function GENERATEPICKS(){
    var n = parseInt($('#highest').val());
    // Get value of the number as integer and not string
    // If input is 9 then we want to check balls in range 0-9. So, we will find number by using getRandomInt(10)
    // which will return a number in range of 0 to 9
    var a = getRandomInt(n+1);
    var b = getRandomInt(n+1);
    var c = getRandomInt(n+1);
    var d = getRandomInt(n+1);
    // get total values by calculating 2^n
    $('#output').html('The Pick-4 winners are: '+a+'-'+b+'-'+c+'-'+d);
    // Changing value of text
    }
</script>

</body>
</html>

Part-3

Same as above but functions are moved inside the head tag as mentioned in the question

<!doctype html>

<html lang="en">
<head>
<!-- CSS only -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<!-- Bootstrap related files -->
<!-- JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>


<script type='text/javascript'>
function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}
// This function is inside head tag
function GENERATEPICKS(){
    var n = parseInt($('#highest').val());
    // Get value of the number as integer and not string
    // If input is 9 then we want to check balls in range 0-9. So, we will find number by using getRandomInt(10)
    // which will return a number in range of 0 to 9
    var a = getRandomInt(n+1);
    var b = getRandomInt(n+1);
    var c = getRandomInt(n+1);
    var d = getRandomInt(n+1);
    // get total values by calculating 2^n
    $('#output').html('The Pick-4 winners are: '+a+'-'+b+'-'+c+'-'+d);
    // Changing value of text
    }
</script>
  <meta charset="utf-8">
  <title>pick4.html</title>

</head>
<div class='container m-4 p-4'>
<label for="highest">Enter highest ball number</label>
<input type="number" class="form-control" id="highest" placeholder="Enter highest ball number">
<!-- Takes input here -->
<button type="button" class="btn btn-primary" onclick='GENERATEPICKS()'>Pick Balls</button>
<p  class="font-weight-bold" id='output'></p>
<!-- Prints output here -->
</div>



</body>
</html>

Related Solutions

A 64 bit computer uses a memory of 32KB. Work out the number of bits of...
A 64 bit computer uses a memory of 32KB. Work out the number of bits of AR, DR, PC, AC, and the HEX code of the address of last memory location. b) The memory attached to a processor has access time of 400ns. When a cache memory is introduced in the system, it is found that on average the access time for the computer was 30% greater than the cache access time for a miss ratio of 0.10. Work out...
Part (b): Reversing the order of bits in a word Recall that in our course we...
Part (b): Reversing the order of bits in a word Recall that in our course we define a word to be a 32-bit sequence (i.e., four consecutive bytes). For some algorithms it is useful to have a reversed version of that 32-bit sequence. (The deeply curious can read a brief description about such use in Fast Fourier Transform algorithm implementations by visiting Wikipedia at this link: http://bit.ly/2rnvwz6 ). Your task for part (b) is to complete the code in reverse.asm...
In a study of memory recall, ten students from a large statistics and data analysis class...
In a study of memory recall, ten students from a large statistics and data analysis class were selected at random and given 15 minutes to memorize a list of 20 nonsense words. Each was asked to list as many of the words as he or she could remember both 1 hour and 24 hours later. The data are as shown in Table 1. Is there evidence to suggest the mean number of words recalled after 1 hour exceeds the mean...
13. A digital computer has a memory unit with 32 bits per word. The instruction set...
13. A digital computer has a memory unit with 32 bits per word. The instruction set consists of 260 different operations. All instructions have an operation code part (opcode) and an address part (allowing for only one address). Each instruction is stored in one word of memory. a) How many bits are needed for the opcode? b) How many bits are left for the address part of the instruction? c) What is the maximum allowable size for memory? d) What...
A digital computer has a memory unit with 32 bits per word. The instruction set consists...
A digital computer has a memory unit with 32 bits per word. The instruction set consists of 122 different operations. All instructions have an operation code part (opcode) and an address part (allowing for only one address). Each instruction is stored in one word of memory. a) How many bits are needed for the opcode? b) How many bits are left for the address part of the instruction? c) What is the maximum allowable size for memory? d) What is...
Problem 3. A digital computer has a memory unit with 32 bits per word. The instruction...
Problem 3. A digital computer has a memory unit with 32 bits per word. The instruction set consists of 122 different operations. All instructions have an operation code part (opcode) and an address part (allowing for only one address). Each instruction is stored in one word of memory. a) How many bits are needed for the opcode? b) How many bits are left for the address part of the instruction? c) What is the maximum allowable size for memory? d)...
A computer memory manufacturer specifies that its memory chip stores data incorrectly an average of 6.3...
A computer memory manufacturer specifies that its memory chip stores data incorrectly an average of 6.3 out of 10 million cycles with a standard deviation of 0.48. A batch of 30 chips your company ordered stores data incorrectly an average of 6.9 times per 10 million cycles. a. Does it seem reasonable that your 30 chips are a random sample from a population with the specifications given by the computer memory manufacturer? Use a = 0.052 tail. b. What is...
Computer Architecture 1. Define what a "word" is in computer architecture: The size (number of bits)...
Computer Architecture 1. Define what a "word" is in computer architecture: The size (number of bits) of the address The total number of bits of an instruction (e.g. 16 bits) Word and width are synonymous. A word is the contents of a memory register. 2. What is the difference between a register’s width and a register’s address? (choose all that apply - there may be more than one correct answer) They are both the same! Address is the same for...
On the job smith computer center chapter 1 The following problem continue from one chapter to...
On the job smith computer center chapter 1 The following problem continue from one chapter to the next, carrying the balances of each month forward. 1 Analyze and record each transaction in the expanded accounting equation. 2. Prepare the financial statements ending July 31 for Smith computer Center. On July 1, 201x Thad Feldman decided to begin his own computer service business. He named the business Smith computer center. During the first month, Thad conducted the following business transactions. A....
1. Recall Ken Washington from the beginning of Chapter 35. Now that you have completed the...
1. Recall Ken Washington from the beginning of Chapter 35. Now that you have completed the chapter, answer the following questions regarding his case. 1. Is it significant that Ken had a urinary catheter in place for 6 days while he was in the hospital? 2. Dr. Buckwalter plans to send Ken home with a urinary catheter in place. What information can you give him to help him prevent infection? 3. You note on the chart that Dr. Buckwalter wants...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT