Questions
Write a full MIPS assembly code for: Function Compare(int A[][], int B[][], int M, int N,...

Write a full MIPS assembly code for: Function Compare(int A[][], int B[][], int M, int N, int i, int j, int k, int l). This function compares the elements of the array A placed between (i,j) and (k,l) with the corresponding elements of the array B placed between the same indexes. The function returns the number of elements of both matrices that coincide in the same position (c,d). That is, it is necessary to check each element A[c,d] with the element B[c,d], with (c,d) inside the corresponding indexes to (i,j) and (k,l), both included. The function accepts 8 arguments:

A: starting address of an integer matrix of MxN dimension.

B: starting address of an integer matrix of dimension MxN.

M: number of rows of the A and B matrix.

N: number of columns of the A and B matrix.

i: an integer corresponding to the row of the first element of the matrix to be considered.

j: a whole number corresponding to the column of the first element of the matrix to be considered. o

k: a whole number corresponding to the row of the last element of the matrix to be considered.

l: a whole number corresponding to the column of the last element of the matrix to be considered.

The function returns two values. In case of error, it simply returns a result with value -1. The possible errors are: o M or N are negative or zero. o The indexes passed as arguments (i,j,k, and l) are out of range. o The element (k,l) is previous in the matrix to the element (i,j). It will not be considered an error if (i,j) and (k,l) have the same value and refer to the same element. If no error is detected, the function returns as a first result the value 0 and as second the number of elements that coincide in the same position in the arrays A and B.

In: Computer Science

a)     Write a program that reads a list of integers, and outputs all even integers in the...

a)     Write a program that reads a list of integers, and outputs all even integers in the list. For example, if the input list is [1, 2, 13, 14, 25], the output list should be [2, 14].

b)    Based on your code for part (a), write a program that reads a list of integers, and reports True if all numbers in the list are even, and False otherwise. Example: For input [1, 2, 13, 14, 25], the output should be False.

Your program must define and call the following two functions.

evens() returns all even integers in the list are even.

all_even() returns True if all integers in the list are even and false otherwise.

Your code could look like this

#Your name here

def evens(thelist):
#your code goes here



def all_even(thelist):
#your code goes here



evens([1, 2, 13, 14, 25]) #should return [2,14]
all_even([1, 2, 13, 14, 25]) #should return False

In: Computer Science

Using Java Although the long data type can store large integers, it cannot store extremely large...

Using Java

Although the long data type can store large integers, it cannot store extremely large values such as an integer with 100 digits. Create a HugeNumber class that uses a linked list of single digits to represent non-negative integers of arbitrary length. The class should include a method to add a new most significant digit to the existing number so that longer and longer numbers can be created. Also add methods to reset the number and to return the value of the huge integer as a String (is this toString?) along with appropriate constructor and accessor methods.

In addition to the requirements given above, implement an inner class iterator which will allow you to sequence through the digits of the HugeNumber one at a time.

Decide if the HugeNumber contains no digits, then converting it to a String should return a “-1” or an empty string and document your decision.

Submit program files for your HugeNumber class and of your class containing main. Include at least test cases for 3 huge numbers, each with 12 or more digits. Make sure to demonstrate the methods to reset the HugeNumber, to return the number as a String, and to iterate through the digits of the HugeNumber one at a time.

In: Computer Science

*// 1- Add JavaDoc to This classes 2- Mak a UML */ import java.util.*; public class...

*//
1- Add JavaDoc to This classes 
2- Mak a UML
*/
import java.util.*;
public class Display
{
   public static void main(String[] args)
   {
       altEnerCar car1 = new altEnerCar(20000, 2001, 20000);
       altEnerCar car2 = new HydrogenCar(0, 2012, 50000, 100, false);
       altEnerCar car3 = new ElectricCar(0, 2014, 30000, 10, 50);
       altEnerCar car4 = new NaturalGasCar(0, 2000, 60000, 5, 20);
       altEnerCar car5 = new PropaneCar(0, 2011, 45000, 10, true);
      
       ArrayList<altEnerCar> cars = new ArrayList<altEnerCar>();
      
       cars.add(car1);
       cars.add(car2);
       cars.add(car3);
       cars.add(car4);
       cars.add(car5);
       Collections.sort(cars);
       System.out.println(cars);
      
   }


}




