Questions
Exercise 1 (a) Use javascript modify the code below, so that in addition to outputting the...

Exercise 1

(a) Use javascript modify the code below, so that in addition to outputting the selection to the web page, the selection is also placed in the browser’s local storage. Use ‘select’ as the local-storage key. The value will be the name of the category that was selected or the empty string is no selection was made.


(d) Add a button called ‘retrieve’. When it is clicked the local storage is read and the prior selection is shown on the web page.


Exercise 2

(a) Extend the code from Exercise 1. When the user clicks the retrieve button the radio buttons or tick boxes are also updated to show the prior selection. Confirm your code is working by making a selection, then exiting the browser, then restarting the browser at the same page and then clicking the retrieve button.


(b) Extend your web page so that the last 10 filter selections are stored. The user is able to see these prior filter selections (perhaps by clicking a button) and then choose one selecting it, making that the current selection.

previous code:

<head>
<title>
EX1
</title>
</head>

<body>

<table>

<tr>
<td>PET A</td>
<td>PET B</td>
<td>PET C</td>
</tr>

<tr>
<td>
<input type='checkbox' name='ProductA' value='Bird A1'>Bird A1
</td>

<td>
<input type='radio' name='ProductB' value='Cat B1'>Cat B1
</td>

<td>
<input type='checkbox' name='ProductC' value='Dog C1'>Dog C1
</td>
</tr>

<tr>
<td>
<input type='checkbox' name='ProductA' value='Bird A2'>Bird A2
</td>

<td>
<input type='radio' name='ProductB' value='Cat B2'>Cat B2
</td>

<td>
<input type='checkbox' name='ProductC' value='Dog C2'>Dog C2
</td>

</tr>

<tr>
<td>
<input type='checkbox' name='ProductA' value='Bird A3'>Bird A3
</td>

<td>
<input type='radio' name='ProductB' value='Cat B3'>Cat B3
</td>

<td>
<input type='checkbox' name='ProductC' value='Dog C3'>Dog C3
</td>
</tr>

</table>
<br/>

<button onclick='print()'>Filter</button>
  
<button onclick='clearA()'>Clear</button>

<div style='margin-top:30px;' id='display'>

</div>

</body>

<script>

function print(){

var itemA= document.getElementsByName('ProductA');

var itemB= document.getElementsByName('ProductB');
  
var itemC= document.getElementsByName('ProductC');

var selectedItemA='';
var selectedItemB='';
var selectedItemC='';

for(var i=0; i<itemA.length; i++){
if(itemA[i].type=='checkbox' && itemA[i].checked==true)
selectedItemA+=itemA[i].value+" ";
}


for(var i=0; i<itemB.length; i++){
if(itemB[i].type=='radio' && itemB[i].checked==true)
selectedItemB+=itemB[i].value+" ";
}

for(var i=0; i<itemC.length; i++){
if(itemC[i].type=='checkbox' && itemC[i].checked==true)
selectedItemC+=itemC[i].value+" ";
}

var disp= document.getElementById('display');
  
var newList='';

newList=selectedItemA+selectedItemB+selectedItemC;

if(newList==''){
disp.innerHTML='No Items selected';
}else{
disp.innerHTML=newList;
}


}

function clearA(){

var itemA= document.getElementsByName('ProductA');

var itemB= document.getElementsByName('ProductB');
  
var itemC= document.getElementsByName('ProductC');

for(var i=0; i<itemA.length; i++){

itemA[i].checked=false;

}

for(var i=0; i<itemB.length; i++){

itemB[i].checked=false;

}

for(var i=0; i<itemC.length; i++){

itemC[i].checked=false;

}

var disp=document.getElementById('display');

disp.innerHTML='';
  
}

</script>

Filter
  
Clear

In: Computer Science

Chapter 6: Use a list to store the players In Python, Update the program so that...

Chapter 6: Use a list to store the players

In Python, Update the program so that it allows you to store the players for the starting lineup. This

should include the player’s name, position, at bats, and hits. In addition, the program

