Questions
Use c++language Use the pseudocode description below to write a program that uses an if, else...

Use c++language Use the pseudocode description below to write a program that uses an if, else if, else decision structure for a program that will determine if someone lives in Boston. 1. display message that describes what the program will do. 2. ask the user to input an answer to the question: Do you live in Boston?. 3. if they entered 'y', display a message confirming that they live in Boston. 4. if they entered 'n' , display a message confirming that they don't live in Boston. 5. if they entered an invalid entry, display a message telling them.

In: Computer Science

What is Industry 4.0 and how is it related to IoT?

What is Industry 4.0 and how is it related to IoT?

In: Computer Science

Using MARS and MIPS 2. Write and test a program to swap the contents of two...

Using MARS and MIPS

2. Write and test a program to swap the contents of two registers. Assume there is only one additional register available that may be destroyed.

Your program should initially read values (of type integer, float or string) into registers. Next, it will swap the values read, then print the final contents of each register

(you are not allowed to use "move").

In: Computer Science

The three major types of Backbone Networks are based on the devices used. In practice, it...

The three major types of Backbone Networks are
based on the devices used. In practice, it is most common to
use a combination of these architectures. In your opinion what
best practices do you recommend in the following?
(a) Architectures.
(b) Technologies.
(c) Implications for management

In: Computer Science

IN JAVA Rational Numbers Create a Rational number class in the same style as the Complex...

IN JAVA

Rational Numbers

Create a Rational number class in the same style as the Complex number class created in class. That is, implement the following methods:

  • constructor
  • add
  • sub
  • mul
  • div
  • toString

You must also provide a Main class and main method to fully test your Rational number class.

In: Computer Science

Java code for a binary tree that does the following:  Display a menu to the...

Java code for a binary tree that does the following:


 Display a menu to the user and request for the desired option.
 Based on the user’s input, request for additional information as follows:
o If the user wants to add a node, request for the name (or ID) of the new node to be added as
well as the name of the desired parent of that node.
 If the parent node already has two children, the new node cannot be added since this
is a binary tree (and each node can only have at most two children).
 Display an appropriate message to the user.
 Display the menu again for the user to make another choice.
 If the parent node already has one child, add the new node as the second child (right
child) of the parent node. Use recursion to traverse the tree to the parent node.
 Display the new tree with the new node added. This should be done using a
recursive method in your project ( method printTree() ).
 Display the menu.
 If the parent node has no children, use recursion to add the new node as the first child
(left child) of the parent node.
 Display the new tree with the new node added.
 Display the menu.

o If the user wants to know the size of the tree (i.e., the number of nodes in the whole tree or a

sub-tree), request for the name or ID of the node that is the root of the desired tree (or sub-
tree). The size of a tree or sub-tree is the number of its children and other ‘descendants’

(including any leaf nodes) plus one (the root node itself).
 Recursively count the number of nodes in the tree (or sub-tree) and display this with
an appropriate message.
 Display the tree (or subtree) whose size was just displayed.
 Display the menu.
o If the user wants to find a node, request for the name or ID of the node to search for in the
tree.
 Search for the node in the tree using recursive calls. If the node is found, display an
appropriate message; otherwise, indicate that the node does not exist in the tree.
 Display the menu.

o If the user wants to exit, terminate the program.
A sample output (to be followed exactly) is included below.


Example Output
A B C
B D E
D H I
H
I
E J K
J
K
C F G
F L
L
G
There are 12 nodes in this tree.
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->.3
Please enter an integer
k
Please enter an integer
6
Invalid input!
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->1
Please input the node you want to add->
M
Please input the parent node of M->
A
Parent already has 2 children.
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->1
Please input the node you want to add->
M
Please input the parent node of M->

F
Node successfully added!
A B C
B D E
D H I
H
I
E J K
J
K
C F G
F L M
L
M
G
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->2
Please input the root node->
A
There are 13 nodes in that tree
A B C
B D E
D H I
H
I
E J K
J
K
C F G
F L M
L
M
G
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->2
Please input the root node->
C
There are 5 nodes in that tree
C F G
F L M
L
M
G
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->3
Please input the node you want to find->

G
Node G found!
G
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->3
Please input the node you want to find->
U
Node U does not exist.
Please select one of the following options:
1. Add Node
2. Tree Size
3. Find Node
0. Exit
->0


