Question

In: Computer Science

Create MyArrayForString.java to handle 'String' type elements and create MyArrayForChar.java to handle 'char' type elements. Test...

Create MyArrayForString.java to handle 'String' type elements and
create MyArrayForChar.java to handle 'char' type elements.

Test them in MyArrayDemo.java.

I need this in java on textpad. There are two files, both have instructions in them on what to add in the code. They are posted below. I ONLY NEED TO TEST add() linearSearch() remove() and printArray().

public class MyArrayForDouble {
double[] nums;
int numElements;
public MyArrayForDouble() { // Constructor. automatically called when creating an instance
numElements = 0;
nums = new double[5];
}
public MyArrayForDouble(int capacity) { // Constructor. automatically called when creating an instance
numElements = 0;
nums = new double[capacity];
}
public MyArrayForDouble(double[] nums1) {
nums = new double[nums1.length];
for(int i=0;i<nums1.length;i++)
nums[i] = nums1[i];
numElements = nums1.length;
}
void printArray(){ // cost, times
System.out.printf("printArray(%d,%d): ",numElements,nums.length);
for(int i=0; i<numElements;i++)
System.out.print(nums[i]+" ");
System.out.println();
}
int linearSearch(double val) {
for(int i=0;i<numElements;i++)
if(nums[i] == val)
return i;
return -1;
}
int binarySearch(double val) {
int start = 0;
int end = nums.length - 1;
int mid;
while(start <= end) {
mid = (start + end)/2;
if(val == nums[mid])
return mid;
else if(val < nums[mid])
end = mid-1;
else // val > nums[mid]
start = mid + 1;
}
return -1;
}
private void enlarge() {
// double up the size of nums;
double[] new_nums = new double[nums.length*2];
for(int i=0;i<numElements;i++)
new_nums[i] = nums[i];
nums = new_nums;
}
void add(double val) {
if(isFull()) // if(numElements == nums.length)
enlarge();
nums[numElements] = val;
numElements++;
}
public void addOrder(int idx, double[] valArray) {
// add all elements of valArray from the specified position of nums.
// need to keep order
// eg) [10,20,30] --> addOrder(1,{1,2}) makes {10,1,2,20,30}
ensureCapacity(numElements + valArray.length);
// Here we can safely assume 'nums' has at least 'numElements + valArray.length' spaces
for(int i=numElements-1; i>=idx ; i--)
nums[i+valArray.length] = nums[i];
for(int i=0;i<valArray.length;i++)
nums[i+idx] = valArray[i];
numElements += valArray.length;
}
private void ensureCapacity(int count) {
if(count <= nums.length)
return;
// need more space
double[] new_nums = new double[count];
for(int i=0;i<numElements;i++)
new_nums[i] = nums[i];
nums = new_nums;
}
int remove(double val){
// search for an element that is equal to val. and remove it from 'nums'
int idx = linearSearch(val);
if(idx < 0)
return 0;
// fill the location with the last element
nums[idx] = nums[numElements-1];
numElements--;
return 1;
}
// void removeAll(int val) { // worst-case: latter half elements are equal to val
// // remove(10) in nums = {1, 2, 3, 2, 4, ..., 10, 10, 10, 10}
// // O(N) * N = O(N*N)
// // search for all the elements equal to val and remove them.
// while(remove(val) > 0);
// }
void removeAll(double val) { // O(N)
int j = 0;
for(int i=0;i<numElements;i++)
if(nums[i] != val)
nums[j++] = nums[i];
numElements = j;
}
double findMin() {
// return the minimum value among elements in nums;
double minV = nums[0];
for(int i=1;i<numElements;i++)
if( nums[i] < minV )
minV = nums[i];
return minV;
}
void sort() { // There is a bug in this code. Find it.
// sort 'nums' in ascending order. eg) 10, 20 , 30
for(int i=0;i<numElements-1;i++) {
int minIdx = i;
for(int j=i+1;j<numElements;j++)
if( nums[j] < nums[minIdx])
minIdx = j;
// swap between nums[i] and nums[minIdx]
double temp = nums[i];
nums[i] = nums[minIdx];
nums[minIdx] = temp;
}
}
double[] toArray() {
// return a copy of the array only with valid elements
//return nums; // this is not a right to return a copy.
double[] new_nums = new double[numElements];
for(int i=0;i<numElements;i++)
new_nums[i] = nums[i];
return new_nums;
}
public MyArrayForDouble clone(){
// return a copy of this instance/object
MyArrayForDouble nums1 = new MyArrayForDouble(this.toArray());
return nums1;
}
public void clear() {
numElements = 0;
}
// In the above class ‘MyArray’, define a new method ‘getElements(int start, int end)’
// that returns a new array. The new array should have elements
// of ‘nums’ from index ‘start’ to ‘end’ inclusively.
// For example, suppose nums = {10,20,30,40,50}. Then getElements(2,4)
// returns a new array {30,40,50}. Assume that index ‘start’ and ‘end’ are valid
// (you don’t need to check their validity).
public double[] getElements(int start, int end) {
double[] new_nums = new double[end-start+1];
for(int i= start; i <= end ; i++)
new_nums[i-start] = nums[i];
return new_nums;
}
boolean isEmpty() { return numElements == 0; }
boolean isFull() { return numElements==nums.length; }
}