should calculate the player’s batting average from at bats and hits.

Console

================================================================

Baseball Team Manager

MENU OPTIONS

1 – Display lineup

2 – Add player

3 – Remove player

4 – Move player

5 – Edit player position

6 – Edit player stats

7 - Exit program

POSITIONS

C, 1B, 2B, 3B, SS, LF, CF, RF, P

================================================================

Menu option: 2

Name: Mike

Position: C

At bats: 0

Hits: 0

Mike was added.

Menu option: 1

Player POS AB H AVG

----------------------------------------------------------------

1 Joe P 10 2 0.2

2 Tom SS 11 4 0.364

3 Ben 3B 0 0 0.0

4 Mike C 0 0 0.0

Menu option: 6

Lineup number: 4

You selected Mike AB=0 H=0

At bats: 4

Hits: 1

Mike was updated.

Menu option: 4

Current lineup number: 4

Mike was selected.

New lineup number: 1

Mike was moved.

Menu option: 7

Bye!

Specifications

 Use a list of lists to store each player in the lineup.

 Use a tuple to store all valid positions (C, 1B, 2B, etc).

 Make sure that the user’s position entries are valid.

In: Computer Science

a. What is the main cue for splitting English documents into sentences? When and how might...

a. What is the main cue for splitting English documents into sentences? When and how might it go wrong? ( python coding required.)

b. What is the main cue in English for splitting sentences into tokens? When and how might it go wrong? (python coding required.)

In: Computer Science

its java language. 1. Create a class called Car. A Car has instance variables, constructor parameters,...

its java language.

1. Create a class called Car. A Car has instance variables, constructor parameters, setters, and getters for “year manufactured” and “make” and “model” (e.g. 2016 Honda Civic) 2. Create a class called CarLot which has an array of 5 Car references. There are two constructors: (a) One constructor takes no parameters and simply populates the array with these cars: cars[0] = new Car(2016, “honda”, “civic”); cars[2] = new Car(2017, “Lamborghini”, “aventador”); cars[3] = new Car(2000, null, “caravan”); cars[4] = new Car(2010, “dodge”, null); (b) The other constructor takes one parameter: a Car, and puts into the array as the first (and only) element. 3. Create a method public void addCar(Car car) which adds the new Car to the first empty element in the array; if there is no empty element just System.out.println(“no room”) instead. 4. Create a method public Car getCar(int index) which returns a reference to the car at the specified array index; if the index is not valid (i.e. not 0 to 4) return null instead. 5. Create a method public Car getOldestCar() which returns a reference to the oldest car in the array. Use your Car class from the previous question. 2. Create a class called UsedCarLot which has an ArrayList of Car references. 3. The constructor takes parameter: the name of the UsedCarLot (e.g. “Jason’s Used Cars”)…store this in the instance variable String CarLotName and has an accessor too: public String getName(). Also the constructor does this: It simply populates the ArrayList with these cars: cars.add(new Car(2016, “honda”, “civic”)); cars.add(new Car(2017, “Lamborghini”, “aventador”)); cars.add(new Car(2000, null, “caravan”)); cars.add(new Car(2010, “dodge”, null)); 4. Create a method public void addCar(Car car) which adds the Car parameter to the ArrayList. 5. Create a method public void removeCarsBetween(int firstYear, int lastYear) which removes all Cars from the list which were manufactured between firstYear and lastYear (inclusive). Use an iterator. 6. Create a method public Car[] getCarsMadeBy(String maker) which returns an array of Car references…all of the Cars which are made by the parameter maker.

In: Computer Science

Briefly describe the process/technology used by dye-based optical storage devices/media (e.g., DVD-R) to write content to...

Briefly describe the process/technology used by dye-based optical storage devices/media (e.g., DVD-R) to write content to a disc.

In: Computer Science

Data structure program Implement (your own) the Radix Sort using single linked list java language

Data structure program Implement (your own) the Radix Sort using single linked list

java language

In: Computer Science

