Questions
1.Instead of Build-Max-Heap, we could use Heap-Insert-Max to build a tree with heap property. Write a...

1.Instead of Build-Max-Heap, we could use Heap-Insert-Max to build a tree with heap property. Write a pseudocode for that procedure, also evaluate it’s time complexity.
2. How Insertion sort works on the following array
[16, 12, 3, 27, 9, 4, 5, 7]]

In: Computer Science

explain why using email address as the primary key for Staff is a bad idea

explain why using email address as the primary key for Staff is a bad idea

In: Computer Science

(C++)Counting Sort: Write C++ codes for counting sort. The input array is A = {20, 18,...

(C++)Counting Sort: Write C++ codes for counting sort. The input array is A = {20, 18, 5, 7, 16,

10, 9, 3, 12, 14, 0}

In: Computer Science

Describe how to select various cable media and network interface cards (NIC) options for your own...

Describe how to select various cable media and network interface cards (NIC) options for your own home network configuration. Be sure to discuss what you would want for the optimal situations for your network. Brainstorm with other students to improve upon their optimal situation or provide an alternative idea for their situation.

In: Computer Science

I need this written in Java, it is a Linked List and each of it's Methods....

I need this written in Java, it is a Linked List and each of it's Methods. I am having trouble and would appreciate code written to specifications and shown how to check if each method is working with an example of one method being checked. Thank you.

public interface Sequence <T> {

    /**
     * Inserts the given element at the specified index position within the sequence. The element currently at that
     * index position (and all subsequent elements) are shifted to the right.
     *
     * @param index the index at which the given element is to be inserted
     * @param x     the element to insert
     * @return {@code true} if and only if adding the element changed the sequence
     * @throws IndexOutOfBoundsException if the index is invalid {@code (index < 0 || index > size())}
     * @throws NullPointerException      if the given element is {@code null}
     */
    boolean add(int index, T x) throws IndexOutOfBoundsException, NullPointerException;

    /**
     * Adds the specified element to the end of the sequence.
     *
     * @param x the element to add
     * @return {@code true} if and only if adding the element changed the sequence
     * @throws NullPointerException if the given element is {@code null}
     */
    boolean add(T x) throws NullPointerException;

    /**
     * Removes all of the elements from the sequence.
     */
    void clear();

    /**
     * Check if the given element belongs to the sequence.
     *
     * @param x the element to check for
     * @return {@code true} if and only if the sequence contains the given element
     * @throws NullPointerException if the given element is {@code null}
     */
    boolean contains(T x) throws NullPointerException;

    /**
     * Returns the element at the given position in the sequence.
     *
     * @param index the index of the element to return
     * @return the element at the given position in the sequence
     * @throws IndexOutOfBoundsException if the index is invalid {@code (index < 0 || index >= size())}
     */
    T get(int index) throws IndexOutOfBoundsException;

    /**
     * Returns the index position of the first occurrence of the given element within the sequence or -1 if it does not
     * belong.
     *
     * @param x the element to search for
     * @return the index position of the first occurrence of the given element within the sequence or -1 if it does not
     * belong
     * @throws NullPointerException if the given element is {@code null}
     */
    int indexOf(T x) throws NullPointerException;

    /**
     * Check if the sequence is empty.
     *
     * @return {@code true} if and only if the sequence is empty.
     */
    boolean isEmpty();

    /**
     * Removes the element at the given position in the sequence.
     *
     * @param index the index position of the element to be removed
     * @return the element at the given position in the sequence
     * @throws IndexOutOfBoundsException if the index is invalid {@code (index < 0 || index >= size())}
     */
    T remove(int index) throws IndexOutOfBoundsException;

    /**
     * Remove the first occurrence of the given element from the sequence (if present).
     *
     * @param x the element to be removed from this list
     * @return {@code true} if and only if removing the element changed the sequence
     * @throws NullPointerException if the given element is {@code null}
     */
    boolean remove(T x) throws NullPointerException;

    /**
     * Replaces the element at the given position of the sequence with the specified element.
     *
     * @param index index of the element to replace
     * @param x     the new element
     * @throws IndexOutOfBoundsException if the index is invalid {@code (index < 0 || index >= size())}
     * @throws NullPointerException      if the given element is {@code null}
     */
    void set(int index, T x) throws IndexOutOfBoundsException, NullPointerException;

    /**
     * Returns the number of elements in this sequence.
     *
     * @return the number of elements in this sequence
     */
    int size();

    /**
     * Returns an array containing all of the elements in this sequence (preserving their order).
     *
     * @return an array containing all of the elements in this sequence (preserving their order)
     */
    Object[] toArray();
}

In: Computer Science

(C++)Radix Sort: Write C++ codes for radix sort: use counting sort for decimal digits from the...

(C++)Radix Sort: Write C++ codes for radix sort: use counting sort for decimal digits from

the low order to high order. The input array is A = {329, 457, 657, 839, 436, 720, 353}

In: Computer Science

Write a program, called NationalTax, that will simulate calculating a citizen's income tax for the year....

Write a program, called NationalTax, that will simulate calculating a citizen's income tax for the year.

A country uses lettered ID's to identify its citizens. Valid ID's will be either 8 or 9 characters long. All characters entered will be alphabetic characters only (a-z or A-Z).

  • Display a welcome message.
  • Prompt the user for their ID and read it in.
  • Next, determine if the ID is valid based on its length.
    • If it is not valid, simply state that the ID is invalid and let the program end naturally (you may NOT use System.exit).
    • However, if it is valid, then do the following:
      • Prompt the user for the tax year (entered as a four-digit integer). No validity check needs to happen here.
      • Prompt the user for their annual income (this includes dollars and cents) and read it in. Since no annual income can be less than zero, if the user enters a negative amount, simply convert it to its positive amount. You may not use if/else statements here. Use the appropriate Math library method.
      • Convert the ID to all CAPS.
      • Display the ID.
      • Display the annual income as dollars and cents.
      • Set the tax amount to be log10 of their annual income multiplied by 100. Display this as their initial tax amount.
      • Then if the first character of the ID is in the range:
        • A - G, then the person works for the government. Reduce their tax by 10%. Display that they are a government employee, that they receive a 10% tax reduction, and display the new tax amount.
        • H - P, then the person works in the public sector. There is no tax reduction. Display they they are a public sector employee and that they receive no tax reduction.
        • Q - U, then the person is unemployed. Display that they are unemployed and that they receive no tax reduction.
        • Otherwise the person is retired. Reduce their tax by 25%. Display that they are retired, that they receive a 25% tax reduction, and display the new tax amount.
      • Then if the last character of the ID is greater than the first character:
        • the person is 21 years old or older. They pay an additional $100 in taxes. Add this to their current tax amount. Display that they are 21 years of age or older, that there is an additional $100 tax, and display the new tax amount.
        • Otherwise the person is less than 21 years old. There is no additional tax. Display that the are under 21 years of age and do not pay the additional tax.
      • Then if the ASCII value of the fifth letter (remember indexing starts at 0) of the ID (as a capital letter) is divisible by 7
        • that person is a millionaire. Their tax is the larger of the current tax amount and $15,000. Display that they are a millionaire, that their tax is the larger of their current tax amount (display the value) and $15,000, and display their new tax amount.
        • Otherwise they are not. Display nothing.
      • Then if the ID contains the string "MED" (remember case does not matter in the ID):
        • then they are a medical professional. Their tax is reduced by $100. Display that they are a medical profession, they their tax is reduced by 100, and display the new tax amount.  
        • Otherwise they are not. Display nothing.
      • Then if the final tax amount is negative, change it to 0.
      • Finally, in one printf statement, display a message that tells the user the ID, the tax year, their annual income, and their final tax amount owed.

In: Computer Science

Part 1: Write a program that finds the sum and average of a series of numbers...

Part 1: Write a program that finds the sum and average of a series of numbers entered by the user. The program will first ask the user how many numbers there are. It then prompts the user for each of the numbers in turn and prints out the sum, average, the list of number from the user. Note: the average should always be a float, even if the user inputs are all ints.

Part 2: Same as part 1 except now the numbers are to be read in from a file.
File contains a single line of numbers delimited by comma. Example: 8, 39, 43, 1, 2, 3

Part 3: Part 2 but modular ( i.e. using functions).
Assume the file name is passed to the function as a parameter. The function then opens the file, reads in the numbers, then computes and returns the sum and average of the numbers.

In: Computer Science

c++ You will implement a template class with the following members: An array of our generic...

c++

You will implement a template class with the following members:

  1. An array of our generic type. The size of this array should be determined by an integer argument to the constructor.
  2. An integer for storing the array size.
  3. A constructor capable of accepting one integer argument. The constructor should initialize the array and set the array size.
  4. A method, find Max, that returns the maximum value in the array.
  5. A method, find Min, that returns the minimum value in the array.

Additionally you will need to create a short driver program that demonstrates your template class working with a few different numeric data types.

In: Computer Science

I'm having trouble determining the lines of code for 4-6 #include <stdio.h> //function prototypes void initializeArray(int...

I'm having trouble determining the lines of code for 4-6

#include <stdio.h>

//function prototypes
void initializeArray(int size, int ids[]);
void printArray(int size, int * idPointer);


int main(void) {
// 1. declare an array of 5 integers called ids
int ids[1,2,3,4,5];
  
// 2. declare an integer pointer called arrayPointer and
// initialize it to point to the array called ids
int *arrayPointer = ids;


// 3. call initializeArray() function sending to it
// 5 for the size and the array called ids
intializeArray(5,ids[]);
  
  
  
// 4. add 3 to the value at where arrayPointer is pointing to
*(arrayPointer + 3);


// 5. add 5 to the value at 2 locations past
// where arrayPointer is pointing to

  
  
// 6. call printArray() function sending to it
// 5 for the size and arrayPointer

  
  
return 0;
}


// This function initializes an array ids of size "size"
void initializeArray(int size, int ids[]) {
int i;
for (i = 0; i < size; i++) {
ids[i] = i * 100;
}
}


// This function prints an array of size "size". The array is pointed at by idPointer
void printArray(int size, int * idPointer) {
int i;
for (i = 0; i < size; i++) {
// 7. finish the code for the printf() statement
printf("Element at index %d is %d\n", i);
}
}

In: Computer Science

Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount...

Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method for the sale amount, calculate the sales tax as 5% of the sale amount. Also include a display method that displays a purchase’s details.

Here is the provided code:

import java.util.*;
public class CreatePurchase
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Purchase purch = new Purchase();
int num;
double amount;
String entry;
final int LOW = 1000, HIGH = 8000;
System.out.println("Enter invoice number");
entry = input.next();
num = Integer.parseInt(entry);
while(num <= LOW || num >= HIGH)
{
System.out.println("Invoice number must be between " +
LOW + " and " + HIGH + "\nEnter invoice number");
entry = input.next();
num = Integer.parseInt(entry);
}
  
System.out.println("Enter sale amount");
entry = input.next();
amount = Double.parseDouble(entry);
while(amount < 0)
{
System.out.println("Enter sale amount");
entry = input.next();
amount = Double.parseDouble(entry);
}
purch.setInvoiceNumber(num);
purch.setSaleAmount(amount);
purch.display();
}
}

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

