Questions
Python 1. Change the order of an input string based on Unicode equivalent. Write a function...

Python

1. Change the order of an input string based on Unicode equivalent.

Write a function Reorder that will take an input string of a maximum length of 20 characters and create a new string that reorders the string based on it’s binary Unicode character equivalent, e.g. ‘a’ = 0x61, ‘A’ = 0x41, from smallest value to largest value. In this example, ‘A’ would come before ‘a’, as 0x41 is a smaller number than ox61. Note, use python logical operators to do the comparison. Do not try to create a Unicode lookup table. For your code, use the string “sum=(x*259)/average” as your input string to your function.

In: Computer Science

Show the values contained in the instance variables elements and numElements of the sample collection after...

Show the values contained in the instance variables elements and numElements of the sample collection after the following sequence of operations:

ArrayCollection<String> sample = new ArrayCollection<String>; sample.add("A"); sample.add("B"); sample.add("C"); sample.add("D"); sample.remove("B");

//---------------------------------------------------------------------------
// ArrayCollection.java by Dale/Joyce/Weems Chapter 5
//
// Implements the CollectionInterface using an array.
//
// Null elements are not allowed. Duplicate elements are allowed.
//
// Two constructors are provided: one that creates a collection of a default
// capacity, and one that allows the calling program to specify the capacity.
//---------------------------------------------------------------------------
package ch05.collections;

public class ArrayCollection<T> implements CollectionInterface<T>
{
protected final int DEFCAP = 100; // default capacity
protected T[] elements; // array to hold collection’s elements
protected int numElements = 0; // number of elements in this collection

// set by find method
protected boolean found; // true if target found, otherwise false
protected int location; // indicates location of target if found

public ArrayCollection()
{
elements = (T[]) new Object[DEFCAP];
}

public ArrayCollection(int capacity)
{
elements = (T[]) new Object[capacity];
}

protected void find(T target)
// Searches elements for an occurrence of an element e such that
// e.equals(target). If successful, sets instance variables
// found to true and location to the array index of e. If
// not successful, sets found to false.
{
location = 0;
found = false;

while (location < numElements)
{
if (elements[location].equals(target))
{
found = true;
return;
}
else
location++;
}
}

public boolean add(T element)
// Attempts to add element to this collection.
// Returns true if successful, false otherwise.
{
if (isFull())
return false;
else
{
elements[numElements] = element;
numElements++;
return true;
}
}

public boolean remove (T target)
// Removes an element e from this collection such that e.equals(target)
// and returns true; if no such element exists, returns false.
{
find(target);
if (found)
{
elements[location] = elements[numElements - 1];
elements[numElements - 1] = null;
numElements--;
}
return found;
}
  
public boolean contains (T target)
// Returns true if this collection contains an element e such that
// e.equals(target); otherwise, returns false.
{
find(target);
return found;
}

public T get(T target)
// Returns an element e from this collection such that e.equals(target);
// if no such element exists, returns null.
{
find(target);
if (found)
return elements[location];
else
return null;
}
  
public boolean isFull()
// Returns true if this collection is full; otherwise, returns false.
{
return (numElements == elements.length);
}

public boolean isEmpty()
// Returns true if this collection is empty; otherwise, returns false.
{
return (numElements == 0);
}

public int size()
// Returns the number of elements in this collection.
{
return numElements;
}
}

In: Computer Science

Draw a landscape image using python coding.

Draw a landscape image using python coding.

In: Computer Science

USE JAVA Write a static generic method PairUtil.minmax that computes the minimum and maximum elements of...

USE JAVA

Write a static generic method PairUtil.minmax that computes the minimum and maximum elements of an array of type T and returns a pair containing the minimum and maximum value. Require that the array elements implement the Measurable interface of Chapter 10.

In: Computer Science

reate a class Song with the data members listed below: title: string the name of the...

reate a class Song with the data members listed below:

  • title: string the name of the song. (initialize to empty string)
  • artist: string the name of the artist. (initialize to the empty string)
  • downloads: int the number of times the song has been downloaded. (initialize to 0)

