Question

Given the following code: public void expand(Object a) {     // assume element has enough capacity...

Given the following code:

public void expand(Object a) {

    // assume element has enough capacity

    for (int i = size - 1; i >= 0; i--) {

        element[4 * i + 3] = a;

        element[4 * i + 2] = a;

        element[4 * i + 1] = a;

        element[4 * i] = element[i];

     }

     size = 4 * size;

}

element is a one-dimensional array that stores elements of the type Object. The data

member size is such that the list elements are in positions 0 through size-1 of the array.

(a)If the list element[0:2] = [a, b, c], whose size is 3, write the result and the size of the array element after executing

expand(new Integer(d)).

Assume that the array element has enough capacity for expansion.

where a, b, c, d are generated as follow:

Number

Based on your student ID number, formed by its

a

1 st and 2nd digits

b

2 nd and 3rd digits

c

3 rd and 4th digits

d

4 th and 5th digits

For example, the student ID is 19563755A.

Values of a to d are: 19, 95, 56, 63

Homework Answers

Answer #1

expand(object a) OUTPUT :
element[4*2+3] = element[11] = a;
element[4*2+2] = element[10] = a;
element[4*2+1] = element[9] = a;
element[4 * 2] = element[2] = c;(given)

similarly,

element[11] = a;
element[10] = a;
element[9] = a;
element[8] = c;
element[7] = a;
element[6] = a;
element[5] = a;
element[4] = b;
element[3] = a;
element[2] = a;
element[1] = a;
element[0] = a;

size = 4*3 = 12;

CODE FOR SECOND PART
public void expand(new integer d){
    string str;
    cin>>str;
     int size = str.length();
    int input[size];
    for(int i=0; str[i]!='\0'; i++){
        input[i] = str[i]-'0';
    }
    int a, b, c, d;
    a = input[0]*10 + input[1];
    b = input[1]*10 + input[2];
    c = input[2]*10 + input[3];
    d = input[3]*10 + input[4];
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
By JAVA programming language public void expand(Object a) {     // assume element has enough capacity...
By JAVA programming language public void expand(Object a) {     // assume element has enough capacity     for (int i = size - 1; i >= 0; i--) {         element[4 * i + 3] = a;         element[4 * i + 2] = a;         element[4 * i + 1] = a;         element[4 * i] = element[i];      }      size = 4 * size; } element is a one-dimensional array that stores elements of the type Object....
The AssemblyLine class has a potential problem. Since the only way you can remove an object...
The AssemblyLine class has a potential problem. Since the only way you can remove an object from the AssemblyLine array is when the insert method returns an object from the last element of the AssemblyLine's encapsulated array, what about those ManufacturedProduct objects that are "left hanging" in the array because they never got to the last element position? How do we get them out? So I need to edit my project. Here is my AssemblyLine class: import java.util.Random; public class...
Microsoft Visual Studio in C#: I have this code and need to loop through each element...
Microsoft Visual Studio in C#: I have this code and need to loop through each element of the patient's array and add to a listbox (lbAccountDisplay) each property of the patient's object. This is the 2nd time to ask this question; it should have all the detail you need to help me. It is a piece of a project and I am trying not to give you the whole project. How do I use a foreach loop to loop through...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4,...
public static void main(String[] args) { //Given the following code : int[][] array2D = {{3, 4, 5, 1}, {3,6,1,2}, {1,3,6,5}; Answer : 1- All values ​​of array2D are automatically 0 ? Yes or No 2- What is the value of array2D [3] .length ?________ 3-  The value that array2D.length shows is 12: Yes or No ? 4- Assign the value of 12 to the element in the third row, fourth column : 5- the value obtained when calculating array2D [1] [1]...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....