Other Class:

_--_____________________________

public class Purchase {
private int invoiceNumber;
private double saleAmount;
private double tax;
private static final double RATE = 0.05;
public void setInvoiceNumber(int num) {
}
public void setSaleAmount(double amt) {
}
public double getSaleAmount() {
}
public int getInvoiceNumber() {
}
public void display() {
System.out.println("Invoice #" + invoiceNumber +
" Amount of sale: $" + saleAmount + " Tax: $" + tax);
}
}

pls help

In: Computer Science

Displaying Content of an XML File Using PHP Script or Code In this week, you are...

Displaying Content of an XML File Using PHP Script or Code

In this week, you are going to write the PHP script or code to read an XML file and display its content on the screen. The file you will modify is the Products page, which you created in Week 1 Project. Given the following data in XML format, modify the Products page to read and display the information in the Products page:

<Product>
<Item>
<Name>T-Shirt</Name>
<Price>12.5</Price>
</Item>
<Item>
<Name>Pants</Name>
<Price>45</Price>
</Item>
<Item>
<Name>Hat</Name>
<Price>10.5</Price>
</Item>
</Product>

Your end page result needs to show the items, their cost (price) in a table format. Use both PHP script as well as HTML tags to create the dynamic table from the given XML file.

In: Computer Science