/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author charl
 */






public class ElectricCar extends NoEmissionsCar
{
   private double batterycharge;
   public ElectricCar()
   {
       this.batterycharge = 200;
   }
   public ElectricCar(double miles, int yearmade, double price, double fuelcost, double batterycharge)
   {
       super(miles, yearmade, price, fuelcost);
       this.batterycharge = batterycharge;
   }
   @Override
   public void setFuelCost(double fuelcost)
   {
       this.fuelcost = fuelcost;
   }
   @Override
   public double getFuelCost()
   {
       return this.fuelcost;
   }
   public void setBatteryCharge(double batterycharge)
   {
       this.batterycharge = batterycharge;
   }
   public double getBatteryCharge()
   {
       return this.batterycharge;
   }
   @Override
   public String toString()
   {
       return "\tMiles: "+miles+"\tMake year: "+yearmade+"\tPrice: "+price+"\tFuel cost: "+fuelcost+"\tBatery Charge: "+batterycharge;
   }


}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author charl
 */




public abstract class EmissionsCar extends altEnerCar
{
   protected double emissions;
   public EmissionsCar()
   {
       this.emissions = 60;
   }
   public EmissionsCar(double miles, int yearmade, double price, double emissions)
   {
       super(miles, yearmade, price);
       this.emissions = emissions;
   }
   public abstract void setEmissions(double emissions);
   public abstract double getEmissions();
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author charl
 */


public class HydrogenCar extends NoEmissionsCar
{
   private boolean infastructure;
   public HydrogenCar()
   {
       this.infastructure = false;
   }
   public HydrogenCar(double miles, int yearmade, double price, double fuelcost, boolean infastructure)
   {
       super(miles, yearmade, price, fuelcost);
       this.infastructure = infastructure;
   }


   
   @Override
   public void setFuelCost(double fuelcost)
   {
       this.fuelcost = fuelcost;
   }
   @Override
   public double getFuelCost()
   {
       return this.fuelcost;
   }
   public void setInfastructure(boolean infastructure)
   {
       this.infastructure = infastructure;
   }
   public boolean getInfastructure(boolean infastructure)
   {
       return this.infastructure;
   }
   @Override
   public String toString()
   {
       return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tFuel Cost: "+fuelcost+"\tInfrastructure: "+infastructure;
   }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author charl
 */


public class NaturalGasCar extends EmissionsCar
{
   private double methaneemissions;
   public NaturalGasCar()
   {
       this.methaneemissions = 15;
   }
   public NaturalGasCar(double miles, int yearmade, double price, double emissions, double methaneemissions)
   {
       super(miles, yearmade, price, emissions);
       this.methaneemissions = methaneemissions;
   }


    
   @Override
   public void setEmissions(double emissions)
   {
       this.emissions = emissions;
      
   }
   @Override
   public double getEmissions()
   {
       return this.emissions;
   }
   public void setMethaneEmissions(double methaneemissions)
   {
       this.methaneemissions = methaneemissions;
      
   }
   public double getMethaneEmissions()
   {
       return this.methaneemissions;
   }
   @Override
   public String toString()
   {
       return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tEmission: "+emissions+"\tMethane Emission: "+methaneemissions;
   }


}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author charl
 */




public abstract class NoEmissionsCar extends altEnerCar
{
   protected double fuelcost;
   public NoEmissionsCar()
   {
       this.fuelcost = 30;
   }
   public NoEmissionsCar(double miles, int yearmade, double price, double fuelcost)
   {
       super(miles, yearmade, price);
       this.fuelcost = fuelcost;
   }
   public abstract void setFuelCost(double fuelcost);
   public abstract double getFuelCost();
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author charl
 */


public class PropaneCar extends EmissionsCar
{
   private boolean infastructure;
   public PropaneCar()
   {
       this.infastructure = true;
   }
   public PropaneCar(double miles, int yearmade, double price, double emissions, boolean infastructure)
   {
       super(miles, yearmade, price, emissions);
       this.infastructure = infastructure;
   }
   @Override
   public void setEmissions(double emissions)
   {
       this.emissions = emissions;
      
   }
   @Override
   public double getEmissions()
   {
       return this.emissions;
   }
   public void setMethaneEmissions(boolean infastructure)
   {
       this.infastructure = infastructure;
      
   }
   public boolean getMethaneEmissions()
   {
       return this.infastructure;
   }
   @Override
   public String toString()
   {
       return "\tMiles: "+miles+"\tMake Year: "+yearmade+"\tPrice: "+price+"\tEmissions: "+emissions+"\t Infrastructure: "+infastructure;
   }


}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author charl
 */
public class altEnerCar implements Comparable<altEnerCar>
{
   protected double miles;
   protected int yearmade;
   protected double price;
  
