Question: EECS 1 0 1 2 Lab 6 : Tracing an Algorithm Due: November 8 , 9 p . m . 1 Introduction You can submit

EECS 1012 Lab 6: Tracing an Algorithm
Due: November 8,9 p.m.
1 Introduction
You can submit your lab work in eClass any time before November 8,9 p.m.
2 Learning Outcomes
The purpose of this lab is To practice computational thinking by drawing flowcharts for basic computation problems, verifying if they are correct (by tracing them), then implementing them in JS.
Your first task in this lab is to verify 6 algorithms by tracing them for some sample inputs. You must also provide pre- and post- conditions for each algorithm. This task can be done in teams of two, if you like. In Part 2, you will implement all 6 exercises in JavaScript. We suggest that you do this portion of the work individually. You will create one html, one css, and one js file for all your work.
3 Flowchart Task
This part can be done in teams of two. If you have done the work at home, discuss it with a peer from your lab before you submit your final solution. If you work with a partner, please indicate the name of your partner on your submission. You will both receive the same mark on your submission.
Complete trace tables and pre- post- conditions in a Word document or on paper (and then take an image with a camera). Make sure the size of any image you submit is less than 500 KB ; you may have to reduce the resolution of your camera to make this possible.
IMPORTANT: You are required to provide preconditions and postconditions for each solution you provide.
1. The algorithm in Figure 1 of the appendix determines if a number is an Armstrong number. A number is called an Armstrong number if the sum of the values of the digits each raised to the power equal to the number of digits in the number equals the number. For example, 153 is an Armstrong number, because \(153=1^{3}+5^{3}+3^{3}\). Trace this algorithm when the input is 153.
2. The algorithm in Figure 2 of the appendix determines if a number is a Perfect number. A perfect number is a positive integer that is equal to the sum of its positive proper divisors, that is, divisors excluding the number itself. For instance, 6 has proper divisors 1,2 and 3, and \(1+2+3=6\), so 6 is a perfect number. Trace this algorithm when the input is 6.
3. The algorithm in Figure 4 of the appendix finds the sum of first \( N \) terms of the following series. \(5+55+555+5555+\ldots \ldots \ldots \). up to \( N \) terms. Trace this algorithm when the input is 4.
4. The algorithm in Figure 4 of the appendix determines if a given number is prime or not. Trace this algorithm for the following inputs: \(1,2,3\) and 4.
5. The charge for luggage on railways is calculated by the algorithm in Figure 5 of the appendix: For the first 40 kg . of weight, the charge is a flat \(\$ 5.75\). For every additional 20 kg (or part thereof) up to 500 kg , there is a charge of \(\$ 3.50\). For weight beyond 500 kg ., the charge is calculated at the rate of \(\$ 0.50\) per kg. Trace this algorithm for the following input: 500.
6. The algorithm in Figure 6 of the appendix shows the logic to find the \( N \) th Fibonacci number. Fibonacci numbers are obtained from the relationship: \( t_{i}=t_{i-1}+t_{i-2}\) for \( i=2\) to \( n \) where \( t_{0}=0\) and \( t_{1}=1\). If the input is 3, the output should therefore be 2 as \( t_{3}=2\). Trace this algorithm for the following inputs: \(2,4,5\).
4 Programming Task
In this part, you translate your flowcharts for the problems above to JavaScript code and link them all to an HTML page. You are given lab6.html, lab6.css, lab6.js and lab6.test.js. files. Review these files carefully, trying to understand the purpose of each line.
You will, more specifically, need to:
1. Complete the activateButton() function in lab6.js (more details are below).
2. Connect your lab6.js file to lab6.html by adding a script element in the head.
3. Ensure that activateButton() is called upon loading lab6.html (see lab 4 and 5 for an example).
4. write your OWN JSDoc comments for your code. 5. When the work is complete, you should have a website that runs each algorithm upon a button click. Some examples of what this should look like can be found in Figures 7 and 8 in the appendix.
You will encode the function activateButton() so that it adds an event listener to the button in your HTML page. Make sure that this event listener is be activated upon a 'click' event. Then write code so that when the user clicks:
- The string value from the select box in the HTML is bound to a variable.
- The numeric value from the input box in the HTML is bound to a variable.
- Your program calls the name of the function that is given in the string value, and passes to this function the value from the input box as an argument.
- If you obtain a return value, print this to the output element alongside the name of the algorithm.
- See the figures (in the Appendix) for an examples of what your HTML page should look like when you have completed this part of the work.
5 Submission
In order to submit, compress the 'Lab06' folder with 'lab6.css', 'lab6.html' and 'lab6.js' and your tracing tables within it and submit your compressed file via eClass. The file you submit should have a .zip extension. You do not have - Your HTML should be linked t
EECS 1 0 1 2 Lab 6 : Tracing an Algorithm Due:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!