**Complete for display digits 0 and 7 only** A combinational circuit is used to control a...

**Complete for display digits 0 and 7 only**

A combinational circuit is used to control a seven-segment display of decimal digits, as shown in Figure 11.35. The circuit has four inputs, which provide the four-bit code used in packed decimal representation (010 = 0000,c, 910 = 1001). The seven outputs define which segments will be activated to display a given decimal digit. Note that some combinations of inputs and outputs are not needed. a. Develop a truth table for this circuit. b. Express the truth table in SOP form. c. Express the truth table in POS form. d. Provide a simplified expression.

In: Computer Science

Code in Java In Chapter 9, we created the CommissionEmployee-BasePlusCommissionEmployee inheritance hierarchy to model the relationship...

Code in Java

In Chapter 9, we created the CommissionEmployee-BasePlusCommissionEmployee inheritance hierarchy to model the relationship between two types of employees and how to calculate the earnings for each. Another way to look at the problem is that CommissionEmployees and BasePlusCommissionEmployees are each Employees and that each has a different CompensationModel object.

A CompensationModel would provide an earnings method. Classes or subclasses of CompensationModel would contain the details of a particular Employee's compensation:

  • CommissionCompensationModel - For Employees who are paid by commission, the CommissionCompensationModel class would contain grossSales and commissionRate instance variables, and would define an earnings method to return grossSales * commissionRate.
  • BasePlusCommissionCompensationModel - For Employees who are paid a base salary and commission, this subclass of CommissionCompensationModel would contain an instance variable of baseSalary and would define the earnings method to return super.earnings() + baseSalary.