Design Requirements
The main class (with the main method) in your application should be named BinaryTreeDemo. It is provided in
its entirety below and should not be changed.


public class BinaryTreeDemo {
public static void main(String[] args) {
Controller controller = new Controller();
controller.manipulateTree();
}
}


You should have another class – Controller – whose object is used to call methods to create the initial tree and
then manipulate it depending on the user’s selections from the menu. The constructor for the Controller class
does the following:
 instantiates an object of the TreeDataStructure class (this object is the root of the tree), and
 calls one of the Controller class methods: “createTree()” (given below).
public void createTree() {
root.addChild("B", "A");
root.addChild("C", "A");
root.addChild("D", "B");
root.addChild("E", "B");
root.addChild("F", "C");
root.addChild("G", "C");
root.addChild("H", "D");
root.addChild("I", "D");
root.addChild("J", "E");
root.addChild("K", "E");
root.addChild("L", "F");
root.printTree();
System.out.println("There are " + root.size() + " nodes in this

tree.\n");

}
The Controller class should also have a method (manipulateTree()) which contains the code to loop as long as
the user wants to, and perform the tasks desired by the user. The Controller class should also have a method to
display the menu to the user.


The TreeDataStructure class should implement the ITreeDataStructure interface (which is provided below).
Your TreeDataStructure class should have two constructors: one which accepts only one String parameter (used
to create the root node which has no parent) and a second one which accepts 2 parameters: a String (the ID of
the new node being created, and an ITreeDataStructure object (the parent of this new node). The methods
addChild(), find(), printTree(), and size() in the TreeDataStructure class must be implemented using recursion.


public interface ITreeDataStructure {
/**
* This method checks to see if a node with the parentID exists in the tree.
* If not, it returns false after printing an appropriate message. If the
* node exists, the method checks to see if it already has two children. If
* it does the method returns false. Otherwise, it either adds the new node
* as the parent node’s left child (if the parent has no children) or as the
* right child (if the parent already has one child). A recursive approach is
* used.
*
* @param ID The ID of the new node to be added to the tree.
* @param parentID The ID of the parent of the new node.
* @return true if new node was added successfully, false otherwise.
*/
public boolean addChild(String ID, String parentID);
/**
* This method looks within the tree to find if “value” (the ID of the node
* to be found) is contained in that subtree. As the search progresses down
* the tree different nodes will be calling find().
*
* @param value a string (ID of a node) to be found in the tree
* @return the node, if found.
*/
public ITreeDataStructure find(String value);
/**
* Returns the parent of this node.
*
* @return the parent of this node.
*/
public ITreeDataStructure getParent();
/**
* Returns the size of the tree.
*
* @return the size of the tree (or subtree) starting from this node
* all the way down to the leaf nodes.
*/

public int size();
/**
* Returns a string with the IDs of this node and its immediate children (if
* any) all on one line.
*
* @return a string with the IDs of this node and its immediate children (if
* any).
*/
public String toString();
/**
* Returns the ID of this node.
*
* @return the String ID of this node.
*/
public String getId();
/**
* Uses recursion (and the toString() method) to print (on a line) each
* node's ID and those of any children it has.
*/
public void printTree();
}

In: Computer Science

The impact of cyberbullying against teenagers and ways to prevent it

The impact of cyberbullying against teenagers and ways to prevent it

In: Computer Science

1. Theory. The most obvious way to represent a sequence of objects is simply to list...

1. Theory.

The most obvious way to represent a sequence of objects is simply to list them, one after the other, like this.

a  

a  

b  

b  

b  

c  

a  

a  

d  

d  

d  

d  

Note that the same objects often appear many times in a row. This is called a run of those objects. In the example sequence, there is a run of 2 a’s, a run of 3 b’s, a run of 1 c, a run of 2 a’s, and a run of 4 d’s. You can represent a sequence with runs by listing its objects, along with the number of times each object appears. For example, you can represent the sequence shown above like this.

a  

b  

c  

a  

d  

2

3

1

2

4

Representing a sequence in this way is called run-length encoding. If a sequence has long runs, or many runs, then run-length encoding will represent it more efficiently than simply listing its objects. However, if a sequence has short runs, or few runs, then run-length encoding may represent it less efficiently, because extra space is needed to store the lengths of the runs.
      Since a stack is just a simple kind of sequence, you can use run-length encoding to implement it. In this assignment, you will write a Java class called RunnyStack that implements a stack which uses run-length encoding. Here are some examples of how it works. Suppose you push an object a on an empty RunnyStack. Then the stack will look like this, with a run of 1 a.

a 1

Now suppose you push b. The stack now looks like this, with a run of 1 b, and a run of 1 a.

b 1

a 1

If you push another b on the RunnyStack, then the length of the run on top of the stack is incremented, so the stack looks like this.

b 2

a 1

If you push yet another b, then the length of the run at the top of the stack would increase to 3. However, suppose that you pop the RunnyStack instead. Then the length of the run at the top is decremented, so that the stack looks like this.

b 1

a 1

If you pop the RunnyStack one more time, then the length of the run on top of the stack is decremented to 0. However, a run of 0 objects is like no run at all, so it vanishes, and the stack looks as it did after the first push.

a 1

Stacks with run-length encoding are used internally by some compilers and interpreters, because they often push the same objects over and over again.

2. Implementation.

You must write a class called RunnyStack that represents a stack. Your class must implement run-length encoding, as described previously. It must also hold objects of type Base, so it will look like this.

class RunnyStack<Base>
{
  ⋮
}

Your class must define at least the following methods, as described below. To simplify grading, your methods must have the same names as the ones shown here.

  • public RunnyStack()

    Constructor. Make a new, empty instance of RunnyStack.

  • public int depth()

    Return the depth of the stack: the sum of the lengths of all the runs it holds. This is not necessarily the same as the number of runs it holds, which is returned by the method runs.

  • public boolean isEmpty()

    Test if the stack is empty.

  • public Base peek()

    If the stack is empty, then throw an IllegalStateException. Otherwise, return the Base at the top of the stack.

  • public void pop()

    If the stack is empty, then throw an IllegalStateException. Otherwise, decrement the length of the run on top of the stack. If this leaves a run of zero Base’s on top of the stack, then remove that run.

  • public void push(Base base)

    If the stack is empty, then add a new run of one Base at the top of the stack. If the stack is not empty, then test if base is equal to the object in the run at the top of the stack. If it is, then increment the length of that run. If it isn’t, then add a new run of one base at the top of the stack. Note that base may be null.

  • public int runs()

    Return the number of runs in the stack. This is not necessarily the same as its depth, which is returned by the method depth.

Here are some hints, requirements, and warnings. First, all these methods must work using O(1) operations, so they are not allowed to use loops or recursions. You will receive no points for this assignment if you use loops or recursions in any way!
      Second, your RunnyStack class must have a private nested class called Run. You must use instances of Run to implement your stack. Each instance of Run represents a run of Base’s. You will receive no points for this assignment if you use arrays in any way! The class Run must have three private slots that have the following names and types. The slot base points to the Base that appears in the run. The slot length is an int that is the length of the run. The slot next points to the instance of Run that is immediately below this one on the stack, or to null. It must also have a private constructor that initializes these slots.
      Third, your push method must test non-null Base’s for equality using their equals methods. It must use the Java ‘==’ operator only for testing null Base’s. It is helpful to define an extra private method called isEqual that takes two Base’s as arguments, and tests if they are equal. If either Base is null, then isEqual uses ‘==’. If neither Base is null, then isEqual uses equals.
      Fourth, RunnyStack’s methods are not allowed to print things. If you were writing RunnyStack in the Real World, then it might be part of some larger program. You don’t know if that larger program should print things.

In: Computer Science

BIG JAVA CH4: Understand the proper use of constants Question: What is the purpose of keyword...

BIG JAVA

CH4: Understand the proper use of constants

Question:

What is the purpose of keyword final? Explain what happens when you use it and give an example.

In: Computer Science

3.1.1 Implement the pop() operation in the stack (1 mark) Implement a stack class named Stack2540Array...

3.1.1 Implement the pop() operation in the stack (1 mark) Implement a stack class named Stack2540Array using array. The starter code is as follows. The instance variables and most operations are provided. You need to implement the pop operation. Make sure that your program checks whether the stack is empty in the pop operation. The implementation can be found in the book and in our lecture slides.

import java . io .*;

import java . util .*;

public class Stack2540Array {

int CAPACITY = 128;

int top ;

String [] stack ;

public Stack2540Array () {

stack = new String [ CAPACITY ]; top = -1; } 1 3.1 Implement the stack ADT using array 3 TASKS public int size () { return top + 1; } public boolean isEmpty () { return ( top == -1) ; } public String top () {

if ( top == -1)

return null ;

return stack [ top ];

}

public void push ( String element ) {

top ++;

stack [ top ] = element ; }

In: Computer Science

Please don't copy and paste from the internet. Thank you - What is meant by term...

Please don't copy and paste from the internet. Thank you

- What is meant by term “inelastic traffic” on a network?

- Explain the primary difference between network applications that use client-server architecture and applications that use peer-to-peer architecture.

- What is meant by the term “peer-churn” with respect to peer-to-peer application architectures?

- Describe in one sentence what is represented by a “port” number to the protocol operating in the transport layer in layered protocol architecture.

Please don't copy and paste from the internet. Thank you

In: Computer Science

JAVA You will then prompt the user to enter each grocery item and store it in...

JAVA

You will then prompt the user to enter each grocery item and store it in your array. Afterward, the program will ask the user to enter which grocery item they are looking for in the list, and return a message back on whether it was found or not found.

(Hint: You will need two for-loops for this program - one for storing each element into the array and one for searching back through the array.) See below for example output:

Example output 1:

How many items would you like on your grocery list?

3

Enter item 1:

potato

Enter item 2:

cheesecake

Enter item 3:

bread

Welcome to your digital grocery list!

What item are you looking for?

bread

bread was found in your list!

Example output 2:

How many items would you like on your grocery list?

3

Enter item 1:

potato

Enter item 2:

cheesecake

Enter item 3:

bread

Welcome to your digital grocery list!

What item are you looking for?

muffins

muffins not found.

In: Computer Science

Develop a program, in which you'll design a class that holds the following personal data: name,...

Develop a program, in which you'll design a class that holds the following personal data: name, address, age, and phone number. As part of the program, you'll then create appropriate accessor and mutator methods. Also, set up three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information.

Input:

  • data for the following attributes of 3 instances of the  Personal Information Class:
  • name, address, age, and phone number

NOTE: The input data do not need to be real data; they need to be entered at the keyboard, when program is run.

Processing: Develop the following:

  • Personal Information Class
  • A program that creates three instances of the above class

Output:

Set up a loop and display data within each object:

  • name, address, age, and phone number

In: Computer Science

Consider a B-tree allowing splits and free-on-empty. Please show an example of these operations on a...

Consider a B-tree allowing splits and free-on-empty. Please show an example of these operations on a data structure containing 15 data items, a fanout of three, and at most three data items per node. Also give the search algorithm (use a give-up scheme).

In: Computer Science

Problem: HugeIntegerClass Create a class HugeInteger which uses a 40-element array of digits to store integers...

Problem: HugeIntegerClass

Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods Input, toString, Add, and Subtract. For comparing HugeInteger objects, provide the following methods: IsEqualTo, IsNotEqualTo, IsGreaterThan, IsLessThan, IsGreaterThanOrEqualTo and IsLessThanOrEqualTo. Each of these is a method that returns true if the relationship holds between the two HugeInteger objects and returns false if the relationship does not hold. Provide method IsZero. In the Input method, use the string method toCharArray to convert the input string into an array of characters, then iterate through these characters to create your HugeInteger. If you feel ambitious, provide methods Multiply, Divide, and Remainder


// Driver Class

Import.java.*;

public class <LastName>_HugeIntegerTest
{
   public static void Main(string[] args)
   {
      HugeInteger integer1 = new HugeInteger();
      HugeInteger integer2 = new HugeInteger();

      System.out.println("Enter first HugeInteger: ");
      integer1.Input(Console.ReadLine());

      System.out.println ("Enter second HugeInteger: ");
      integer2.Input(Console.ReadLine());

      System.out.println ("HugeInteger 1”+ integer1);
      System.out.println ("HugeInteger 2” +integer2);

      HugeInteger result;

      // add two HugeIntegers
      result = integer1.Add(integer2);
      System.out.println ("Add result” + result);

      // subtract two HugeIntegers
      result = integer1.Subtract(integer2);
      System.out.println ("Subtract result” + result);

      // compare two HugeIntegers
      System.out.println ( "HugeInteger 1 is zero: “ + integer1.IsZero());
      System.out.println ( "HugeInteger 2 is zero: “ + integer2.IsZero());
      System.out.println (
         "HugeInteger 1 is equal to HugeInteger 2: “ + integer1.IsEqualTo(integer2));
      System.out.println (
         "HugeInteger 1 is not equal to HugeInteger 2:” + integer1.IsNotEqualTo(integer2));
      System.out.println (
         "HugeInteger 1 is greater than HugeInteger 2: “ + integer1.IsGreaterThan(integer2));
      System.out.println (
         "HugeInteger 1 is less than HugeInteger 2:” + integer1.IsLessThan(integer2));
      System.out.println (
         "HugeInteger 1 is greater than or equal to HugeInteger 2: “ + integer1.IsGreaterThanOrEqualTo(integer2));
      System.out.println ( "HugeInteger 1 is less than or equal to HugeInteger 2: “ + integer1.IsLessThanOrEqualTo(integer2));
   }
}


Sample Run 1:

Enter first HugeInteger:

1234567890123456789012345678901234567890

Enter second HugeInteger:

0987654321098765432109876543210987654321

HugeInteger1 +1234567890123456789012345678901234567890

HugeInteger2 +987654321098765432109876543210987654321

Add result+2222222211222222221122222222112222222211

Subtract result+246913569024691356902469135690246913569

HugeInteger 1 is zero: false

HugeInteger 2 is zero: false

HugeInteger 1 is equal to HugeInteger 2: false

HugeInteger 1 is not equal to HugeInteger 2:true

HugeInteger 1 is greater than HugeInteger 2: true

HugeInteger 1 is less than HugeInteger 2:false

HugeInteger 1 is greater than or equal to HugeInteger 2: true

HugeInteger 1 is less than or equal to HugeInteger 2: false

Sample Run 2:

Enter first HugeInteger:

65479876253763637782636782636

Enter second HugeInteger:

989

HugeInteger1 +65479876253763637782636782636

HugeInteger2 +989

Add result+65479876253763637782636783625

Subtract result+65479876253763637782636781647

HugeInteger 1 is zero: false

HugeInteger 2 is zero: false

HugeInteger 1 is equal to HugeInteger 2: false

HugeInteger 1 is not equal to HugeInteger 2:true

HugeInteger 1 is greater than HugeInteger 2: true

HugeInteger 1 is less than HugeInteger 2:false

HugeInteger 1 is greater than or equal to HugeInteger 2: true

HugeInteger 1 is less than or equal to HugeInteger 2: false

public class HugeInteger

{

private final int DIGITS = 40;

private int[] integer;// array containing the integer

private boolean positive; // whether the integer is positive

// parameterless constructor

public HugeInteger()

{

//

}

// Convert a string to HugeInteger

public void Input(String inputstring)

{

//

}

// add two HugeIntegers

public HugeInteger Add(HugeInteger addValue)

{

//

}

// add two positive HugeIntegers

private HugeInteger AddPositives(HugeInteger addValue)

{

//

}

// subtract two HugeIntegers

public HugeInteger Subtract(HugeInteger subtractValue)

{

//

}

// subtract two positive HugeIntegers

private HugeInteger SubtractPositives(HugeInteger subtractValue)

{

//

}

// find first non-zero position of HugeInteger

private int FindFirstNonZeroPosition()

{

//

}

// get string representation of HugeInteger

public String toString()

{

//

}

// test if two HugeIntegers are equal

public boolean IsEqualTo(HugeInteger compareValue)

{

//

}

// test if two HugeIntegers are not equal

public boolean IsNotEqualTo(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is greater than another

public boolean IsGreaterThan(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is less than another

public boolean IsLessThan(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is greater than or equal to another

public boolean IsGreaterThanOrEqualTo(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is less than or equal to another

public boolean IsLessThanOrEqualTo(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is zero

public boolean IsZero()

{

//

}

//Optional

public HugeInteger multiply(HugeInteger multiplyValue)

{

//

}

}

In: Computer Science