Questions
Roster method and Set builder notation 1. Use the roster method to list the members of...

Roster method and Set builder notation

1. Use the roster method to list the members of these sets.

A = { y | y is the square of an integer and y < 100}

B = {x ∈ ℚ | x = a / b, a = 3, b ∈ ℤ+ , x ≥ 2 }

C = { y | y is the remainder of x/5, x ∈ ℤ+ } another definition: C = {y | y = x%5, x∈ ℤ+ }

In: Computer Science

for an array A of size N, and A[0] != A[n-1]. devise an efficient algorithm for...

for an array A of size N, and A[0] != A[n-1]. devise an efficient algorithm for find a pair of elements A[i] and A[i+1] such that A[i] != A[i+1]. can you always find such pair and why

In: Computer Science

Why would log-structured merge trees be inappropriate (bad) for an application like git that manages source...

Why would log-structured merge trees be inappropriate (bad) for an application like git that manages source code? Explain

In: Computer Science

Let f1(n) and f2(n) be asymptotically nonnegative functions. Using the formal definition of Θ-notation, prove that...

Let f1(n) and f2(n) be asymptotically nonnegative functions. Using the formal definition of Θ-notation, prove that max(f1(n), f2(n)) = Θ(f1(n)+f2(n)).

In: Computer Science

How can I reduce data set by deleting any rows that have all FALSE bool values...

How can I reduce data set by deleting any rows that have all FALSE bool values for every column in
that row using pandas. Assuming there are 20+ columns/rows to loop through. Example: The table data below the pandas code should drop/reduce the data to remove the second & fifth row. True and False in the table are dtype bool.

id Test1 value1 value2 value3 value4
0.1 1 False False False False
0.2 2 False True True False
0.3 3 True False False False
0.4 4 False False False False

In: Computer Science

1. make a c++ program that generates a random number 1to 100 using rand(). user gets...

1. make a c++ program that generates a random number 1to 100 using rand().
user gets 5 attempts
stop program when they get it right
find out which guess was the closest to the actual number and print out that they have to run the difference in miles for example (50-30)=20 miles
do not use arrays!
very quick upvote for good response

In: Computer Science

In DHCP discover message, what is the source address and what is the destination address? What...

In DHCP discover message, what is the source address and what is the destination address? What are their special meanings?

In: Computer Science

For Machine Learning, one question....................................................................................... 1) Discuss the relation between feature scaling and the gradient descent...

For Machine Learning, one question.......................................................................................

1) Discuss the relation between feature scaling and the gradient descent algorithm. To be precise, discuss how feature scaling can affect the gradient descent algorithm?

In: Computer Science

D-Latch is a simple clocked memory element in which the output is equal to the stored...

D-Latch is a simple clocked memory element in which the output is equal to the stored state inside the element.

In D-Latch the state is changed whenever the appropriate inputs change and the clock is asserted. A D-Latch has two inputs and two outputs.

The inputs are the data value to be stored and a clock signal that indicates when the latch should read the value on the data input and store it. The outputs are simply the value of the internal state and its complement.

When the clock input is asserted, the latch is said to be open, and the value of the output becomes the value of the data input. When the clock input is de-asserted, the latch is said to be closed, and the value of the output is whatever value was stored the last time the latch was open.

What is the difference between DFF and D-Latch?

Can one chip be used for constructing the other? Explain.

In: Computer Science

1. programmers often refer to a _____ search as a "divide and conquer" procedure a. bubble...

1. programmers often refer to a _____ search as a "divide and conquer" procedure

a. bubble

b. binary

c. division

d. split

2. you can add an item at any point in a _______ container and the array size expands automatically to accomodate the new item

a. arraylLst

b. Array

c. ResizableArray

d. array

3.int[][] myVals = {{2,4,6,8},{20,40,60,80};

Using the above two dimensional array, what is the value of myVals[1][2]?

a. 4

b.60

c. 6

d.40

In: Computer Science

In Java 1. Which term best describes a "A uses B" class relationship? word answer: 2....

In Java
1. Which term best describes a "A uses B" class relationship? word answer:

2. choose correct one:

What are some of the ways a class can exhibit dependency?

A. A class can invoke the methods of another class.

B. A method within a class can accept an object of the same class.

C. A class can rely on a constant defined in another class.

D. All of the above.

Which if the following statements is FALSE regarding arrays of objects?

A. Objects stored in an array are automatically instantiated when the array is created.

B. Attempting to print out an empty array of objects will generate a NullPointerException.

C. An array of objects initially holds null references.

D. An array of objects is actually an array of references to the objects.

What symbol changes a typical parameter to a variable parameter list?

A :

B *

C ...

D ?

Which of the following rules is TRUE regarding variable parameter lists?

A. A variable parameter list can appear in any order in a list of formal arguments.

B. A method can only have one variable parameter list in its list of formal parameters.

C. A variable parameter list can be the only formal argument in a method.

D. You cannot use a variable parameter list in a constructor.

3. Fill in the Blanks

The keyword [_____] is used to establish an inheritance relationship.

The existing class is also known as the [_____] class.

4. When should the protected modifier be used?

A. When you want all classes to access variables or methods from any other classes.

B. When you want a derived class to access a variable or method from the (originally) existing class.

C. When you don't want any variable or method to be accessible outside the class.

D. When you want a single method or variable to be shared among all objects.

5. The super reference is typically used by the child class to call which type of method? Word Answer:

6. Fill in the Blanks

A new method must have the same [_____] as the existing method in order to perform overriding..

In: Computer Science

Can you please take this code and just rewrite it so it can be easily be...

Can you please take this code and just rewrite it so it can be easily be able to put into a complier. in java

Implementation of above program in java:

import java.util.HashMap;
import java.util.Scanner;
import java.util.Map.Entry;

public class Shopping_cart {
  
   static Scanner s= new Scanner (System.in);
  
//   declare hashmap in which key is dates as per mentioned and Values class as value which consists all the record of cases
   static HashMap<String,Item> map= new HashMap<>();

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       getupdates();
   }
  
   static void getupdates() {
      
       System.out.println("Welcome to Shopping Cart. Enter:");
       System.out.println("1 : Add an Item ");
       System.out.println("2 : Add multiples Quantities of Given Item ");
       System.out.println("3 : Remove an unspecified Item ");
       System.out.println("4 : CheckOut");
       System.out.println("5 : Checkbudget");
       System.out.print("Choice: ");
       int selection= s.nextInt();
      
      
       switch(selection) {
       case 1:
          add_new_item();
          getupdates();
            
          case 2:
              Add_multiples_items();
              getupdates();
                
          case 3:
              remove_unspecified_data();
              getupdates();
                
          case 4:
                  checkout();
                  getupdates();
                 
          case 5:
                
              checkbudget();
              getupdates();
                    
          case 6:
              System.out.println("Stay Safe");
              break;
                
              default:
                  System.out.println("Invalid choice");
                   System.out.println("Please enter the valid choice");
                   getupdates();
                    
       }
   }

   public static int total_price() {
      
       int total_price=0;
       for (Entry<String, Item> entry : map.entrySet()) {
                  
                   Item it=map.get(entry.getKey());
                  
                   total_price+=it.getPrice()*it.get_quantity();
                  
               }
         
       return total_price;
      
   }
  
  
     
  
   private static void checkbudget() {
      
       System.out.print("Enter your Total Budget : ");
       int budget=s.nextInt();
      
       int totalprice=0;
  


System.out.println("Total Amount = "+total_price());

while(budget<total_price()) {
   totalprice = remove_unspecified_data();
     
     
     
   if(budget>=totalprice) {
       break;
   }
}


System.out.println();

System.out.println("Now updates cart : ");

checkout();

System.out.println();
      
   }

   private static void checkout() {
       System.out.println(" Here list of Items in Your Cart");
      
       int i=1;
       int total_price=0;
       System.out.println(" S.no Name of item Quantity price ");
       System.out.println(" ");
       for (Entry<String, Item> entry : map.entrySet()) {
          
           Item it=map.get(entry.getKey());
          
           System.out.println(" "+i+" "+entry.getKey()+" "+it.get_quantity()+" $"+it.getPrice()*it.get_quantity());
           total_price+=it.getPrice()*it.get_quantity();
           i++;
       }
      
       System.out.println();
      
       System.out.println("Total Amount = "+total_price);
      
       System.out.println();
       System.out.println();
   }

   private static int remove_unspecified_data() {
      
       System.out.print("Enter the item you want to remove from your cart : ");
       String name=s.next();
      
       Item it1=map.get(name);
      
       int quant=it1.get_quantity();
      
       if(quant>1) {
          
       quant--;
       it1.set_quantity(-1);
      
       map.put(name, it1);
       }
         
       else {
           map.remove(name, it1);
       }
      
       int total_price=total_price();
         
       total_price-=it1.getPrice();
         
       System.out.println();
       System.out.println();
      
       return total_price;
      
   }

   private static void Add_multiples_items() {
       System.out.print("Enter the item you want to add in your cart : ");
       String name=s.next();
      
System.out.println("Enter price of Item : ");
      
       int price=s.nextInt();
      
       System.out.print("Enter the quantity of that item you want to add : ");
       int quan=s.nextInt();
      
       if(map.containsKey(name)) {
           Item it1=map.get(name);
           it1.set_quantity(quan);
           map.put(name, it1);
       }
       else {
           Item it= new Item(name,price,quan);
           map.put(name, it);
       }
      
       System.out.println();
       System.out.println();
      
   }

   private static void add_new_item() {
       System.out.print("Enter the item you want to add in your cart : ");
      
       String name=s.next();
      
       System.out.println("Enter price of Item : ");
      
       int price=s.nextInt();
      
      
      
       if(map.containsKey(name)) {
           Item it1=map.get(name);
           it1.set_quantity(1);
           map.put(name, it1);
       }
       else {
           Item it= new Item(name,price,1);
           map.put(name, it);
       }
      
       System.out.println();
       System.out.println();
      
   }
  
  

}

class Item
{   
private String name;
private int price;
private int quantity; //in cents
  
//Constructor
public Item(String n, int p,int quantity)
{
name = n;
price = p;
this. quantity=quantity;
}
  
public boolean equals(Item other)
{
return this.name.equals(other.name) && this.price == other.price;
}
  
//displays name of item and price in properly formatted manner
public String toString()
{
return name + ", price: $" + price/100 + "." + price%100;
}
  
//Getter methods
public int getPrice()
{
return price;
}
  
public int get_quantity()
{
return quantity;
}
  
public void set_quantity(int qa)
{
   quantity+=qa;
}
  
public String getName()
{
return name;
}
}

In: Computer Science

Assignment requirements You will be creating your custom Set (think a list of unique elements) class...

Assignment requirements

You will be creating your custom Set (think a list of unique elements) class in C++. Please do NOT use STL, or any pre-defined library for this assignment.

1. The data type of the set collection: array (or vector).

2. Create three operations (based on Set ADT descriptions

-union()

-intersection()

-difference()

3. Put some test code in main()

In: Computer Science

Input a phrase from the keyboard. For example, input could be: Today is a rainy day,...

Input a phrase from the keyboard. For example, input could be:

Today is a rainy day, but the sun is shining.

Your program should count (and output) the number of "a"s in the phrase, the number of "e"s, the number of "i"s , the number of "o"s, the number of "u"s, and the total number of vowels.

Note: The number of "a"s means the total of uppercase and lowercase "a"s etc.

Also: the vowels are a,e,i,o,u.

In the above example your output should be:

The phrase is "Today is a rainy day, but the sun is shining."

The number of a's: 4

The number of e's: 1

The number of i's: 5

The number of o's: 1

The number of u's: 2

The total number of vowels is: 13

Code language: java

In: Computer Science

JAVA DATA STRUCTURE (Linked Lists/Queue) public class Node {    int value;    Node nextNode;   ...

JAVA DATA STRUCTURE (Linked Lists/Queue)

public class Node {
   int value;
   Node nextNode;

   Node(int v, Node n){
       value = v;
       nextNode = n;
   }

   Node (int v){
       this(v,null);
   }
}

public class Stack {
   protected Node top;

   Stack(){
       top = null;
   }

   boolean isEmpty(){
       return( top == null);
   }
   void push(int v){
       Node tempPointer;
       tempPointer = new Node(v);
       tempPointer.nextNode = top;
       top = tempPointer;
   }
   int pop(){
       int tempValue;
       tempValue = top.value;
       top = top.nextNode;
       return tempValue;
   }
   void printStack(){
       Node aPointer = top;
       String tempString = "";
       while (aPointer != null)
       {
           tempString = tempString + aPointer.value + "\n";
           aPointer = aPointer.nextNode;
       }

       System.out.println(tempString);
   }
}

public class StackWithLinkedList {
   public static void main(String[] args){
       int popValue;
       Stack myStack = new Stack();
       myStack.push(5);
       myStack.push(7);
       myStack.push(9);
       myStack.printStack();
       popValue = myStack.pop();
       popValue = myStack.pop();
       myStack.printStack();
   }
}

Add the Queue class to the program introduced above. New Class should be CREATED (-->NOT importing<-- ANY TYPE of CLASS from Java Library, just using the provided classes), You should create Queue class like we created the Stack class(see the CODE above). Create the Queue class with the following specifications:

a. It must create a queue(constructor)

b. Insert one end (enqueue)

c. Do extractions at the other end (dequeue)

d. Determine if queue is empty (isEmpty)

e. Print the content of the queue (printQueue)

f. Finally, you must develop a main class QueueWithLinkedList that proves that every method works (just like we did with the StackWithLinkedList class provided in the program above)

In: Computer Science