Questions
[PYTHON] Two natural number p,q are called coprime if there are no common prime factors in...

[PYTHON] Two natural number p,q are called coprime if there are no common prime factors in their prime factorization. E.g. 15 and 20 are not coprime because 5 is a common prime number in their prime factorization, while 20 and 9 are coprime. The Euler’s phi function, φ(n), counts the number of all natural numbers ≤ n which are coprime to n. E.g. φ(9) = 6, as all natural numbers ≤ 9 are 1,2,3,4,5,6,7,8,9. And out of these, the numbers coprime to 9 are 1,2,4,5,7 and 8, a total of 6 natural numbers.

You are required to write a Python function totient(n) that accepts a natural number as input argument and returns the following:

1. a list of all the natural numbers less than or equal to n which are coprime to n; and

2. the result of the Euler’s phi function when run on n.

E.g. totient(9) should return [1,2,4,5,7,8], 6

You can use your function prime factors from Problem 2. to determine if two numbers are coprime or not.

In: Computer Science

Create a program that asks the user to input three numbers and computes their sum. This...

Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.

In: Computer Science

Discuss and gather insight and feedback on the importance of data models and how to discover...

Discuss and gather insight and feedback on the importance of data models and how to discover business rules and interpret them as an information resource.

In: Computer Science

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