Questions
Use C language Problem 1: Buy cheese (Level 1) • Problem description You have M dollors...

Use C language

Problem 1: Buy cheese (Level 1)
• Problem description
You have M dollors and want to buy as much cheese as possible. There is a cheese shop with
two kinds of cheese. The unit prices of the both cheese are p1 and p2, the total amount of them
are a1 and a2. You can buy either cheese or both, but the amount you buy cannot exceed its total
amount. Write a program to output the largest amount of cheese you can buy.
• Input & output requirements
All the integers variables (M, p1, a1, p2, and a2) are taken from user input. The input begins
with a line containing one non-negative interger M, and followed by two lines, each line
contains two integers, unit price and total amount.
The output should be a real number accurate up to 2 decimal places.
• Sample results
Sample 1
Please input M: 2↲
Please input p1 and a1: 1 2↲
Please input p2 and a2: 2 2↲
The maximum amount of cheese is 2.00
Sample 2
Please input M: 3↲
Please input p1 and a1: 2 2↲
Please input p2 and a2: 1 1↲
The maximum amount of cheese is 2.00

In: Computer Science

You shall implement a class named DnaSequence, which models a sequence of DNA. Requirements: You must...

You shall implement a class named DnaSequence, which models a sequence of DNA. Requirements:

You must implement all public constructors and methods described in this documentation.

Your class must have only 1 field, and it must be a private char[].

No print statements are allowed anywhere in your class.


The constructors require you to discard any character that is not 'A', 'C', 'G', or 'T'. This is very easily accomplished using a regular expression in String.replaceAll:

// returns a String containing "ACG" "A B C D E F G".replaceAll("[^ATCG]", "")

Here is a screenshot of the top of a partially redacted version of my DnaSequence.java file:

Testing

You'll probably want to create another class with a main method that tests your DnaSequence class, e.g.:


import java.util.Arrays; public class DnaSequenceTests { public static void main(String[] args) { DnaSequence seq = new DnaSequence(new char[] { 'G', 'A', 'T', 'T', 'A', 'C', 'A' }); assert "GATTACA".equals(seq.toString()); assert seq.baseAt(2) == 'T'; assert seq.gcContent() == 2.0 / seq.length(); seq.complement(0); assert seq.equals(new DnaSequence("CATTACA")); assert Arrays.equals(seq.nucleotideCounts(), new int[] { 3, 2, 0, 2 }); } }

Class DnaSequence

java.lang.Object

DnaSequence

public class DnaSequence
extends Object

Represents a simple DNA sequence.

Author:

A hardworking student for CS 12J, [email protected]

  • Field Summary

    Fields
    Modifier and Type Field Description
    private char[] dna

    The actual sequence of nucleotides is stored in this array, invisible to the outside world, only directly accessible within this class.

  • Constructor Summary

    Constructors
    Constructor Description
    DnaSequence​(char[] dna)

    Constructs a new DNA sequence from the contents of a char[].

    DnaSequence​(String dna)

    Constructs a new DNA sequence from the contents of a String.

  • Method Summary

    All MethodsInstance MethodsConcrete Methods

    Modifier and Type Method Description
    char baseAt​(int index)

    Returns the nucleotide base char value at the specified index.

    void complement​(int index)

    Mutator method that flips one base of this sequence to its complement.

    boolean equals​(DnaSequence that)

    Compares this sequence to another.

    double gcContent()

    Calculates and returns the GC-content of this DNA sequence.

    int hammingDistance​(DnaSequence that)

    Calculates and returns the Hamming distance between this DNA sequence and another.

    int length()

    Returns the length of this DNA sequence.

    boolean[] mutationPoints​(DnaSequence that)

    Calculates and returns where two DNA sequences of equal lengths differ.

    int[] nucleotideCounts()

    Calculates and returns the number of times each type of nucleotide occurs in this DNA sequence.

    DnaSequence reverseComplement()

    Calculates and returns the reverse complement of this DNA sequence as a new DnaSequence.

    String toString()

    Returns a string representation of this sequence (for example, "ATCCGTGGACT").

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • dna

      private char[] dna

      The actual sequence of nucleotides is stored in this array, invisible to the outside world, only directly accessible within this class.

  • Constructor Details

    • DnaSequence

      public DnaSequence​(String dna)

      Constructs a new DNA sequence from the contents of a String. Discards any invalid characters in the string, e.g. any character that is not 'A', 'T', 'C', or 'G'.

      Parameters:

      dna - a string containing characters that represent a DNA sequence

    • DnaSequence

      public DnaSequence​(char[] dna)

      Constructs a new DNA sequence from the contents of a char[]. Discards any invalid characters in the string, e.g. any character that is not 'A', 'T', 'C', or 'G'. Does not modify nor retain a reference to the parameter array.

      Parameters:

      dna - an array containing char values representing a DNA sequence

  • Method Details

    • length

      public int length()

      Returns the length of this DNA sequence. The length is equal to the number of nucleotides in the sequence.

      Returns:

      the length of this DNA sequence

    • toString

      public String toString()

      Returns a string representation of this sequence (for example, "ATCCGTGGACT").

      Overrides:

      toString in class Object

      Returns:

      a String containing all nucleotides in this sequence, in order

    • equals

      public boolean equals​(DnaSequence that)

      Compares this sequence to another. The result is true if and only if this sequence represents the same sequence of nucleotides as the other.

      Parameters:

      that - the other sequence

      Returns:

      whether this sequence represents the same sequence of nucleotides as the other

    • baseAt

      public char baseAt​(int index)

      Returns the nucleotide base char value at the specified index. An index ranges from 0 to this.length() - 1. The first base value of the sequence is at index 0, the next at index 1, and so on, as in array indexing.

      Parameters:

      index - the index of the base value

      Returns:

      the base value at the specified index of this sequence. The first base value is at index 0.

    • nucleotideCounts

      public int[] nucleotideCounts()

      Calculates and returns the number of times each type of nucleotide occurs in this DNA sequence.

      Returns:

      an int array of length 4, where indices 0, 1, 2 and 3 contain the number of 'A', 'C', 'G' and 'T' characters (respectively) in this sequence

    • reverseComplement

      public DnaSequence reverseComplement()

      Calculates and returns the reverse complement of this DNA sequence as a new DnaSequence. In DNA sequences, 'A' and 'T' are complements of each other, as are 'C' and 'G'. The reverse complement is formed by reversing the symbols of a sequence, then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").

      Returns:

      a new DnaSequence representing the reverse complement of this sequence

    • gcContent

      public double gcContent()

      Calculates and returns the GC-content of this DNA sequence. The GC-content of a DNA sequence is given by the percentage of symbols in the string that are 'C' or 'G'. For example, the GC-content of "AGCTATAG" is .375 (37.5%).

      Returns:

      the GC-content of this sequence, to double precision

    • hammingDistance

      public int hammingDistance​(DnaSequence that)

      Calculates and returns the Hamming distance between this DNA sequence and another. The Hamming distance between two sequences is the number of points in the sequences where the corresponding symbols differ. For example, the Hamming distance between "ATTATGC" and "ATGATCC" is 2.

      Parameters:

      that - the other sequence

      Returns:

      the Hamming distance between this sequence and the other, or -1 if the two sequences are of unequal length

    • mutationPoints

      public boolean[] mutationPoints​(DnaSequence that)

      Calculates and returns where two DNA sequences of equal lengths differ. For example, given sequences "ATGT" and "GTGA", the result should be array [true, false, false, true ].

      Parameters:

      that - the other sequence

      Returns:

      an array of boolean values, of length equivalent to both sequences' lengths, containing true in each index where the two sequences differ, and false where they do not differ. If the two sequences are of unequal length, this method returns {null}.

    • complement

      public void complement​(int index)

      Mutator method that flips one base of this sequence to its complement. In DNA sequences, 'A' and 'T' are complements of each other, as are 'C' and 'G'. For example, if feline is a reference to a DnaSequence object representing the sequence "GATCAT", then subsequent to invocation feline.complement(0), the represented sequence shall be "CATCAT".

      Parameters:

      index - the index at which to perform the complement

In: Computer Science

A)What is Artificial intelligence (AI)? What is the primary goal of AI? How AI is related to Expert Systems?


A)What is Artificial intelligence (AI)? What is the primary goal of AI? How AI is related to Expert Systems?

B)What is knowledge management (KM)? Explain the differences between the two fundamental approaches to knowledge management.

In: Computer Science

What consequences does moving from a 32-bit environment to a 64-bit environment have on programs, including...

What consequences does moving from a 32-bit environment to a 64-bit environment have on programs, including the operating system?

In: Computer Science

code in python I want to make a function that adds all the multipliers together. The...

code in python

I want to make a function that adds all the multipliers together. The code is posted below and please look at wanted output section to see what I want the code to output. The last line of the code is the only addition I need. Thanks.

Code:

initial=int(input("Initial value : "))       #taking inputs
multiplier=float(input("Multiplier : "))
compound=int(input("No of compounds : "))
print("Your values are:")
mult=initial                         #initalizing to find answer
for i in range(0,compound):         #multiplying by multiplier
    print(round(mult,1))
    mult=mult*multiplier

Code Output:

Initial Value: 10

Multiplier: 1.4

Number of compounds: 10

Your Values are: 10 , 14, 19.6 , 27.4, 38.4, 53.8, 75.3, 105.4, 147.6, 206.6

Total value Amount: 24 , 33.6, 47.04, 65.856, 92.1984, 129.07776, 180.708864, 252.9924096

In: Computer Science

What is the PRIMARY goal of an Information Security Continuous Monitoring (ISCM) strategy? Create expedited assessment...

What is the PRIMARY goal of an Information Security Continuous Monitoring (ISCM) strategy?

  1. Create expedited assessment process for cost savings.
  2. Maintain visibility of an organization’s high-cost controls.
  3. Support organization risk management decisions.
  4. Assess the organizational tiers.

In: Computer Science

What is the primary goal of the vulnerability assessment and remediation domain of the maintenance model?

What is the primary goal of the vulnerability assessment and remediation domain of the maintenance model? Is this important to an organization with an Internet presence? Why?

In: Computer Science

#include <stdio.h> #include <stdlib.h> int play_game(int *); // Returns 0 if player won, 1 if the...

#include <stdio.h>

#include <stdlib.h>

int play_game(int *); // Returns 0 if player won, 1 if the computer won, 2 if there is a tie, and -1 if the player decides to quit

int menu(int *); // Displays choices to user // Receives score array

int main() { srand(42); // Seeding Random with 42

int score[3]; // Array keeping Player, Computer, and Tie Scores

score [0] = 0; // Player - initialized to Zero

score [1] = 0; // Computer - initialized to Zero

score [2] = 0; // Tie - initialized to Zero

int winner=0; // Winner index of

printf("ROCK PAPER SCISSORS!\n\n");

while(winner >=0) // If Winner == -1 -> the game stops {

winner = play_game(score); // Plays the game

. if(winner >=0) // If a value to not stop the game comes in.

score[winner]++; // Increment score counter }

printf("GOOD BYE!\n");

return 0; }

please help with the two functions listed on top.

need to know

int menu(int *): Receives: integer array score Returns: Menu number for Rock, Paper, Scissors, or Exit. Returns -1 for any other number than applicable menu choice Grading: 1) Displays “ROCK PAPER SCISSORS!” at the top of the menu 2) Displays the current score between the player and the computer (including ties) 3) Displays choice numbers for Rock, Paper, Scissors, and Exit. 4) Asks for a choice – If improper choice is given (alpha-numeric and wrong number), asks for another choice 5) Console Display is organized and easily read 6) Code is organized and easily read (Comments where needed) HINT: Use of a switch statement makes the code a little easier to read.

int play_game(int *): Receives: integer array score Returns: an index of score to be incremented. If the player wins, returns 0. If the computer wins, returns 1. If there is a tie, returns 2. Grading: 1) The computer choice is randomly generated between 3 numbers using rand(). 2) Displays BOTH the User choice and the Computer Choice 3) Displays whether the result is a win, loss, or tie for the User. 4) Displays the following statements depending on what was played by the User and Computer  “ROCK CRUSHES SCISSORS!”  “SCISSORS CUT PAPER!”  “PAPER COVERS ROCK!”  “TIE – BAZINGA!” 5) Returns 0 if the User won, 1 if the Computer won, and 2 if the User and Computer Tied.

In: Computer Science

Hi! I am trying to work in my project, so I am doing my sql in...

Hi! I am trying to work in my project, so I am doing my sql in a supermarket. I did already my table but I having trouble to do my queries in diferent tables. I hope you can help me. I know its simple but I still learning. QB2 revision + queries batch 3 (QB3): basic aggregates (without conditions)

In a new thread in forum "QB2 revision + queries batch 3 (QB3): basic aggregates (without conditions)" provide: a revised version of QB2, and the DML for queries batch 3 (QB3), where each query requires the use of more than a single table..

CREATE TABLE `itemscategories` (
`category_id` int(11) NOT NULL,
`category_name` varchar(255) NOT NULL
)

CREATE TABLE `itemsproducts` (
`product_id` int(11) NOT NULL,
`product_name` varchar(255) NOT NULL,
`category_id` int(10) NOT NULL,
`list_price` decimal(10,2) NOT NULL,
`quantity` int(11) NOT NULL DEFAULT 0,
`product_stock` varchar(10) NOT NULL
)