Write assembly code to implement the expression A = (B + C - D) x (D...

Write assembly code to implement the expression A = (B + C - D) x (D + E x F) on three-, two-, one-, and zero-address machines (do not change the values of the operands). Refer to Chapter 5 Slides 25-28 for the syntax.

In: Computer Science

this code is about implementing stacks , I want for someone to rewrite it totally in...

this code is about implementing stacks , I want for someone to rewrite it totally in different way

#include <iostream>
#include <stdexcept>
#include <vector>
#include <cstdlib>
using namespace std;

class Stack {
    public:
        bool isEmpty();
        // returns true if stack has no elements stored

        int top();
        // returns element from top of the stack
        // throws runtime_error("stack is empty")

        int pop();
        // returns element from top of the stack and removes it
        // throws runtime_error("stack is empty")

        void push(int);
        // puts a new element on top of the stack

    private:
        vector<int> elements;
};

//member function definitions
bool Stack::isEmpty()
{
    return elements.empty();
}

int Stack::top()
{
    if(isEmpty())
        throw runtime_error("stack is empty");
    return elements.back();
}

int Stack::pop()
{
    if(isEmpty())
        throw runtime_error("stack is empty");
    int item = elements.back();
    elements.pop_back();
    return item;
}

void Stack::push(int item)
{
    elements.push_back(item);
}
//member functions definitions end

int main()
{
    string line, cmd;
    int val;
    Stack stack;

    cout << "stack> ";
    //read line by line
    while(getline(cin, line))
    {
        //get the command

        //trim leading whitespace
        if(line.find_first_not_of(" \t") == string::npos)
        {
            // empty line
            cout << "stack> ";
            continue;
        }
        line = line.substr(line.find_first_not_of(" \t"));
        cmd = line.substr(0, line.find(" "));
        if(cmd == "push")
        {
            // remaining string
            line = line.substr(line.find(" ") + 1);
            if(line.size() == 0
                    || ( (line[0] == '-' || line[0] == '+') && line.find_first_of("0123456789") > 1)
                    || line.find_first_not_of("0123456789+-") == 0)
            {
                cout << "error: not a number" << endl;
            }
            else
            {
                val = atoi(line.c_str());
                stack.push(val);
            }
        }
        else if(cmd == "pop")
        {
            try
            {
                val = stack.pop();
                cout << val << endl;
            }
            catch(runtime_error& e)
            {
                cout << "error: " << e.what() << endl;
            }
        }
        else if(cmd == "top")
        {
            try
            {
                val = stack.top();
                cout << val << endl;
            }
            catch(runtime_error& e)
            {
                cout << "error: " << e.what() << endl;
            }
        }
        else if(cmd == "list")
        {
            Stack s2;
            bool first = true;
            cout << "[";
            /* pop repeatedly and store in another stack */
            while(! stack.isEmpty())
            {
                val = stack.pop();
                s2.push(val);
                if(!first)
                    cout << ",";
                cout << val;
                first = false;
            }
            cout << "]" << endl;
            /* restore original stack */
            while(! s2.isEmpty())
            {
                stack.push(s2.pop());
            }
        }
        else if(cmd == "end")
        {
            break;
        }
        else
        {
            cout << "error: invalid command" << endl;
        }

        cout << "stack> ";
    }

    cout << endl;
}

In: Computer Science

2.2.1 cLL The class is described according to the simple UML diagram below: 2cLL<T> -head:item<T> *...

2.2.1
cLL
The class is described according to the simple UML diagram below:
2cLL<T>
-head:item<T> *
-size:int
------------------------
+cLL()
+~cLL()
+isEmpty():bool
+getSize():int
+push(newItem: item<T>*):void
+pop():item<T>*
+removeAt(x:T):item<T> *
+printList():void
The class variables are as follows:
• head: The head pointer for the linked list.
• size: The current size of the circular linked list. It starts at 0 and grows as the list
does.
The class methods are as follows:
• cLL: The constructor. It will set the size to 0 and initialise head as null.
• ∼cLL: The class destructor. It will iterate through the circular linked list and
deallocate all of the memory assigned for the items.
• isEmpty: This function returns a bool. If the circular linked list is empty, then it
will return true. Otherwise, if it has items then it will return false.
• getSize: This returns the current size of the circular linked list. If the list is empty
the size should be 0.
• push: This receives a new item and adds it to the circular linked list. It is added to
the front of the list. The front in this case refers to the head.
• pop: This receives, and returns, the first element in the list. The first element is
removed from the list in the process. If the list is empty, return null. The first
element referring to the head pointer in this case.
• removeAt: This will remove an item from the linked list based on its value. If
the value is not found, nothing should be removed. Also note that in the event of
multiple values being found, the first one in the list, from head, should be removed.
Note that nothing is deleted. Instead the node must be removed through relinking
and then returned.
• printList: This will print out the entire list from head onwards. The output consists
of a single comma delimited line, with a newline at the end. For example:
1,2,3,4,5
32.2.2
item
The class is described according to the simple UML diagram below:
item <T>
-data:T
-------------------
+item(t:T)
+~item()
+next: item*
+getData():T
The class has the following variables:
• data: A template variable that stores some piece of information.
• next: A pointer of item type to the next item in the linked list.
The class has the following methods:
• item: This constructor receives an argument and instantiates the data variable with
it.
• ∼item: This is the destructor for the item class. It prints out ”Item Deleted” with
no quotation marks and a new line at the end.
• getData: This returns the data element stored in the item.

In: Computer Science

haskell : write a function that reverse the first three element of a list, but not...

haskell :

write a function that reverse the first three element of a list, but not the rest.
example [1,2,3,4,5,6] == [3,2,1,4,5,6]

In: Computer Science

Create a program that implements a singly linked list of Students. Each node must contain the...

Create a program that implements a singly linked list of Students.

Each node must contain the following variables:

  • Student_Name
  • Student_ID

In main():

  1. Create the following list using addHead(). The list must be in the order shown below.

Student_ID

Student_Name

00235

Mohammad

00662

Ahmed

00999

Ali

00171

Fahad

  1. Print the complete list using toString() method.
  2. Create another list using AddTail(). The list must be in the order shown below.

Student_ID

Student_Name

00236

Salman

00663

Suliman

00998

Abdulrahman

  1. Print the complete list using toString() method.
  2. Delete head note from both list.
  3. Print the both list using toString() method.

in java

In: Computer Science

Using python Create a function that inputs a list of numbers and outputs the median of...

Using python

Create a function that inputs a list of numbers and outputs the median of the numbers.
sort them and them show the output.

In: Computer Science

Show how circular linked list can be useful to implement Circular Queue (CQ) ADT (Abstract Data...

Show how circular linked list can be useful to implement Circular Queue (CQ) ADT (Abstract Data Type). Compare and contrast with array based implementation. Which one would you recommend to implement CQ and why

In: Computer Science

Write a Java program to implement a double-linked list with addition of new nodes at the...

Write a Java program to implement a double-linked list with addition of new nodes at the end of the list. Add hard coded nodes 10, 20, 30, 40 and 50 in the program. Print the nodes of the doubly linked list.

In: Computer Science

(Computer Network Question)Answer the following questions when the two nodes with a point-to-point connection are communicating...

(Computer Network Question)Answer the following questions when the two nodes with a point-to-point connection are communicating with a link with a bandwidth of 8 Mbps and a one-way radio delay of 2 mssec. (The header overhead, i.e. header length, is ignored in the performance calculation process.)

a)Draw a sliding window of 1KB (8000bit) frames with a size of 1KB (KB) when sending in a sliding window with a size of 2 transmission window, the process of operation if no error occurs. What is the link utilization rate when the link is said to be long-term communication in a communication environment like this? Calculate the utilization with the base of the utilization coefficient calculation (assume that the receiving node immediately sends the ACK and the length of the ACK is negligible).

b)To maintain link utilization of 80% or more in the same communication environment, what should be the minimum size of the transmission window? Figure out the transmission process of the proposed answer and calculate the transmission efficiency.

In: Computer Science