----------------------------------------------------------------------
public class MyArrayDemo {
static void printArray(int[] nums){
for(int i=0; i<nums.length;i++)
System.out.print(nums[i]+" ");
System.out.println();
}
public static void main(String[] args) {
// MyArrayForDouble mynums1 = new MyArrayForDouble();
// mynums1.add(10.5); mynums1.add(1.9); mynums1.add(-0.2); mynums1.add(10.5); mynums1.printArray();
// System.out.println(mynums1.linearSearch(1.9));
// mynums1.remove(1.9); mynums1.printArray();
// mynums1.removeAll(10.5); mynums1.printArray();
// Add your code to test MyArrayForString and MyArrayForChar
// --> Required.
}
}

Solutions

Expert Solution

1.

public class MyArrayForDouble {
    double[] nums;
    int numElements;
    public MyArrayForDouble() { // Constructor. automatically called when creating an instance
        numElements = 0;
        nums = new double[5];
    }
    public MyArrayForDouble(int capacity) { // Constructor. automatically called when creating an instance
        numElements = 0;
        nums = new double[capacity];
    }
    public MyArrayForDouble(double[] nums1) {
        nums = new double[nums1.length];
        for(int i=0;i<nums1.length;i++)
            nums[i] = nums1[i];
        numElements = nums1.length;
    }
    void printArray(){        // cost, times
        System.out.printf("printArray(%d,%d): ",numElements,nums.length);
        for(int i=0; i<numElements;i++)        
            System.out.print(nums[i]+" ");    
        System.out.println();                    
    }    
    int linearSearch(double val) {
        for(int i=0;i<numElements;i++)        
            if(nums[i] == val)                
                return i;                    
        return -1;                                            
    }
    int binarySearch(double val) {
        int start = 0;                    
        int end = nums.length - 1;        
        int mid;                        
        while(start <= end) {             
            mid = (start + end)/2;        
            if(val == nums[mid])         
                return mid;                
            else if(val < nums[mid])     
                end = mid-1;            
            else // val > nums[mid]     
                start = mid + 1;        
        }
        return -1;                                                            
    }
    
