This problem should be solved using the DrRacket software in Racket/Scheme language.
Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the lists to obtain the result. See the following examples for clarificaton.
(merge-sorter '(3 1 5 4 2) ---> (1 2 3 4 5) (merge-sorter '()) ---> () (merge-sorter '(1)) ---> (1)
In: Computer Science
Q: Let’s say you have an unordered list of numbers and you wanted to put them in order from lowest to highest value. How would you do that? You’re probably thinking that you would just look at all the numbers, find the lowest number and put it at the beginning of your list. Then you would find the next largest number and put it in the second spot in the list, and so on until you’ve ordered the entire list of numbers. It’s simple, basic, and not very exciting. Now, let’s say that instead of ordering the list yourself, you decide it’s a better idea to write a computer program to order the list for you. Now you don’t have to deal with moving the numbers around, you just need to tell your program how to move the numbers, and then let the program handle any list you give it.Identify all possible ways of telling your program how to move the numbers, where each way provides the required result.
(Note: The program code is preferred to be in Java)
In: Computer Science
Download labSerialization.zip and unzip it:
ListVsSetDemo.java:
package labSerialization;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Demonstrates the different behavior of lists and sets.
* Author(s): Starter Code
*/
public class ListVsSetDemo {
private final List<ColoredSquare> list;
private final Set<ColoredSquare> set;
/**
* Initializes the fields list and set with the elements
provided.
*
* @param elements
*/
public ListVsSetDemo(ColoredSquare... elements) {
list = new ArrayList<>(Arrays.asList(elements));
set = new HashSet<>(Arrays.asList(elements));
}
/**
* Creates a string that includes all the list elements.
* Each element is followed by a new-line.
*
* @return string of list elements
*/
public String getListElements() {
StringBuilder sb = new StringBuilder();
for (ColoredSquare el : list) {
sb.append(el).append("\n");
}
return sb.toString();
}
/**
* Creates a string that includes all the elements in the set.
* Each element is followed by a new-line.
*
* @return string of set elements
*/
public String getSetElements() {
StringBuilder sb = new StringBuilder();
for (ColoredSquare el : set) {
sb.append(el).append("\n");
}
return sb.toString();
}
/**
* Adds the element <code>el</code> to both the list and
the set.
*
* @param el
*/
public void addElement(ColoredSquare el) {
list.add(el);
set.add(el);
}
}
ColoredSquare.java:
package labSerialization;
import java.awt.Color;
/**
* A square that is defined by its size and color.
* Author(s): Starter Code
*/
public class ColoredSquare {
private final int side;
private final Color color;
/**
* Initializes the fields <code>side</code> and
<code>color</code>.
* @param s the side length of the square
* @param c the color of the square
*/
public ColoredSquare(int s, Color c) {
side = s;
color = c;
}
/**
* Calculates the area of the square.
*/
public int area() {
return side * side;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((color == null) ? 0 :
color.hashCode());
result = prime * result + side;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof ColoredSquare))
return false;
ColoredSquare other = (ColoredSquare) obj;
if (color == null) {
if (other.color != null)
return false;
} else if (!color.equals(other.color))
return false;
if (side != other.side)
return false;
return true;
}
@Override
public String toString() {
return String.format("side:%d #%02X%02X%02X",
side, color.getRed(), color.getGreen(),
color.getBlue());
}
}
LabSerialization.java:
package labSerialization;
import java.awt.Color;
/**
* LabSerialization demonstrates how to serialize and
deserialize
* a custom object that references other objects on the heap.
* Author(s): Starter Code + ........... // fill in your name
*/
public class LabSerialization {
public static void main(String[] args) {
ListVsSetDemo demo = new ListVsSetDemo(
new ColoredSquare(4, Color.RED),
new ColoredSquare(6, Color.BLUE),
new ColoredSquare(4, Color.RED),
new ColoredSquare(8, Color.YELLOW));
displayListAndSet(demo);
};
/**
* Displays the elements of the list and the set.
*/
private static void displayListAndSet(ListVsSetDemo demo) {
System.out.println("List:");
System.out.println(demo.getListElements());
System.out.println("Set:");
System.out.println(demo.getSetElements());
}
}
In class ListVsSetDemo
In class ColoredSquare:
In class LabSerialization:
Sample Output
This sample output should give you a good idea of what is
expected. Note though, that the elements in HashSet are in no
particular order. Because of that, the second part of the output
might look slightly different.
Sample Output
List:
side:4 #FF0000
side:6 #0000FF
side:4 #FF0000
side:8 #FFFF00
Set:
side:6 #0000FF
side:8 #FFFF00
side:4 #FF0000
In: Computer Science
This problem should be solved using the DrRacket software in the Racket/Scheme language.
Consider two techniques for representing a graph as Scheme lists. We can represent a directed graph as a list of edges. We call this representation an el-graph (i.e. edge-list graph). An edge is itself a list of length two such that the first element is a symbol denoting the source of the edge and the second element is a symbol denoting the target of the edge. Note that an edge is a list (not just a pair). For example, the following is a graph: '((x y) (y z) (x z)). We can also represent a graph similar to an adjacency matrix. We call this representation an x-graph (i.e. matrix-graph). In this case, a graph is a list of adjacencies where an adjacency is a list of length two such that the first element is a node (a symbol) and the second element is a list of the targets of that node. For example, the following is a graph: '((x (y z)) (y (z)) (z ())).
- Write function (el-graph->x-graph g), that accepts an el-graph g and returns an x-graph of g.
- Write function (x-graph->el-graph g), that accepts an x-graph g and returns an el-graph of g.
In: Computer Science
Question 1
[multiple answer] a relation in mathematics
Question 2
[multiple answers] in the relational model, relations are commonly used
Question 3
[multiple answers] constraints on relations in normal RDBMSs (not considering MS access)
Question 4
[multiple answers] which of the following constraints can be violated by inserting a record into a database table?
Question 5
[multiple answers] which of the following constraints can be violated through a deletion of a record from a database table?
Question 6
[multiple answers] assume a table A with primary key aid, and a table B with primary key bid and foreign key aid which references aid in table A. Which of the following operations can result in a violation of the referential integrity (foreign key) constraint?
Question 7
[multiple answers] referentially triggered actions
Question 8
[multiple answers] a 1-to-1 relationship in the entity-relationship model can be represented in the relational model
Question 9
[multiple answers] a 1-to-many relationship in the entity-relationship model can be represented in the relational model
Question 10
[multiple answers] a many-to-many relationship in the entity-relationship model can be represented in the relational model
In: Computer Science
This was my prompt, and I'm not quire sure what to do.
1. Circle:
Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis.
The class has two private instance variables: radius (of the type double) and color (of the type String).
The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated.
Construction:
A constructor that constructs a circle with the given color and sets the radius to a default value of 1.0.
A constructor that constructs a circle with the given, radius and color.
Once constructed, the value of the radius must be immutable (cannot be allowed to be modified)
Behaviors:
Accessor and Mutator aka Getter and Setter for the color attribute
Accessor for the radius.
getArea() and getCircumference() methods, hat return the area and circumference of this Circle in double.
Hint: use Math.PI (https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI (Links to an external site.))
2. Rectangle:
Implement a Java class with the name Rectangle. It should be in the package edu.gcccd.csis.
The class has two private instance variables: width and height (of the type double)
The class also has a private static variable: numOfRectangles (of the type long) which at all times will keep track of the number of Rectangle objects that were instantiated.
Construction:
A constructor that constructs a Rectangle with the given width and height.
A default constructor.
Behaviors:
Accessor and Mutator aka Getter and Setter for both member variables.
getArea() and getCircumference() methods, that return the area and circumference of this Rectangle in double.
a boolean method isSquare(), that returns true is this Rectangle is a square.
Hint: read the first 10 pages of Chapter 5 in your text.
3. Container
Implement a Java class with the name Container. It should be in the package edu.gcccd.csis.
The class has two private instance variables: rectangle of type Rectangle and circle of type Circle.
Construction:
No explicit constructors.
Behaviors:
Accessor and Mutator aka Getter and Setter for both member variables.
an integer method size(), that returns 0, if all member variables are null, 1 either of the two member variables contains a value other than null, and 2, if both, the rectangle and circle contain values other than null.
In: Computer Science
I want to make the Main function of this program to only drive. So, make more functions, and change main function to just drive.
This program Dice Game.
Based on this C++ program below:
#include <iostream>
#include <cstdlib>
using namespace std;
int cheater(int computer, int user){
cout<<"Using cheat"<<endl;
if(computer>user)return computer+rand()%2;
if(computer==3 || computer==18)return computer;
if(user>computer)return computer -1;
}
int main()
{
int user, computer,sum,u_diff,c_diff,u_win=0,c_win=0;
int gameCount=0;
bool enableCheat=false;
int lastGameWon=0;
do
{
cout<<"User guess is(1 - 18) :";
cin>>user;
if(user>=3&&user<=18) //the sum of three dice should
be between 3 to 18
{
gameCount+=1;
cout<<"Computer guess is :";
computer=rand()%16+3;
cout<<computer<<endl<<"User guess is :
"<<user<<endl;
cout<<"Sum of the three rolls is :";
sum=rand()%16+3; //rand()%16 will generate the random number
between 0 to 15.
if(enableCheat)sum=cheater(computer,user);
cout<<sum<<endl;
u_diff=user-sum;
c_diff=computer-sum;
if(u_diff<0){
u_diff=u_diff* -1; //u_diff,c_diff is the diffence and it should
always be positive.
}
if(c_diff<0){
c_diff*=c_diff* -1; //if u_diff or c_diff is negetive than we make
it positive.
}
if(u_diff<c_diff){
cout<<"user won\n";
u_win++;
if(lastGameWon+1==gameCount)enableCheat=true;
lastGameWon=gameCount;
} else{
cout<<"computer won\n";
c_win++;
enableCheat=false;
}
cout<<"User won: "<<u_win<<" times.";
}else if(user >= 19 || user <= 0){
cout<<"please enter between 1 to 18\n";
}
}while(user!=-1);
return 0;
}
In: Computer Science
Public static boolean isPalindrome(String word)
* Check to see if a word is a palindrome. Should be
case-independent.
* @param word a String without whitespace
* @return true if the word is a palindrome
Public static int longestWordLength(String words)
* Returns length of the longest word in the given String using
recursion (no loops).
* Hint: a Scanner may be helpful for finding word boundaries. After
delimiting by space,
* use the following method on your String to remove punctuation
{@code .replaceAll("[^a-zA-Z]", "")}
* If you use a Scanner, you will need a helper method to do the
recursion on the Scanner object.
* @param words A String containing one or more words.
* @return The length of the longest word in the String.
* @see Scanner#Scanner(String)
* @see Scanner#next()
* @see String#split(String)
* @see String#replaceAll(String, String)
* @see Math#max(int, int)
In: Computer Science
How does version control fit into the daily activities during a sprint?
In: Computer Science
Send an element from 2d array to a function using pointer to pointer. c++
I am having an issue with being able to send specific elements to the swap function.
#include <iostream>
using namespace std;
void swap(int **a, int **b){
int temp = **a;
**a=**b;
**b=temp;
}
void selSort(int **arr, int d){
for(int i =0; i<d-1; i++){
int min = *(*arr+i);
int minin = i;
for(int j =i+1; j<d; j++){
if(*(*arr+j)
< min){
min = *(*arr+j);
minin = j;
}
swap(*&(arr+i),*&(arr+minin));
}
}
}
int main() {
int array[2][2] = {4,3,2,1},
*ptr = &array[0][0],
**pptr = &ptr;
int size = sizeof(array)/sizeof(int);
for(int i =0; i<size; i++){
cout
<<*(*pptr+i)<<endl;
}
selSort(pptr, size);
for(int i =0; i<size; i++){
cout
<<*(*pptr+i)<<endl;
}
return 0;
}
In: Computer Science
Practice Coding Task
C++ ATM Machine with Some Classes
Create an ATM machine in C++ with a few classes.
Requirements:
Automated Teller Machine (ATM) simulationGiven 3 trials, the user
is able to see his balance by entering a four-digit pin that must
NEVER be displayed on screen but masked by the Asterix (*)
character. A list of pins stored on the file system must be loaded
to verify the pin. The user should be able to withdrawfundsbelow a
set limit and cannot redraw more than 3 times within a space of 5
minutes. The balance from each pin should be determined each time
the program is run and is a random value between 0 and 100. The
user should also be allowed to change his pin at any time which
should be reflected in the file system.
In: Computer Science
Try to make it as simple as you can and explain as much as it needed.
Ans:
Ans:
Ans:
Ans:
Ans:
In: Computer Science
In C language
Please display results
The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b. First let me show the computations for a=210 and b=45.
Divide 210 by 45, and get the result 4 with remainder 30, so 210=4·45+30.
Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15.
Divide 30 by 15, and get the result 2 with remainder 0, so 30=2·15+0.
The greatest common divisor of 210 and 45 is 15.
Formal description of the Euclidean algorithm
Input Two positive integers, a and b.
Output The greatest common divisor, g, of a and b.
Internal computation
1. If a<b, exchange a and b.
2. Divide a by b and get the remainder, r. If r=0, report b as the GCD of a and b.
3. Replace a by b and replace b by r. Return to the previous step.
Your assignment is to write an assembler code (gcd.s) that asks the user two positive numbers and calculates their greatest common denominator.
For example, you program should produce the following outputs:
Enter first positive integer: 6
Enter second positive integer: 8
The GCD is 2
In: Computer Science
Use a switch statement to create a menu with the following options
For now just print a message prompting user for input and allowing them to return the menu. No functionality is required at this time, but save this code for later use.
In: Computer Science
Java queue linked list
/*
* Complete the enqueue(E val) method
* Complete the dequeue() method
* Complete the peek() method
* No other methods/variables should be added/modified
*/
public class A3Queue {
/*
* Grading:
* Correctly adds an item to the queue - 1pt
*/
public void enqueue(E val) {
/*
* Add a node to the list
*/
}
/*
* Grading:
* Correctly removes an item from the queue - 1pt
* Handles special cases - 0.5pt
*/
public E dequeue() {
/*
* Remove a node from the list and
return it
*/
return null;
}
/*
* Grading:
* Correctly shows an item from the queue - 1pt
* Handles special cases - 0.5pt
*/
public E peek() {
/*
* Show a node from the list
*/
return null;
}
private Node front, end;
private int length;
public A3Queue() {
front = end = null;
length = 0;
}
private class Node {
E value;
Node next, prev;
public Node(E v) {
value = v;
next = prev =
null;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class A3Driver {
public static void main(String[] args) {
A3DoubleLL list = new
A3DoubleLL<>();
for(int i = 1; i < 10; i++)
{
list.add(i);
}
System.out.println("Before
Swap");
System.out.println(list.printList());
System.out.println(list.printListRev());
list.swap(4);
System.out.println("After
Swap");
System.out.println(list.printList()
+ ":1,2,3,4,6,5,7,8,9,");
System.out.println(list.printListRev() +
":9,8,7,6,5,4,3,2,1,");
System.out.println();
System.out.println("Hot
Potatoe");
A3CircleLL hotPotato = new
A3CircleLL();
hotPotato.playGame(5, 3);
System.out.println("Correct:");
System.out.println("Removed Player
4\nRemoved Player 3\nRemoved Player 5\nRemoved Player 2\nWinning
player is 1");
System.out.println();
A3Queue queue = new
A3Queue<>();
queue.enqueue(5);
queue.enqueue(20);
queue.enqueue(15);
System.out.println(queue.peek()+":5");
System.out.println(queue.dequeue()+":5");
queue.enqueue(25);
System.out.println(queue.dequeue()+":20");
System.out.println(queue.dequeue()+":15");
}
}
In: Computer Science