   public altEnerCar()
   {
       this.miles = 0;
       this.yearmade = 2019;
       this.price = 50000;
   }
   public altEnerCar(double miles, int yearmade, double price)
   {
       this.miles = miles;
       this.yearmade = yearmade;
       this.price = price;
   }
   public void setMiles(double miles)
   {
       this.miles = miles;
   }
   public void setYearMade(int yearmade)
   {
       this.yearmade = yearmade;
   }
   public void setPrice(double price)
   {
       this.price = price;
   }
   public double getMiles()
   {
       return this.miles;
   }
   public int getYearMade(int yearmade)
   {
       return this.yearmade;
   }
   public double getPrice()
   {
       return this.price;
   }
   public String toString()
   {
       return "\nmiles: "+miles+"\nyear made: "+yearmade+"\nprice: "+price;
   }
   public int compareTo(altEnerCar otherAECar)
   {
       return -1*(Double.valueOf(otherAECar.getPrice()).compareTo(this.price));
   }
  
}

In: Computer Science

Create a JavaScript program of objects that asks the user how old they are in years....

Create a JavaScript program of objects that asks the user how old they are in years. Then ask the user if they would like to know how old they are in months, days, hours, or seconds. Use if/else conditional statements to display their approximate age in the selected timeframe. Perform all calculations using an AgeConverter class that accepts the age in years during initialization and has separate properties and methods to calculate and return the age in months, days, hours, and seconds. Include data validation in the class and error handling in the main program by using Node Js as IDE.

In: Computer Science

What is the role of physical software media in documentation? What are all the information must...

What is the role of physical software media in documentation? What are all the information must be stored on a media label? i need a unique answer please don't copy from other answers

In: Computer Science

What is an example of a cryptography technology? How is it used or misused?