CREATE TABLE `storecustomer` (
`customer_id` int(11) NOT NULL,
`customer_name` varchar(25) NOT NULL,
`customer_lastname` varchar(25) NOT NULL,
`customer_phone` int(12) NOT NULL
)

CREATE TABLE `storeemployer` (
`employer_id` int(11) NOT NULL,
`employer_name` varchar(20) NOT NULL,
`employer_lastname` varchar(20) NOT NULL,
`employer_salary` int(8) NOT NULL,
`employer_number` int(12) NOT NULL,
`employer_dob` date NOT NULL,
`store_id` int(11) NOT NULL
)

CREATE TABLE `storeinformation` (
`store_id` int(11) NOT NULL,
`store_name` varchar(50) NOT NULL,
`store_phone` varchar(50) NOT NULL,
`street` varchar(50) NOT NULL,
`city` varchar(50) NOT NULL,
`state` varchar(10) NOT NULL,
`zip_code` varchar(5) NOT NULL
)

CREATE TABLE `storeorders` (
`order_id` varchar(11) NOT NULL,
`product1_id` int(15) NOT NULL,
`final_quatity` int(10) NOT NULL,
`customer_id` int(10) NOT NULL,
`status` varchar(4) NOT NULL,
`category_id` int(10) NOT NULL,
`date_process` date NOT NULL,
`shipped_date` date NOT NULL
)

In: Computer Science

Jojo just graduated and moved up to grade 4. Today is his first day in 4th...

Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader.

The first task is to find the prime factorization of a number. Prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. Prime factorization of a number is breaking a number down into the set of prime numbers which multiply together to result in the original number. Example below is the prime factorization of 1176.

. As a good friend of Jojo, help Jojo to solve the prime factorization task given by his teacher. Format Input There are T testcases. Each testcase contains an integer N which indicates the number to be factorized into prime factorization. Format Output Output T line with format “Case # X: ”, where X indicates the testcase number and then followed by the number prime factorization in ascending order of prime factors with the correct format.As a good friend of Jojo, help Jojo to solve the prime factorization task given by his teacher. Format Input There are T testcases. Each testcase contains an integer N which indicates the number to be factorized into prime factorization. Format Output Output T line with format “Case # X: ”, where X indicates the testcase number and then followed by the number prime factorization in ascending order of prime factors with the correct format.

In: Computer Science

Problem 7. Give the canonical prime factorization of 504


Prime Factorizations 

Problem 7. Give the canonical prime factorization of 504 

Problem 8. Give the canonical prime factorization of 540 

Problem 9. Give the canonical prime factorization of 208740. 

Problem 10. Give the canonical prime factorization of 514395

In: Computer Science

Problem 1. Using prime factorization, find gcd(900, 140) and lcm(900, 140).


Problem 1. Using prime factorization, find gcd(900, 140) and lcm(900, 140).

In: Computer Science

A data miner wants to identify how price and advertising drive sales for the company and...

A data miner wants to identify how price and advertising drive sales for the company and wants to forecast but does not like to use algorithms. Which of the methods below represents the best solution.

        a. regression               b. Clustering               c. segmentation           d. Neural Nets

In: Computer Science

Question 1: Write a program in C++ using multi filing which means 3 files ( main...

Question 1: Write a program in C++ using multi filing which means 3 files ( main file, header file, and functions file) and attached screenshots as well. Attempt the Question completely which contain a and b parts

a) Write a program that takes a number from the user and checks whether the number entered validates the given format: “0322-5441576”, xxxx-xxxxxxx where “x” implies the digits only and first two digits are 0 and 3 respectively. The program also identifies the Network of the given number. (Use of string related functions is a must)

b) Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions.

For character identification

Develop a program that takes a string argument, and returns an array containing all unique characters.

For character counting

Develop a program that takes an array returned from above function as an argument along with the given string and return an array containing the total count of each uniquely identified character present in the argument array.

Note: kindly write a proper code of program mention in Question and answer complete Question along with both parts and screenshots Thanks.....

In: Computer Science

Fifty randomly selected students were asked the number of movies they watched them previous week. The...



Fifty randomly selected students were asked the number of movies they watched them previous week. The results are as follows:

# of Movies

# of Movies | Student Frequency

0. 10

1 . 18

2 . 12

3 . 8

4 . 2



a) Find the sample mean, median, and range of the sample. .

b) Find the standard deviation and the variance.

c) Find the first quartile. (1 mark)

d) Find the second quartile. To which value it corresponds? (1 mark)

e) Find the third quartile. (1 mark)

f) What percent of the students saw fewer than three movies.

j) Find the 40th percentile.

h) Find the 90th percentile.

In: Computer Science