Each of these classes would contain a toString() method that displays the Compensation Model information as illustrated in the sample output.

This approach is more flexible than our original hierarchy. For example, consider an Employee who gets promoted. With the approach described here, you can simply change that Employee's CompensationModel by assigning the composed CompensationModel reference an appropriate subclass object. With the CommissionEmployee - BasePlusCommissionEmployee hierarchy, you'd need to change the Employee's type by creating a new object of the appropriate class and moving data from the old object to the new one.

Implement the Employee class and CompensationModel hierarchy discussed in this exercise. In addition to the firstName, lastName, socialSecurityNumber and CommisionCompensationModel instance variables, class Employee should provide:

  • A constructor that receives three Strings and a CommissionCompensationModel to initialize the instance variables.
  • A set method that allows the client code to change an Employee's CompensationModel.
  • An earnings method that calls the CompensationModel's earning method and returns the result.
  • A toString() method that displays all the information about the Employee as illustrated in the sample output.

Your code in the subclasses should call methods in the super classes whenever possible to reduce the amount of code in the subclasses and utilize the code already developed in the super classes as in the code demonstrated in Figures 9.10 and 9.11 in the book.

Use the following code in your main function to test your classes, just copy and paste it into your main method:

        // Create the two employees with their compensation models.
       
        CommissionCompensationModel commissionModel = new CommissionCompensationModel(2000.00, 0.04);
        BasePlusCommissionCompensationModel basePlusCommissionModel = new BasePlusCommissionCompensationModel(2000.00, 0.05, 600.00);
       
        Employee employee1 = new Employee("John", "Smith", "111-11-1111", commissionModel);
        Employee employee2 = new Employee("Sue", "Jones", "222-22-2222", basePlusCommissionModel);
       
        System.out.printf("%s%n%s%n", employee1, employee2);
        System.out.printf("%s%s%s%s%s%8.2f%n%n", "Earnings for ", employee1.getFirstName(), " ", employee1.getLastName(), ": ", employee1.earnings());
       
        // Change the compensation model for the two employees.
       
        CommissionCompensationModel commissionModelNew = new CommissionCompensationModel(5000.00, 0.04);
        BasePlusCommissionCompensationModel basePlusCommissionModelNew = new BasePlusCommissionCompensationModel(4000.00, 0.05, 800.00);
       
        // Set the new compensation models for the employees.
        employee1.setCompensation(basePlusCommissionModelNew);
        employee2.setCompensation(commissionModelNew);
       
        // Print out the new information for the two employees.
        System.out.printf("%s%n%s%n", employee1, employee2);

The output from your program should look like the following:

run:
John Smith
Social Security Number: 111-11-1111
Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.04
Earnings:    80.00

Sue Jones
Social Security Number: 222-22-2222
Base Plus Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.05
Base Salary of:   600.00
Earnings:   700.00

Earnings for John Smith:    80.00

John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.00
Commission Rate of: 0.05
Base Salary of:   800.00
Earnings: 1000.00

Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.00
Commission Rate of: 0.04
Earnings:   200.00

In: Computer Science

In An Introduciton to Programmig Using Visual Basic tenth edition chapter 6 the 4th project program...

In An Introduciton to Programmig Using Visual Basic tenth edition chapter 6 the 4th project program has me using loops. I am having a hard time trying to figure out what the double declining balance methods depreciation value is. It is 2 divided by the items life, but multiplied by the previous years balance. I do not know how to find the previous years balance to use in the depreciation value. Thank you

In: Computer Science