  • What is an example of a cryptography technology?
  • How is it used or misused?

In: Computer Science

In java, Finding the maximum value in a BST (Binary Search Tree). Students need to write...

In java,

Finding the maximum value in a BST (Binary Search Tree). Students need to write the code.

In: Computer Science

Use the Universal Access utility to explore the different assistive technologies available within Fedora 20. Note...

Use the Universal Access utility to explore the different assistive technologies available within Fedora 20. Note the ones that you find useful.

In: Computer Science

Jojo is given N integers, A 1, A 2, ..., A N by his teacher. His...

Jojo is given N integers, A 1, A 2, ..., A N by his teacher. His teacher also give him an integer K and 2 M integers, L 1, L 2, ..., L M and R 1, R 2, ..., R M. For each i from 1 to M , his teacher asked him to calculate the sum of multiple of K index numbers from index L i to R i . For example if L i = 3 and R i = 10 and K = 3, then he has to calculate the value of ( A 3 + A 6 + A9). Help him by making the program to calculate it quickly!

Format Input:

The first line consist of three integers, N , M, and K. The second line consist of N integers, A 1, A 2, ..., A N . The next M lines consist of two integers, L i and R i.

Format Output:

Output M lines, the answer for L i and R i , where i is an integer from 1 to M.

Constraints

• 1 ≤ N, M ≤ 105

• 1 ≤ A i ≤ 102 • 1 ≤ K ≤ 10

• 1 ≤ L i ≤ R i ≤ N

Sample Input 1 (standard input):

5 3 2

100 3 1 87 6

1 1

1 5

3 4

Sample Output 1 (standard output):

0

90

87

Note: Use C language, don’t use function./recursive/void.

The input is N,M,K not only N &M.

In: Computer Science

I have added the MyList.java all the way on the bottom. Thats all the detail I...

I have added the MyList.java all the way on the bottom.

Thats all the detail I have for this and what kind of more detail information you need.

Plz Write the program in Java. And Plz post the running program with main and test.Thanks.

Implementing Lists:

Start by carefully reading Listing 24.5: MyLinkedList.java (on page 938 of the 11th Edition of the text). Note that the listing is incomplete. Your assignment is to implement a revised MyLinkedList class after you have included all the code needed to fill in and complete all the methods that were omitted. Next, write a (main) driver program that initializes a linked list with 10 names (your choice), and then completely tests every one of its methods of ensure that the class meets all its requirements.

Listing 24.5

MyLinkedList.java
1 public class MyLinkedList implements MyList {
2 private Node head, tail;
3 private int size = 0; // Number of elements in the list
4
5 /** Create an empty list */
6 public MyLinkedList() {
7 }
8
9 /** Create a list from an array of objects */
10 public MyLinkedList(E[] objects) {
11 for (int i = 0; i < objects.length; i++)
12 add(objects[i]);
13 }
14
15 /** Return the head element in the list */
16 public E getFirst() {
17 if (size == 0) {
18 return null;
19 }
20 else {
21 return head.element;
22 }
23 }
24
25 /** Return the last element in the list */
26 public E getLast() {
27 if (size == 0) {
28 return null;
29 }
30 else {
31 return tail.element;
32 }
33 }
34
35 /** Add an element to the beginning of the list */
36 public void addFirst(E e) {
37 // Implemented in Section 24.4.3.1, so omitted here
38 }
39
40 /** Add an element to the end of the list */
41 public void addLast(E e) {
42 // Implemented in Section 24.4.3.2, so omitted here
43 }
44
45 @Override /** Add a new element at the specified index
46 * in this list. The index of the head element is 0 */
47 public void add(int index, E e) {
48 // Implemented in Section 24.4.3.3, so omitted here
49 }
50
51 /** Remove the head node and
52 * return the object that is contained in the removed node. */
53 public E removeFirst() {
54 // Implemented in Section 24.4.3.4, so omitted here
55 }
56
57 /** Remove the last node and
58 * return the object that is contained in the removed node. */
59 public E removeLast() {
60 // Implemented in Section 24.4.3.5, so omitted here
61 }
62
63 @Override /** Remove the element at the specified position in this
64 * list. Return the element that was removed from the list. */
65 public E remove(int index) {
66 // Implemented earlier in Section 24.4.3.6, so omitted
67 }
68
69 @Override /** Override toString() to return elements in the list */
70 public String toString() {
71 StringBuilder result = new StringBuilder("[");
72
73 Node current = head;
74 for (int i = 0; i < size; i++) {
75 result.append(current.element);
76 current = current.next;
77 if (current != null) {
78 result.append(", "); // Separate two elements with a comma
79 }
80 else {
81 result.append("]"); // Insert the closing ] in the string
82 }
83 }
84
85 return result.toString();
86 }
87
88 @Override /** Clear the list */
89 public void clear() {
90 size = 0;
91 head = tail = null;
92 }
93
94 @Override /** Return true if this list contains the element e */
95 public boolean contains(Object e) {
96 // Left as an exercise
97 return true;
98 }
99
100 @Override /** Return the element at the specified index */
101 public E get(int index) {
102 // Left as an exercise
103 return null;
104 }
105
106 @Override /** Return the index of the head matching element in
107 * this list. Return −1 if no match. */
108 public int indexOf(Object e) {
109 // Left as an exercise
110 return 0;
111 }
112
113 @Override /** Return the index of the last matching element in
114 * this list. Return −1 if no match. */
115 public int lastIndexOf(E e) {
116 // Left as an exercise
117 return 0;
118 }
119
120 @Override /** Replace the element at the specified position
121 * in this list with the specified element. */
122 public E set(int index, E e) {
123 // Left as an exercise
124 return null;
125 }
126
127 @Override /** Override iterator() defined in Iterable */
128 public java.util.Iterator iterator() {
129 return new LinkedListIterator();
130 }
131
132 private class LinkedListIterator
133 implements java.util.Iterator {
134 private Node current = head; // Current index
135
136 @Override
137 public boolean hasNext() {
138 return (current != null);
139 }
140
141 @Override
142 public E next() {
143 E e = current.element;
144 current = current.next;
145 return e;
146 }
147
148 @Override
149 public void remove() {
150 // Left as an exercise
151 }
152 }
153
154 private static class Node {
155 E element;
156 Node next;
157
158 public Node(E element) {
159 this.element = element;
160 }
161 }
162 }

MyList.java
public interface MyList extends java.lang.Iterable  {
    //Add a new element at the end of this list
    public void add(E e);

    //Add a new element at the specified index in this list
    public void add(int index, E e);

    //Clear the list
    public void clear();

    //Return true if this list contains the element
    public boolean contains(E e);

    //Return the element from this list at the specified index
    public E get(int index);

    //Return the index of the first matching element in this list.
    //Return -1 if no match.
    public int indexOf(E e);

    /** Return true if this list contains no elements */
    public boolean isEmpty();

    /** Return the index of the last matching element in this list
     * Return -1 if no match. */
    public int lastIndexOf(E e);

    /** Remove the first occurrence of the element o from this list.
     * Shift any subsequent elements to the left.
     * Return true if the element is removed.
     */
    public boolean remove(E e);

    /** Remove the element at the specified position in this list
     * Shift any subsequent elements to the left.
     * Return the element that was removed from the list.
     */
    public E remove(int index);

    /** Replace the element at the specified position in this list
     * with the specified element and returns the new set.
     * */
    public Object set(int index, E e);

    /** Return the number of elements in this list */
    public int size();
}

In: Computer Science

I keep getting the error below in zbooks. How can I fix this. Thank You JAVA...

I keep getting the error below in zbooks. How can I fix this. Thank You JAVA

zyLabsUnitTest.java:14: error: cannot find symbol s = MidtermProblems.difference(75, 75);

^ symbol: method difference(int,int) location: class MidtermProblems 1 error

import java.lang.Math;

public class MidtermProblems {

public static String difference(int a, int b) {

int diff = Math.abs(a - b);

String ans = "";

   if (diff == 0) {

ans = "EQUAL";

   } else if (diff > 10) {

ans = "Big Difference " + diff;

   } else if (diff <= 10) {

ans = "Small Difference " + diff;

        }

        return ans;
   }
}


In: Computer Science

I have a C problem. I need to read the data of a txt file to...

I have a C problem. I need to read the data of a txt file to array by struct, then use these data to sum or sort.

The txt file and the struct like

aa.txt

1 2

3 4

*****************************

struct aaa{
int num1,num2;
}bbb[2];

num1 for 1,3, num2 for 2 4

I made a void readfile () function for read data. How can I pass the numbers to another function ( void sum () and void sort() ) for sum and sort

I finished the void readfile(), but I have no idea how to pass the value to another function.

I tries to use the pointer of struct, can you give me a general idea?

Because I must move data to an array, is my array of struct wrong? I mean if I need to use malloc

Thanks

In: Computer Science

Using the software Emulator EMU8086, write an assembly program that uses a loop to print "HELLO...

Using the software Emulator EMU8086, write an assembly program that uses a loop to print "HELLO WORLD" 3 times and "LIFE" 2 times.

Example:

HELLO WORLD

HELLO WORLD

HELLO WORLD

LIFE

LIFE

  

In: Computer Science

Write a complete C++ program to implements a Min-heap. Each node will contain a single integer...

Write a complete C++ program to implements a Min-heap.

Each node will contain a single integer data element. Initialize the Min-heap to contain 5 nodes, with the values 8, 12, 24, 32, 42.

The program should allow for the insertion and deletion of nodes while maintaining a Min-Heap.

The program should allow the user to output data in Preorder, Inorder and Postorder.

The program should loop with menu items for each of the above objectives and the choice to quit

Here's the code:

**EDIT: Need help in outputting data into Preorder, Inorder and Postorder, plus ensuring the nodes are implemented correctly (I think I overlooked this part). **

#include studio.h
#include isotream

int array[100]; // variable for array to store up to 100 elements
int n;


using namespace std;
void display();
void delete_elem(int num);


void heapify(int index,int n){
if(index >= n)return;
  

int left = 2*index;
int right = 2*index + 1;
int mx_ind = index;
if(left < n and array[left] > array[mx_ind]){
mx_ind = left;
}
if(right < n and array[right] > array[mx_ind]){
mx_ind = right;
}
if(mx_ind != index){
swap(array[mx_ind],array[index]);
heapify(mx_ind,n);
}

}
int insert(int num, int location)
{
int parentnode;
while (location > 0)
{
parentnode =(location - 1)/2;
if (num <= array[parentnode])
{
array[location] = num;
return location;
}
array[location] = array[parentnode];
location = parentnode;
}
array[0] = num;
return 0;
}

int main()
{
int choice, num;
n = 0;
while(1)
{
printf("1.Insert the element \n");
printf("2.Delete the element \n");
printf("3.Display all elements \n");
printf("4.Quit \n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter the element to be inserted to the list : ");
scanf("%d", &num);
insert(num, n);
n = n + 1;
break;
case 2:
printf("Enter the elements to be deleted from the list: ");
scanf("%d", &num);
delete_elem(num);
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("Invalid choice \n");
}
}
}

void display()
{
int i;
if (n == 0)
{
printf("Heap is empty \n");
return;
}
for (i = 0; i < n; i++)
printf("%d ", array[i]);
printf("\n");
}


void delete_elem(int num)
{
int left, right, i, temp, parentnode;

for (i = 0; i < num; i++) {
if (num == array[i])
break;
}
if (num != array[i])
{
printf("%d not found in heap list\n", num);
return;
}
array[i] = array[n - 1];
n = n - 1;
parentnode =(i - 1) / 2;
if (array[i] > array[parentnode])
{
insert(array[i], i);
return;
}
left = 2 * i + 1;
right = 2 * i + 2;
while (right < n)
{
if (array[i] >= array[left] && array[i] >= array[right])
return;
if (array[right] <= array[left])
{
temp = array[i];
array[i] = array[left];
array[left] = temp;
i = left;
}
else
{
temp = array[i];
array[i] = array[right];
array[right] = temp;
i = right;
}
left = 2 * i + 1;
right = 2 * i + 2;
}
if (left == n - 1 && array[i])
{
temp = array[i];
array[i] = array[left];
array[left] = temp;
}
}

In: Computer Science