    private void enlarge() {
        // double up the size of nums;
        double[] new_nums = new double[nums.length*2];
        for(int i=0;i<numElements;i++)
            new_nums[i] = nums[i];
        nums = new_nums;
    }
    void add(double val) {
        if(isFull())     // if(numElements == nums.length)
            enlarge();
        nums[numElements] = val;
        numElements++;
    }
    public void addOrder(int idx, double[] valArray) {
        // add all elements of valArray from the specified position of nums.
        // need to keep order
        // eg) [10,20,30] --> addOrder(1,{1,2}) makes {10,1,2,20,30}
        ensureCapacity(numElements + valArray.length);
        // Here we can safely assume 'nums' has at least 'numElements + valArray.length' spaces
        for(int i=numElements-1; i>=idx ; i--)
            nums[i+valArray.length] = nums[i];
        
        for(int i=0;i<valArray.length;i++)
            nums[i+idx] = valArray[i];
        numElements += valArray.length;
    }
    
    private void ensureCapacity(int count) {
        if(count <= nums.length)
            return;
        // need more space
        double[] new_nums = new double[count];
        for(int i=0;i<numElements;i++)
            new_nums[i] = nums[i];
        nums = new_nums;
    }
    int remove(double val){
        // search for an element that is equal to val. and remove it from 'nums'
        int idx = linearSearch(val);
        if(idx < 0)
            return 0;
        // fill the location with the last element
        nums[idx] = nums[numElements-1];
        numElements--;
        return 1;
    }
//    void removeAll(int val) { // worst-case: latter half elements are equal to val
//                             // remove(10) in nums = {1, 2, 3, 2, 4, ..., 10, 10, 10, 10}
//                             // O(N) * N = O(N*N)
//        // search for all the elements equal to val and remove them.
//        while(remove(val) > 0);
//    }
    void removeAll(double val) { // O(N)
        int j = 0;
        for(int i=0;i<numElements;i++)
            if(nums[i] != val)
                nums[j++] = nums[i];
        numElements = j;
    }
    double findMin() {
        // return the minimum value among elements in nums;
        double minV = nums[0];
        for(int i=1;i<numElements;i++)
            if( nums[i] < minV )
                minV = nums[i];
        return minV;
    }
    void sort() { 
        for(int i=0;i<numElements-1;i++) {
            int minIdx = i;
            for(int j=i+1;j<numElements;j++) {
                if( nums[j] < nums[minIdx]) {
                    minIdx = j;
            // swap between nums[i] and nums[minIdx]
            double temp = nums[i];
            nums[i] = nums[minIdx];
            nums[minIdx] = temp;
            }
        }
        }
    }
    double[] toArray() {
        // return a copy of the array only with valid elements
        //return nums; // this is not a right to return a copy.
        double[] new_nums = new double[numElements];
        for(int i=0;i<numElements;i++)
            new_nums[i] = nums[i];
        return new_nums;
    }
    public MyArrayForDouble clone(){
        // return a copy of this instance/object
        MyArrayForDouble nums1 = new MyArrayForDouble(this.toArray());
        return nums1;
    }
    public void clear() {
        numElements = 0;
    }
//    In the above class ‘MyArray’, define a new method ‘getElements(int start, int end)’
//    that returns a new array. The new array should have elements
//    of ‘nums’ from index ‘start’ to ‘end’ inclusively.
//    For example, suppose nums = {10,20,30,40,50}. Then getElements(2,4)
//    returns a new array {30,40,50}. Assume that index ‘start’ and ‘end’ are valid
//    (you don’t need to check their validity).
    public double[] getElements(int start, int end) {
        double[] new_nums = new double[end-start+1];
        for(int i= start; i <= end ; i++)
            new_nums[i-start] = nums[i];
        return new_nums;
    }
    boolean isEmpty() { return numElements == 0; }
    boolean isFull() { return numElements==nums.length; }
}

2.


public class MyArrayForChar {