Include the following member functions:

  • default constructor,
  • a constructor with parameters for each data member (in the order given above),
  • getters and setter methods for each data member named in camel-case.  For example, if a class had a data member named myData, the class would require methods named in camel-case: getMyData and setMyData.
  • double grossRevenue(double price): This function should take in a price per download and returns the total revenue for the song (revenue = price * downloads).

You only need to write the class definition and any code that is required for that class (i.e., header and implementation).

NOTE: you must not use the implicit "private" for class data types and methods. Include public or private explicitly.

In: Computer Science

In C++, create two vectors, one a vector of ints and one a vector of strings....

In C++, create two vectors, one a vector of ints and one a vector of strings. The user will fill each one with data, and then your program will display the values.

  1. Copy the template file /home/cs165new/check10a.cpp to your working directory.
  2. For this assignment, in order to focus our practice on the syntax of the vectors, you can put all of your code in main.
  3. Create and display a vector of ints as follows:
    1. Create a vector of ints.
    2. Prompt the user for ints until they enter 0, and store them in your vector.
    3. Loop through all the numbers in the vector and display each one.
    4. When you loop through, make sure to use the size of your vector in your condition (not a separate integer from above).
  4. Create and display a vector of strings as follows:
    1. Create a vector of strings.
    2. Prompt the user for strings until they enter "quit", and store them in your vector.
    3. Loop through all the strings in the vector and display each one.
    4. When you loop through, make sure to use the size of your vector in your condition (not a separate integer from above).
  5. You do not have to use iterators for this assignment (but you are welcome to if you would like). It can be done using the [] operator.

Sample Output

The following is an example of output for this program:

Enter int: 3

Enter int: 12

Enter int: 4

Enter int: 0

Your list is:

3

12

4

Enter string: The

Enter string: quick

Enter string: brown

Enter string: fox

Enter string: jumps

Enter string: over

Enter string: the

Enter string: lazy

Enter string: dog

Enter string: quit

Your list is:

The

quick

brown

fox

jumps

over

the

lazy

dog

In: Computer Science

Can I get detailed explanation about the following topics Keyword Queries Boolean Queries Phrase Queries Proximity...

Can I get detailed explanation about the following topics

Keyword Queries

Boolean Queries

Phrase Queries

Proximity Queries

Natural Language Queries

Wildcard Queries

Rather than the solution for Chapter 27, proplem 18RQ in Fundamentals of database system (6th Edition) and also provide me with examples

Regards

In: Computer Science

using java. using eclipse. write a program that asks to enter 3 real numbers using GUI....

using java. using eclipse. write a program that asks to enter 3 real numbers using GUI. print the sum if all 3 numbers are positive, print the product of the 2 positive numbers if one is negative, use one nested if statement. all output should be to dialog and the console. ...... So i have most of this program done, i just cant figure out how to get the product of the 2 positve numbers to print to the console and dialog. Here is what I have so far.... i know the if and else if statements are correct, i just dont know how to get the if and else if to print to console and dialog correctly for the product.

import java.util.Scanner;
import javax.swing.JOptionPane;
public class Project3 {
public static float getFloat(){
  String s = JOptionPane.showInputDialog("Enter a real number");
  return Float.parseFloat(s);
}

public static void main(String[] args) {
  float x = getFloat();
  float y = getFloat();
  float z = getFloat();
  // if all three are positive print the sum
  if(x>0 && y>0 && z>0) System.out.printf("Sum:%8.2f\n", (x+y+z));
  //if two of the three are positive print the product
  else if((x>0 && y>0 && z<0)||(x>0 && y<0 && z>0)||(x<0 && y>0 && z>0));
  System.out.printf("Product:%8.2f",((x*y)||(x*z)||(y*z)));
  
  
  JOptionPane.showMessageDialog(null, "Sum:"+(x+y+z)+"\nProduct:"+((x*y)||(x*z)||(y*z)));
  
  
  Scanner scan=new Scanner(System.in);
  System.out.println("\nEnter 2 real numbers");
  // if both are negative print the quotient
  float a = scan.nextFloat();
  float b = scan.nextFloat();
  if(a<0 && b<0) System.out.printf("Quotient:%8.2f", (a/b));
  JOptionPane.showMessageDialog(null, "Quotient:"+(a/b));
  
  
  System.exit(0);
}

}

In: Computer Science

*I JUST WANT A GENERAL WALKTHROUGH OF HOW TO DO THIS. PSEUDOCODE IS FINE. THANK-YOU. THIS...

*I JUST WANT A GENERAL WALKTHROUGH OF HOW TO DO THIS. PSEUDOCODE IS FINE. THANK-YOU. THIS IS IN C THE PROGRAMMING LANGUAGE.*

The program will require the following structure:

struct _data {                                 

   char *name;

   long number;

};

The program will require command line arguments:

int main(int argv, char **argc) {

       

Where argv is the number of arguments and argc is an array

holding the arguments (each is a string). Your program must catch

any case where no command line arguement was provided and print

a warning message (see below).

You MUST include/use the following functions, defined as follows:

int SCAN(FILE *(*stream)) - this function will open the file/stream

and return an integer indicating how many lines there are. Note that

I need to pass stream, which is a pointer, by reference. So I am

passing this as a pointer to a pointer.

struct _data *LOAD(FILE *stream, int size) - this function will

rewind file, create the dynamic array (of size), and read in the

data, populating the _data struct dynamic array. Note that stream

is passed by value this time. The function then returns the populated

array of struct.

void SEARCH(struct _data *BlackBox, char *name, int size) - this function

will get the dynamic array of struct passed to it, the name we are looking

for, and the size of the array. This function will then search the dynamic

array for the name. See below for examples.

void FREE(struct _data *BlackBox, int size) - this function will free up

all of the dynamic memory we allocated. Take note of the number of times

malloc/calloc were called, as you need to free that same number.

Finally, the data file will be called hw5.data and will be formatted as:

ron 7774013

jon 7774014

tom 7774015

won 7774016

HINTS:

------

Functions that will make things much easier:

getline()

feof()

strtok()

atoi()

SAMPLE RUNS:

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

Case 1 - No command line argument provided.

[yourname@chef junk]$ ./CS230-5

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

* You must include a name to search for. *

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

Case 2 - Provided name is NOT in the list.

[yourname@chef junk]$ ./CS230-5 joe

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

The name was NOT found.

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

Case 3 - Provided name is in the list.

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

The name was found at the 2 entry.

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

In: Computer Science

Express the following bit patterns in hexadecimal. 01000101011001110100010101100111 10001001101010111000100110101011 11111110110111001111111011011100 00000010010100100000001001010010

Express the following bit patterns in hexadecimal.

  1. 01000101011001110100010101100111

  2. 10001001101010111000100110101011

  3. 11111110110111001111111011011100

  4. 00000010010100100000001001010010

In: Computer Science

Python Questions Suppose we run the Python program my_program.py from command line like this: Python my_program.py...

Python Questions

Suppose we run the Python program my_program.py from command line like this:

Python my_program.py 14 CSC121

Which of the following statement in my_program.py will display CSC121?

A.
import sys
print(sys.argv)
B.
 
 
 
import sys
print(sys.argv[0])
C.
 
 
import sys
print(sys.argv[1])
 
 
D.
import sys
print(sys.argv[2])
  1. from datetime import datetime
    dob = datetime(2015, 1, 1)
     

    Which of the following statements will change year to 2018?

    A.
    dob.year=2018
    B.
     
     
     
    dob.replace(year=2018)
    C.
     
     
    dob = dob.replace(year=2018)
     
     
    D.
    dob.set_year(2018)

10 points   

QUESTION 4

  1. from datetime import datetime
    dob = datetime(2011,12,10)
    today = datetime.now()
    age = today - dob

    What is the type of age?

    A.

    int

    B.

    float

    C.

    datetime

    D.

    timedelta

    Which of the following functions returns integers between 0 and 20 that are divisible by both 2 and 3?

    A.
    def divisible_2_3 ():
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                yield i
    B.
     
     
     
    def divisible_2_3 ():
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                return i
    C.
     
     
    def divisible_2_3 ():
        seq = []
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                yield seq
     
     
    D.
    def divisible_2_3 ():
        seq = []
        for i in range(20):
            if i % 2 == 0 and i % 3 == 0:
                return i

In: Computer Science

Q:Write a Java application which allows the user to enter student information The user will enter...

Q:Write a Java application which allows the user to enter student information

The user will enter full name, address, city, province, postal code, phone number and email in text field controls. The student’s major (Computer Science or Business) will be selected from two radio buttons.
A combo box will display the list of courses for each program whenever the user selects the desired program.
A course will be added to a list box whenever the user selects a course from the corresponding combo box. Make sure that the user cannot add a course several times.
Additional information about the student will be provided from a group of check boxes (such as involvement in various activities, etc).
All the information about the student will be displayed in a text area component. Use simple SWING layout managers, such as FlowLayout, BorderLayout, and GridLayout to create the SWING GUI of this application. Provide the titles for the data that will be displayed in the text area.

Note:I know how to do most of the things from question but i do not know how to implement layouts.

In: Computer Science

Write a program that will guess an integer that the user has picked. Imagine that the...

Write a program that will guess an integer that the user has picked. Imagine that the user will write down a positive integer x on a piece of paper and your program will repeatedly ask questions in order to guess what x is, and the user replies honestly. Your program will start by asking for an int n, and you must have 1 ≤ x ≤ n. After that, the program will successively guess what x is, and the user must tell the computer if x is equal to the guess (entering ’e’), larger than the guess (entering ’l’), or smaller than the guess (entering ’s’). Your program will guess by maintaining a lower bound (initially 1) and upper bound (initially n) and pick the largest integer equal to or smaller than1 the midpoint of the lower bound and upper bound. If the user responds with ’l’ indicating that x is larger, the guess becomes the new lower bound plus one. If the user responds with ’s’ indicating that x is smaller, the guess becomes the new upper bound minus one. If the user responds with ’e’ indicating that x is the guess, your program will report the number of guesses made and terminate execution:

Example 1)

Enter n: 50

Is your number 25? l

Is your number 38?

l Is your number 44? s

Is your number 41? e

Your number must be 41. I used 4 guesses.

Example 2)

Enter n: 9

Is your number 5? s

Is your number 2?

l Is your number 3? s

Error: that’s not possible.

Example 3)

Enter n: -2

Error: n must be positive.

Example 4)

Enter n: 9

Is your number 5? m

Error: invalid input.

Example 5)

Enter n: a

Error: invalid input.

In: Computer Science

In the Python: Note 1: You may not use these python built-in functions: sorted(), min(), max(),...

In the Python:

Note 1: You may not use these python built-in functions:

sorted(), min(), max(), sum(), pow(), zip(), map(), append(), count() and counter().

(7 points) unique.py: A number in a list is unique if it appears only once. Given a list of

random numbers, print the unique numbers and their count. Print the duplicate numbers and

their count.

Sample runs:

Enter the size of the list : 7

[8, 2, 6, 5, 2, 4, 5]

There are 3 unique numbers: 8 6 4

There are 2 duplicate numbers: 2 5

Sample run:

Enter the size of the list : 7

[2, 2, 4, 3, 3, 3, 4]

There are 0 unique numbers:

There are 3 duplicate numbers: 2 3 4

In: Computer Science

Taking a test on "Inheritance" in C++ tomorrow. So far we have learned about classes, structs...

Taking a test on "Inheritance" in C++ tomorrow. So far we have learned about classes, structs and arrays and strings. We will be provided with coding prompts and have to hand write codes that show examples of inheritance (most likely including some of the earlier concepts as well).

I would like some code examples such as this to study and look over with comments please.

In: Computer Science