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...
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...
Your C program will do the following : Must use at least 2 function prototypes &...
Your C program will do the following : Must use at least 2 function prototypes & definitions . You can also use repetitions , control structures . You re not allowed any type of global arrays, or global variables. You are only allowed to use 2 dimensional arrays. 1. In your main program, create a array of size 7 X 7. 2. Create a function that accepts the empty array. The function will initiate the to zero. Then, the function...
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...
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...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT