Questions
def box_sort(names, sizes): Given a list of strings names, a corresponding list of ints sizes, we...

def box_sort(names, sizes): Given a list of strings names, a corresponding list of ints sizes, we want to sort items by size so that each of our four sublists contains items in the smallest possible boxes of the following exact sizes: 2, 5, 25, and 50 units. Anything larger than 50 won't fit in a box and is simply ignored at this time. Create and return a list of the four sublists of items.

o Assume: names is a list of strings, and sizes is a list of ints.
o Restrictions: remember, you can't call any built-in sorting functions. It's not hard-coding to

directly calculate based on the four given sizes, but keeping a list of box sizes may actually simplify your code.
box_sort(['a','b','c','d'], [1,5,6,10]) → [['a'],['b'],['c','d'],[]] box_sort(['a','b','c'], [49,50,51]) → [[],[],[],['a','b']]

def packing_list(names, sizes, box_size): Given a list of names, a corresponding list of int sizes, and an int box_size, this time we want to keep packing items into boxes of the given box_size until it's full, and then start filling another box of the same size. We return a list of filled boxes as a list of lists of strings. Oversized items are immediately placed into our output in a list by themselves, with an asterisk prefix to indicate that it does not fit. (We continue filling the current box after an oversized item). Items are only considered in their given ordering; do not reorder the items to seek a better packing list! Create and return this list of lists, each one containing items in one box or the single oversized item.

o Assume: names is a list of strings, sizes is a list of ints, and box_size is an int. Order is preserved for all non-oversized items, and oversized items show up immediately before the box that was being filled at the time of consideration.

          # boxes of 2+1, 4, and 2.

packing_list(['a','b','c','d'], [2,1,4,2],5) → [['a','b'],['c'],['d']]

          # while packing our second box, we find oversized item b, then finish our box.

packing_list(['x','a','b','c'], [5,2,10,3], 5) → [['x'],['*b'],['a','c']]

In: Computer Science

C++ language You will create a Hangman class. Possible private member variables: int numOfCharacters; //for the...

C++ language

You will create a Hangman class.
Possible private member variables:
int numOfCharacters; //for the secret word
char * secretWord;
char *guessedWord;

public:

//please create related constructors, getters, setters,constructor()

constructor()

You will need to initialize all member variables including the two dynamic variables.

destructor()

Please deallocate/freeup(delete) the two dynamic arrays memories.

guessALetter(char letter)

1.the function will check if the letter guessed is included in the word.

2. display the guessed word with related field(s) filled if the letter guessed matches the some of the letters of the word

gameResult()

1. Display how many times guessed so far

2. Display how many times with the wrong letter guessed3. Display "you win" if all letters are filled in the guess word4. Display "you lost" if the times of guessing the wrong letter reaches 6 (Note: 6 body parts - head, body, left arm, right arm, left leg, right leg)


main()

Instantiate an object of Hangman.Ask the host: how many letters in the guess word.

Ask the host: what is the guess word?

Design a loop for the player to play the guess game

1. The loop should exit if the number of wrong guess reaches 6

2. inside the loop, there should be a condition to allow the player to exit, say "Do you want to continue playing (y|n)?". If the user chooses 'n', exit the loop.

3. Inside the loop, you may do some function chaining calls, something like:

obj.guessALetter(guessLetter).gameResult()

In: Computer Science

Program in Java Write an algorithm to transfer the elements from queue Q1 to queue Q2,...

Program in Java

Write an algorithm to transfer the elements from queue Q1 to queue Q2, so that the contents in Q2 will be in reverse order as they are in Q1 (e.g. if your queue Q1 has elements A, B, and C from front to rear, your queue Q2 should have C, B, and A from front to rear). Your algorithm must explicitly use an additional stack to solve the problem. Write your algorithm in pseudo code first, and make sure to share it.

You may want to implement your own stack and queue for practice purpose although you are allowed to use the library if you want to. However, you can only use the basic methods such as push and pop for stack, enqueue and dequeue for queues.

In: Computer Science

Objective: Manipulate the Linked List Pointer. Write a java subclass to extend LList.java. Provide a reverse...

Objective: Manipulate the Linked List Pointer.

  1. Write a java subclass to extend LList.java. Provide a reverse list method in the subclass to reverse the order of the linked list.
  2. Print the original linked list and the reverse ordered linked list at the end of program.
  3. You can use the gamescore.txt to test the reverse method.

_____________________________________________________________________________________________________________________________________________________

/** Source code example for "A Practical Introduction to Data

    Structures and Algorithm Analysis, 3rd Edition (Java)"

    by Clifford A. Shaffer

    Copyright 2008-2011 by Clifford A. Shaffer

*/

/** List ADT */

public interface List {

  /** Remove all contents from the list, so it is once again

      empty. Client is responsible for reclaiming storage

      used by the list elements. */

  public void clear();

  /** Insert an element at the current location. The client

      must ensure that the list's capacity is not exceeded.   

      @param item The element to be inserted. */

  public void insert(E item);

  /** Append an element at the end of the list. The client

      must ensure that the list's capacity is not exceeded.   

      @param item The element to be appended. */

  public void append(E item);

  /** Remove and return the current element.

      @return The element that was removed. */

  public E remove();

  /** Set the current position to the start of the list */

  public void moveToStart();

  /** Set the current position to the end of the list */

  public void moveToEnd();

  /** Move the current position one step left. No change

      if already at beginning. */

  public void prev();

  /** Move the current position one step right. No change

      if already at end. */

  public void next();

  /** @return The number of elements in the list. */

  public int length();

  /** @return The position of the current element. */

  public int currPos();

  /** Set current position.

      @param pos The position to make current. */

  public void moveToPos(int pos);

  /** @return The current element. */

  public E getValue();

}

/** Source code example for "A Practical Introduction to Data

    Structures and Algorithm Analysis, 3rd Edition (Java)"

    by Clifford A. Shaffer

    Copyright 2008-2011 by Clifford A. Shaffer

*/

// Doubly linked list implementation

class LList implements List {

protected DLink head;        // Pointer to list header

protected DLink tail;        // Pointer to last element in list

protected DLink curr;      // Pointer ahead of current element

int cnt;          // Size of list

//Constructors

LList(int size) { this(); }  // Ignore size

LList() {

  curr = head = new DLink(null, null); // Create header node

  tail = new DLink(head, null);

  head.setNext(tail);

  cnt = 0;

}

public void clear() {         // Remove all elements from list

  head.setNext(null);         // Drop access to rest of links

  curr = head = new DLink(null, null); // Create header node

  tail = new DLink(head, null);

  head.setNext(tail);

  cnt = 0;

}

public void moveToStart()  // Set curr at list start

{ curr = head; }

public void moveToEnd()  // Set curr at list end

{ curr = tail.prev(); }

/** Insert "it" at current position */

public void insert(E it) {

  curr.setNext(new DLink(it, curr, curr.next()));  

  curr.next().next().setPrev(curr.next());

  cnt++;

}

/** Append "it" to list */

public void append(E it) {

  tail.setPrev(new DLink(it, tail.prev(), tail));

  tail.prev().prev().setNext(tail.prev());

  cnt++;

}

/** Remove and return current element */

public E remove() {

  if (curr.next() == tail) return null; // Nothing to remove

  E it = curr.next().element();      // Remember value

  curr.next().next().setPrev(curr);

  curr.setNext(curr.next().next());  // Remove from list

  cnt--;           // Decrement the count

  return it;                         // Return value removed

}

/** Move curr one step left; no change if at front */

public void prev() {

  if (curr != head)   // Can't back up from list head

    curr = curr.prev();

}

// Move curr one step right; no change if at end

public void next()

  { if (curr != tail.prev()) curr = curr.next(); }

public int length() { return cnt; }

// Return the position of the current element

public int currPos() {

  DLink temp = head;

  int i;

  for (i=0; curr != temp; i++)

    temp = temp.next();

  return i;

}

// Move down list to "pos" position

public void moveToPos(int pos) {

  assert (pos>=0) && (pos<=cnt) : "Position out of range";

  curr = head;

  for(int i=0; i

}

public E getValue() {   // Return current element

  if (curr.next() == tail) return null;

  return curr.next().element();

}

// Extra stuff not printed in the book.

  /**

   * Generate a human-readable representation of this list's contents

   * that looks something like this: < 1 2 3 | 4 5 6 >.  The vertical

   * bar represents the current location of the fence.  This method

   * uses toString() on the individual elements.

   * @return The string representation of this list

   */

  public String toString()

  {

    // Save the current position of the list

    int oldPos = currPos();

    int length = length();

    StringBuffer out = new StringBuffer((length() + 1) * 4);

    moveToStart();

    out.append("< ");

    for (int i = 0; i < oldPos; i++) {

      out.append(getValue());

      out.append(" ");

      next();

    }

    out.append("| ");

    for (int i = oldPos; i < length; i++) {

      out.append(getValue());

      out.append(" ");

      next();

    }

    out.append(">");

    moveToPos(oldPos); // Reset the fence to its original position

    return out.toString();

  }

}

/** Source code example for "A Practical Introduction to Data

    Structures and Algorithm Analysis, 3rd Edition (Java)"

    by Clifford A. Shaffer

    Copyright 2008-2011 by Clifford A. Shaffer

*/

/** Doubly linked list node */

class DLink {

  private E element;         // Value for this node

  private DLink next;     // Pointer to next node in list

  private DLink prev;     // Pointer to previous node

  /** Constructors */

  DLink(E it, DLink p, DLink n)

  { element = it;  prev = p; next = n; }

  DLink(DLink p, DLink n) { prev = p; next = n; }

  /** Get and set methods for the data members */

  DLink next() { return next; }

  DLink setNext(DLink nextval)

    { return next = nextval; }

  DLink prev() { return prev; }

  DLink setPrev(DLink prevval)

    { return prev = prevval; }

  E element() { return element; }

  E setElement(E it) { return element = it; }

}

public class GameEntry {

protected String name;

protected int score;

public GameEntry(String n, int s) {

   name = n;

   score = s;

}

public String getName() {return name;}

public int getScore() {return score;}

public String toString() {

return "("+name+","+score+")";

}

}

//gamescore.txt

Mike,1105
Rob,750
Paul,720
Anna,660
Rose,590
Jack,510

In: Computer Science

1) How do you read the contents of a text file that contains whitespace characters as...

1) How do you read the contents of a text file that contains whitespace

characters

as part of its data?

2) What capability does the fstream data type provide that the ifstream

and ofstream

data types do not?

3) What header file do you need to include in a program that performs

file operations?

4) What data type do you use when you want to create a file stream object

that

can write data to a file?

5) What data type do you use when you want to create a file stream object

that

can read data from a file?

6) Why should a program close a file when it

s finished using it?

7) Write code that does the following:

(a) Opens an output file with the filename Numbers.txt ,

uses a loop to write the numbers 1 through 100 to the file,

and then closes the file.

(b) Opens the Numbers.txt file that was created in Part 7a,

reads all of the numbers from the file and

displays them in rows of 10 values, and then closes the file.

(c) Add all of the numbers read from the file and displays their

total.

In: Computer Science

The use of computers in education is referred to as computer-assisted instruction (CAI). More sophisticated CAI...

The use of computers in education is referred to as computer-assisted instruction (CAI). More sophisticated CAI systems monitor the student’s performance over a period of time. The decision to begin a new topic is often based on the student’s success with previous topics. Modify the following auxiliary program (Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use rand to produce two positive one-digit integers. It should then type a question such as: How much is 8 * 9? The student then types the answer. Your program checks the student’s answer. If it is correct, print “Very good!” and then ask another addition question. If the answer is wrong, print “No. Please try again.” and then let the student try the same question again repeatedly until the student finally gets it right. Terminate the program when the student has 5 right answers.) to count the number of correct and incorrect responses typed by the student. After the student types 5 answers, your program should calculate the percentage of correct responses. If the percentage is lower than 75 percent, your program should print “Please ask for extra help” and then terminate. If the percentage is 75 percent or higher, your program should print “Good work!” and then terminate.

I am programming student so please keep code simple enough that I can learn from it thanks

In: Computer Science

Create a program that will loop and prompt to enter the highlighted data items in the...

Create a program that will loop and prompt to enter the highlighted data items in the structure below. This is every item except customerNumber , isDeleted and newLine;


const int NAME_SIZE = 20;
const int STREET_SIZE = 30;
const int CITY_SIZE = 20;
const int STATE_CODE_SIZE = 3;

struct Customers {
    long customerNumber;
    char name[NAME_SIZE];
    char streetAddress_1[STREET_SIZE];
    char streetAddress_2[STREET_SIZE];
    char city[CITY_SIZE];
    char state[STATE_CODE_SIZE];
    int zipCode;

    char isDeleted;
    char newLine;
};

Always set the item isDeleted to 'N' and newline to '\n'. The item newLine is a convenient item that is there to assist in viewing the contents of the file using "type filename" the cmd window.

Notepad will show the binary chars and will not line up the data as expected. You may see some odd characters after the expected data for the character arrays. That is normal for C/C++.

The item customerNumber should start at 0 and increase by 1 for every record written.


Once the data in the structure is loaded, write it to the file "Customers.dat" and prompt to continue. If the reply is to not continue, close the file and exit.

The file "Customers.dat" must be opened in Binary mode.

1. Modify this program to open the file "Customers.dat" so that all data is written to the end of the file AND to allow the file to be read.

2. Create a method called "getLargestCustomerNumber" and call it after the "Customers.dat" file has been opened. Read all the existing customerNumbers and determine the largest customerNumber - do not assume the last record in the file is the largest number. Use this number as the base when adding new customer data.

3. Display the customer number calculated for the customer number that is receiving input.

4. The program needs to create the Customers.dat file if it does not exist.

5. The program should be able to start multiple times and add data with increasing customerNumbers. There should be no duplicated customer numbers.

In: Computer Science

1. public class MyString { private char[] data; MyString(String string) { data = string.toCharArray(); } public...

1.
public class MyString {
    private char[] data;

    MyString(String string) { data = string.toCharArray(); }
    public int compareTo(MyString other) { /* code from HW1 here */ }
    public char charAt(int i) { return data[i]; }
    public int length() { return data.length; }
    public int indexOf(char c) { /* code from HW1 here */ }
    public boolean equals(MyString other) { /* code from HW1 here */ }

    /*
    * Change this MyString by removing all occurrences of
    * the argument character c. For example, if MyString s
    * represents the text "radar", then s.remove('a') will
    * change s so that it now represents the text "rdr".
    */
    public void remove(char c) {
        /* Type in the box below the code that should go here. */
    }
}

public class ArrayIntSet {

private int[] data;

private int size;

public ArrayIntSet(int capacity) {

data = new int[capacity];

size = 0;

}

2.

public int size() { return size; }

public boolean contains(int i) { /* Code from HW3 here */ }

public boolean addElement(int element) { /* Code from HW3 here */ }

private int index(int element) { /* Code from HW3 here */ }

public boolean removeElement(int element) { /* Code from HW3 here */ }

public boolean equals(ArrayIntSet other) { /* Code from HW3 here */ }

public void union(ArrayIntSet other) { /* Code from HW3 here */ }

public void intersect(ArrayIntSet other) { /* Code from HW3 here */ }

/*

* Returns a new ArrayIntSet that contains

* all the even numbers from this set.

*/

public ArrayIntSet evenSubset() {

/* Write code for this method in the box below */

}

}

In: Computer Science

I don't know why my java code is not running this error code pops up -->...

I don't know why my java code is not running this error code pops up --> Error: Could not find or load main class DieRoll Caused by: java.lang.ClassNotFoundException: DieRoll.

Code below:

   import java.util.Random;

   import java.util.Scanner;

   public class Assignment {

   public static void combineStrings() {

   String school = "Harvard";

   String city = "Boston, MA";

   int stringLen;

  

   String upper, changeChar, combine;

  

   stringLen = school.length();

   System.out.println(school+" contains "+stringLen+" characters." );

  

   upper = school.toUpperCase();

   System.out.println(upper);

  

   changeChar = upper.replace("A", "*");

   combine = school +" "+city;

   System.out.println("The final string is "+combine );

   }

  

   public static void dieRoll()

   {

   Scanner scanner = new Scanner(System.in);

   Random random = new Random();

   int sides, n1, n2, n3;

  

   System.out.print("How many sides? ");

   sides = scanner.nextInt();

  

  

   n1 = random.nextInt(sides)+1;

   n2 = random.nextInt(sides)+1;

   n3 = random.nextInt(sides)+1;

  

   System.out.println("First Roll\t="+n1);

   System.out.println("Second Roll\t="+n2);

   System.out.println("Third Roll\t="+n3);

   System.out.println("Die Total\t="+(n1+n2+n3));

   System.out.println("Average Roll\t="+((n1+n2+n3)/3.0));

   }

  

  

   public static void candy()

   {

   int numCarton=0,candyBars;

   Scanner scanner = new Scanner(System.in);

  

   System.out.println("Enter the number of candy bars : ");

   candyBars = scanner.nextInt();

   do

   {

   numCarton++;

   candyBars = candyBars-24;

   }while(candyBars > 0);

  

   System.out.println("Number of Cartons needed = "+numCarton);

   }

  

public static void main(String[] args) {

  

   combineStrings();

   dieRoll();

   candy();

   }

}

In: Computer Science

Design the Class Diagram (UML) for a banking system with its clients’ accounts and an ATM...

Design the Class Diagram (UML) for a banking system with its clients’ accounts and an ATM machine. Each client account holds the user’s name (String of Full Name), account number (int) and balance (int). All client account details should be hidden from other classes but the system should provide tools/methods to access, change, and display (toString for account) each of these details.

The ATM machine holds the available money inside it (double) and the maximum money it can hold (double).

A user can request to withdraw, deposit or display balance through their account after checking the possibility of the action based on the ATM machine attributes. The balance display can be directly sent to the ATM. However, the withdraw request needs checking the user’s balance before checking the cash availability in the ATM machine. Also the deposit requires ensuring that the amount of cash will not exceed the maximum of the ATM.

For example, if the machine is full with cash then a user cannot deposit his money and a message should be displayed to the client that the machine is full and money cannot be deposited. In addition, if the machine has lower amount than what the withdraw request requires, the operation will be cancelled with an appropriate message on the standard output.

Use a default constructor (no formal parameters) and a full constructor (all class variables are initialized from formal parameters) for the client account.

object oriented programming "" Eclipse java"

In: Computer Science

Describe and give an example of the following: CyberTerrorism, Hacktivism, Black Hat Hacking, CyberCrime, CyberEspionage, CyberWar.

Describe and give an example of the following: CyberTerrorism, Hacktivism, Black Hat Hacking, CyberCrime, CyberEspionage, CyberWar.

In: Computer Science

Create a function output() in C that takes the pointer to the array and its size...

Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests.

(function prototype : void output(int *arrayPtr, int size);

In: Computer Science

in java Create the classes SubstitutionCipher and ShuffleCipher, as described below: 1. SubstitutionCipher implements the interfaces...

in java

Create the classes SubstitutionCipher and ShuffleCipher, as described below: 1. SubstitutionCipher implements the interfaces MessageEncoder and MessageDecoder. The constructor should have one parameter called shift. Define the method encode so that each letter is shifted by the value in shift. For example, if shift is 3, a will be replaced by d, b will be replaced by e, c will be replaced by f, and so on. (Hint: You may wish to define a private method that shifts a single character.)

In: Computer Science

Kitchen Gadgets sells a line of high-quality kitchen utensils and gadgets. When customers place orders on...

Kitchen Gadgets sells a line of high-quality kitchen utensils and gadgets. When customers place orders on the company’s Web site or through electronic data interchange (EDI), the system checks to see if the items are in stock, issues a status message to the customer, if they are in stock the customer will pay, the system will generate a shipping order to the warehouse, which fills the order. When the order is shipped, the customer is billed. The system also produces inventory reports to the accounting department. Complete the following tasks:

  1. Draw a context diagram for the order system.

  1. Draw a diagram 0 DFD for the order system.

In: Computer Science

Q5. [10] The left quotient of a regular language L1 with respect to L2 is defined...

Q5. [10] The left quotient of a regular language L1 with respect to L2 is defined as:
               L2/L1 = { y | x L2 , xy L1 }
Show that the family of regular languages is closed under the left quotient with a regular language.
Hint: Do NOT construct a DFA that accepts L2/L1 but use the definition of L2/L1 and the closure
properties of regular language.

In: Computer Science