    Character[] chars;
    int numElements;
    public MyArrayForChar() { 
        // Constructor. automatically called when creating an instance
        numElements = 0;
        chars = new Character[5];
    }
    public MyArrayForChar(int capacity) { 
        // Constructor. automatically called when creating an instance
        numElements = 0;
        chars = new Character[capacity];
    }
    public MyArrayForChar(Character[] nums1) {
        chars = new Character[nums1.length];
        for(int i=0;i<nums1.length;i++)
            chars[i] = nums1[i];
        numElements = nums1.length;
    }
    void printArray(){        // cost, times
        System.out.printf("printArray(%d,%d): ",numElements,chars.length);
        for(int i=0; i<numElements;i++)        
            System.out.print(chars[i]+" ");    
        System.out.println();                    
    }    
    
    int linearSearch(Character val) {
        for(int i=0;i<numElements;i++)        
            if(chars[i] == val)                
                return i;                    
        return -1;                                            
    }
    
    int binarySearch(Character val) {
        sort();
        int start = 0;                    
        int end = chars.length - 1;        
        int mid;                        
        while(start <= end) {             
            mid = (start + end)/2;        
            if(val == chars[mid])         
                return mid;                
            else if(val < chars[mid])     
                end = mid-1;            
            else // val > nums[mid]     
                start = mid + 1;        
        }
        return -1;                                                            
    }
    
    private void enlarge() {
        // Character up the size of nums;
        Character[] new_nums = new Character[chars.length*2];
        for(int i=0;i<numElements;i++)
            new_nums[i] = chars[i];
        chars = new_nums;
    }
    void add(Character val) {
        if(isFull())     // if(numElements == nums.length)
            enlarge();
        chars[numElements] = val;
        numElements++;
    }
    public void addOrder(int idx, Character[] valArray) {
        // add all elements of valArray from the specified position of nums.
        // need to keep order
        // eg) [10,20,30] --> addOrder(1,{1,2}) makes {10,1,2,20,30}
        ensureCapacity(numElements + valArray.length);
        // Here we can safely assume 'nums' has at least 'numElements + valArray.length' spaces
        for(int i=numElements-1; i>=idx ; i--)
            chars[i+valArray.length] = chars[i];
        
        for(int i=0;i<valArray.length;i++)
            chars[i+idx] = valArray[i];
        numElements += valArray.length;
    }
    
    private void ensureCapacity(int count) {
        if(count <= chars.length)
            return;
        // need more space
        Character[] new_nums = new Character[count];
        for(int i=0;i<numElements;i++)
            new_nums[i] = chars[i];
        chars = new_nums;
    }
    int remove(Character val){
        // search for an element that is equal to val. and remove it from 'nums'
        int idx = linearSearch(val);
        if(idx < 0)
            return 0;
        // fill the location with the last element
        chars[idx] = chars[numElements-1];
        numElements--;
        return 1;
    }
//    void removeAll(int val) { // worst-case: latter half elements are equal to val
//                             // remove(10) in nums = {1, 2, 3, 2, 4, ..., 10, 10, 10, 10}
//                             // O(N) * N = O(N*N)
//        // search for all the elements equal to val and remove them.
//        while(remove(val) > 0);
//    }
    void removeAll(Character val) { // O(N)
        int j = 0;
        for(int i=0;i<numElements;i++)
            if(chars[i] != val)
                chars[j++] = chars[i];
        numElements = j;
    }
    Character findMin() {
        // return the minimum value among elements in nums;
        Character minV = chars[0];
        for(int i=1;i<numElements;i++)
            if( chars[i] < minV )
                minV = chars[i];
        return minV;
    }
    void sort() { 
        for(int i=0;i<numElements-1;i++) {
            for(int j=i+1;j<numElements;j++) 
            {
                if( chars[j]  < chars[i]) {
                     char temp = chars[i];
                     chars[i]=chars[j];
                     chars[j]=temp;
                }
            }
        }
    }
    Character[] toArray() {
        // return a copy of the array only with valid elements
        //return nums; // this is not a right to return a copy.
        Character[] new_nums = new Character[numElements];
        for(int i=0;i<numElements;i++)
            new_nums[i] = chars[i];
        return new_nums;
    }
    public MyArrayForChar clone(){
        // return a copy of this instance/object
        MyArrayForChar nums1 = new MyArrayForChar(this.toArray());
        return nums1;
    }
    public void clear() {
        numElements = 0;
    }

    public Character[] getElements(int start, int end) {
        Character[] new_nums = new Character[end-start+1];
        for(int i= start; i <= end ; i++)
            new_nums[i-start] = chars[i];
        return new_nums;
    }
    boolean isEmpty() { return numElements == 0; }
    boolean isFull() { return numElements==chars.length; }


}

3.

public class MyArrayForString {


    String[] strings;
    int numElements;
    public MyArrayForString() { 
        // Constructor. automatically called when creating an instance
        numElements = 0;
        strings = new String[5];
    }
    public MyArrayForString(int capacity) { 
        // Constructor. automatically called when creating an instance
        numElements = 0;
        strings = new String[capacity];
    }
    public MyArrayForString(String[] nums1) {
        strings = new String[nums1.length];
        for(int i=0;i<nums1.length;i++)
            strings[i] = nums1[i];
        numElements = nums1.length;
    }
    void printArray(){        // cost, times
        System.out.printf("printArray(%d,%d): ",numElements,strings.length);
        for(int i=0; i<numElements;i++)        
            System.out.print(strings[i]+" ");    
        System.out.println();                    
    }    
    int linearSearch(String val) {
        for(int i=0;i<numElements;i++)        
            if(strings[i].equals(val))                
                return i;                    
        return -1;                                            
    }
    int binarySearch(String val) {
        sort();
        int start = 0;                    
        int end = strings.length - 1;        
        int mid;                        
        while(start <= end) {             
            mid = (start + end)/2;    
            int result = val.compareTo(strings[mid]); 
             if (result == 0) 
                    return mid; 
             if (result > 0) 
                    start = mid + 1;
             else
                    end = mid - 1; 
                
        }
        return -1;                                                            
    }
    
    private void enlarge() {
        // String up the size of nums;
        String[] new_nums = new String[strings.length*2];
        for(int i=0;i<numElements;i++)
            new_nums[i] = strings[i];
        strings = new_nums;
    }
    void add(String val) {
        if(isFull())     // if(numElements == nums.length)
            enlarge();
        strings[numElements] = val;
        numElements++;
    }
    public void addOrder(int idx, String[] valArray) {
        // add all elements of valArray from the specified position of nums.
        // need to keep order
        // eg) [10,20,30] --> addOrder(1,{1,2}) makes {10,1,2,20,30}
        ensureCapacity(numElements + valArray.length);
        // Here we can safely assume 'nums' has at least 'numElements + valArray.length' spaces
        for(int i=numElements-1; i>=idx ; i--)
            strings[i+valArray.length] = strings[i];
        
        for(int i=0;i<valArray.length;i++)
            strings[i+idx] = valArray[i];
        numElements += valArray.length;
    }
    
    private void ensureCapacity(int count) {
        if(count <= strings.length)
            return;
        // need more space
        String[] new_nums = new String[count];
        for(int i=0;i<numElements;i++)
            new_nums[i] = strings[i];
        strings = new_nums;
    }
    int remove(String val){
        // search for an element that is equal to val. and remove it from 'nums'
        int idx = linearSearch(val);
        if(idx < 0)
            return 0;
        // fill the location with the last element
        strings[idx] = strings[numElements-1];
        numElements--;
        return 1;
    }
//    void removeAll(int val) { // worst-case: latter half elements are equal to val
//                             // remove(10) in nums = {1, 2, 3, 2, 4, ..., 10, 10, 10, 10}
//                             // O(N) * N = O(N*N)
//        // search for all the elements equal to val and remove them.
//        while(remove(val) > 0);
//    }
    void removeAll(String val) { // O(N)
        int j = 0;
        for(int i=0;i<numElements;i++)
            if(strings[i] != val)
                strings[j++] = strings[i];
        numElements = j;
    }
    String findMin() {
        // return the minimum value among elements in nums;
        String minV = strings[0];
        for(int i=1;i<numElements;i++)
            if( strings[i].compareTo(minV)>0 )
                minV = strings[i];
        return minV;
    }
    void sort() { 
        for(int i=0;i<numElements-1;i++) {
            for(int j=i+1;j<numElements;j++) {
                if(strings[i].compareTo(strings[j])>0)   
                {  
                //swapping array elements  
                String temp = strings[i];  
                strings[i] = strings[j];  
                strings[j] = temp;  
                }  
            }
        }
    }
    String[] toArray() {
        // return a copy of the array only with valid elements
        //return nums; // this is not a right to return a copy.
        String[] new_nums = new String[numElements];
        for(int i=0;i<numElements;i++)
            new_nums[i] = strings[i];
        return new_nums;
    }
    public MyArrayForString clone(){
        // return a copy of this instance/object
        MyArrayForString nums1 = new MyArrayForString(this.toArray());
        return nums1;
    }
    public void clear() {
        numElements = 0;
    }

    public String[] getElements(int start, int end) {
        String[] new_nums = new String[end-start+1];
        for(int i= start; i <= end ; i++)
            new_nums[i-start] = strings[i];
        return new_nums;
    }
    boolean isEmpty() { return numElements == 0; }
    boolean isFull() { return numElements==strings.length; }


}


4.

public class MyArrayDemo {
        static void printArray(int[] nums) {
                for (int i = 0; i < nums.length; i++)
                        System.out.print(nums[i] + " ");
                System.out.println();
        }

        public static void main(String[] args) {

                MyArrayForDouble mynums1 = new MyArrayForDouble();
                mynums1.add(10.5);
                mynums1.add(1.9);
                mynums1.add(-0.2);
                mynums1.add(10.5);
                mynums1.printArray();
                System.out.println(mynums1.linearSearch(1.9));
                mynums1.remove(1.9);
                mynums1.printArray();
                mynums1.removeAll(10.5);
                mynums1.printArray();

                
                MyArrayForChar mynums2 = new MyArrayForChar();
                mynums2.add('c');
                mynums2.add('a');
                mynums2.add('b');
                mynums2.add('d');
                mynums2.printArray();
                System.out.println(mynums2.linearSearch('d'));
                mynums2.sort();
                mynums2.printArray();
                mynums2.remove('d');
                mynums2.printArray();
                mynums2.removeAll('a');
                mynums2.printArray();
                
                MyArrayForString mynums3 = new MyArrayForString();
                mynums3.add("abc");
                mynums3.add("sdsaa");
                mynums3.add("sadb");
                mynums3.add("cvc");
                mynums3.printArray();
                System.out.println(mynums3.linearSearch("cvc"));
                mynums3.sort();
                mynums3.printArray();
        
                 
        }
}

Related Solutions

Create MyArrayForString.java to handle 'String' type elements and create MyArrayForChar.java to handle 'char' type elements. Test...
Create MyArrayForString.java to handle 'String' type elements and create MyArrayForChar.java to handle 'char' type elements. Test them in MyArrayDemo.java. I need this in java on textpad. There are two files, both have instructions in them on what to add in the code. They are posted below. public class MyArrayForDouble { double[] nums; int numElements; public MyArrayForDouble() { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[5]; } public MyArrayForDouble(int capacity) { // Constructor. automatically...
convert this string type   program into interger data type #include "stdafx.h" #include #include unsigned int putIntoHashTable(char...
convert this string type   program into interger data type #include "stdafx.h" #include #include unsigned int putIntoHashTable(char *ptrInputData, unsigned int bufferLength); // function to add to hash table unsigned int getFromHashTable(char *ptrOutputData, unsigned int bufferLength); // function to retrieve data from hash table #define INPUT_BUFFER_SIZE 200 // local buffer used for adding data to the hash table (there is no reason in this assignment to change this value) #define HASH_SIZE 100 // size of hash table to be used (for testing...
CREATE TABLE Hotel ( roomNumber     INTEGER         PRIMARY KEY, type                  CHAR(1
CREATE TABLE Hotel ( roomNumber     INTEGER         PRIMARY KEY, type                  CHAR(10)         NOT NULL, rate                   INTEGER         NOT NULL, -- CONSTRAINT IC1 CHECK (type IN ('suite', 'king', 'queen')), CONSTRAINT IC2 CHECK (type <> 'suite' OR rate > 200), CONSTRAINT IC3 CHECK (NOT (type = 'king' AND (rate < 80 OR rate > 220))), CONSTRAINT IC4 CHECK (NOT (type = 'queen' AND rate >= 100)) ); which 8 of these inserts will be rejected only 8 are rejected 1. INSERT INTO Hotel VALUES (21, 'king', 90); 2. INSERT INTO Hotel...
Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string...
Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string */ if (c == 0) return s; /* convert the first character to upper case*/ if (c >= ‘a’ && d <= ‘z’) { c -= 32; s[0] = c; } /* convert the remaining characters*/ strtoupper(s + 1); return s; }
Create a class called FileSumWrapper with a method that has the signature public static void handle(String...
Create a class called FileSumWrapper with a method that has the signature public static void handle(String filename, int lowerBound). Make this method call FileSum.read and make your method catch all the errors. FileSum.read is a method that takes a filename and a lower bound, then sums up all the numbers in that file that are equal to or above the given lower bound. I'm unsure at how to incorporate the FileSum.read() method to even start anything. I also don't know...
Binomial Hypothesis Test. While this method is limited in the type of data it can handle...
Binomial Hypothesis Test. While this method is limited in the type of data it can handle (binary - "success/failure" outcomes), it is powerful in providing figures of authority with scientific information off of which to base important decisions. There is a limitation to using this method and, statistically, this notion refers to the "power" of a test. First, let's suppose that you are a disease outbreak coordinator for the Center for Disease Control and Prevention. A recent flu outbreak has...
import java.util.Scanner; public class test {    public static void main(String args[]){        char letter;...
import java.util.Scanner; public class test {    public static void main(String args[]){        char letter;        int number = 0;        Scanner in = new Scanner(System.in);        System.out.print("Enter a letter: ");        letter = in.next().charAt(0);        if(letter == 'A' || letter == 'B' || letter == 'C') number = 2;        if(letter == 'D' || letter == 'E' || letter == 'F') number = 3;        if(letter == 'G' || letter ==...
I am trying to tokenize a string using a function by passing the char string[] and...
I am trying to tokenize a string using a function by passing the char string[] and char *pointer[100]. While I have working code inside the int main(), I am having trouble actually declaring the parameters for the function. I know how to pass the char array (char string[]), but not how to pass the char pointer array (char *pointer[100]). This is my code below: int main() {    // Declare variables    char str[] = "this is a test only...
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary...
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary string and iteratively constructs a decimal value (val) and width of each binary pattern (separated by spaces), until a space or a null character ('\0') is encountered in the string. Once a space or a null character is found, this function should call the assembly code (decode_morse()) to obtain the corresponding ASCII value, for the current val and width, and place the ASCII value...
1a. char days[SIZE]; Create a C-String which uses days to store "Monday". 1b.To use things like...
1a. char days[SIZE]; Create a C-String which uses days to store "Monday". 1b.To use things like cout and cin you must use this line of code: 1c. Automatic conversion of an operand to another data type is known as: 1d. To use a string you must use this preprocessor directive: 1e. There are four types of data type modifiers for numerical data, provide one of them. 1f. char ch = 'A'; How would you type cast this to a double...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT