Perform the following base conversion using division
and remainder method:4 marks
a) 498base10 to base 3
b) 2458base10 =
c) 961base10
d) 21base10 to base
3 5 9 7
In: Computer Science
2. [50] Write a C program to count the total number of commented characters and words in a C file taking both types of C file comments (single line and block) into account.
In: Computer Science
This program is written by Ruby and Please rewrite this program as python.
input_lines = gets.split(" ")
tasizan = input_lines[0].to_i
hikizan = input_lines[1].to_i
cnt=-0
drill=[]
while cnt<tasizan
kazu1 = rand(100)
kazu2 = rand(100)
next if kazu1+kazu2>99
next if drill.include?("#{kazu1} + #{kazu2} =")
drill.push("#{kazu1} + #{kazu2} =")
cnt+=1
end
cnt=0
while cnt<hikizan
kazu1 = rand(100)
kazu2 = rand(100)
next if kazu1 <= kazu2
next if drill.include?("#{kazu1} - #{kazu2} =")
drill.push("#{kazu1} - #{kazu2} =")
cnt+=1
end
puts drill.sample(tasizan+hikizan)In: Computer Science
Describe the difference between IP and Network Access layer in TCP protocol and also explain the control information embedded in these two layers
In: Computer Science
In: Computer Science
6. Add using binary addition
7. Subtract using binary two’s complement
In: Computer Science
In: Computer Science
this lab, you will write a shell script, called compare_cols.sh. This program should
one two three,four five,six seven,eight,nine six ten,eleven
Bashscript
In: Computer Science
What are IP address classes?
Please explain each class and their characteristics.
In: Computer Science
In: Computer Science
This is the class that needs to be written...
import java.util.ArrayList;
/**
* Deals out a game of 5-card-stud.
*
* @author PUT YOUR NAME HERE
* @version PUT THE DATE HERE
*/
public class FiveCardStud
{
private Deck myDeck;
private ArrayList<Hand> players;
/**
* Constructor for objects of class FiveCardStud
*/
/*
Write a constructor for the FiveCardStud class. The
constructor
accepts a single integer parameter for the number of players.
The number of players should be from 2 to 6 inclusive.
Make sure to take care of values outside of this range.
For numbers less than 2, set the number to 2 and print
an appropriate message. For numbers greater than 6
set the number to 6 and print an appropriate message.
For each player add a hand to the list of players.
Print out the name of the game.
Don't forget to initialize the fields.
*/
/**
* Deal the cards.
*/
/*
Write a method called "deal".
The method should print out a message to let the user know
that the cards have been dealt.
It should remove any old cards from all players hands
from previous games (Hint: there is a fold method in the Hand
class.)
It should then shuffle the deck and add 5 cards to each player's
hand.
*/
/**
* Prints out all player's hands.
*/
/*
Write a method called "showCards".
The method should print out each players hand as shown
in the sample output.
*/
}
These are other classes that are already written and do not need to be changed...
import java.util.ArrayList;
import java.util.Iterator;
/**
* Represents a single player's hand in a card game.
*
* @author Derek Green, Mar. 27, 04
* @revised by Allyson Anderson, Nov.1, 06
*/
public class Hand
{
private ArrayList<Card> hand;// contains this players
cards
/**
* Constructor for objects of class Hand
*/
public Hand()
{
hand = new ArrayList<Card>();
}
/**
* Add a single card to the player's hand.
*/
public void addCard(Card card)
{
hand.add(card);
}
/**
* Clear the player's hand.
*/
public void fold()
{
hand.clear();
}
/**
* Show the player's cards.
*/
public void displayHand()
{
Iterator<Card> it = hand.iterator();
while(it.hasNext())
{
System.out.println((it.next()).getCard());
}
}
}
import java.util.ArrayList;
import java.util.Iterator;
/**
* Represents a deck of 52 playing cards.
*
* @author Derek Green, Mar. 26, 04
* @revised by Allyson Anderson, Nov. 1, 06
*/
public class Deck
{
private final String[] suits = {"Spades ", "Hearts ", "Clubs ",
"Diamonds"};
private final String[] faces = {"Ace", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "Jack", "Queen", "King"};
private Card[] card;
private int topCard;
/**
* Construct a deck of cards
*/
public Deck()
{
card = new Card[52];
topCard = -1;//deal method will increment topCard
for(int i = 0; i < 52; i++)
{
card[i] = new Card(suits[i/13], faces[i%13]);// brand new deck with
all cards in order
}
}
/**
* deal() returns the next card or null if the deck is empty.
*/
public Card deal()
{
topCard++;// set topCard to the next card
if(topCard < 52)
{
return card[topCard];
}
else
{
return null;
}
}
/**
* shuffle() randomly generates a sequence of cards for the card
array
*/
public void shuffle()
{
topCard = -1;// reset the top card
int nextNumber;
boolean[] available = new boolean[52];// used to select random #'s
between 0 and 51 without replacement
for(int i = 0; i < 52; i++)
{
available[i] = true;//all #'s between 0 and 51 are available
}
for(int i = 0; i < 52; i++)
{
nextNumber = (int)(Math.random()*52);// select a # from 0 to
51
while(!available[nextNumber])//while nextNumber is not available
(i.e. this number has already been used)
{
nextNumber = (int)(Math.random()*52);//try a different number until
you find an unused one
}
available[nextNumber] = false;// this number is taken
card[i] = new Card(suits[nextNumber/13],
faces[nextNumber%13]);
}
}
/**
* Print out the entire deck for testing purposes.
*/
public void testDeck()
{
for(int i = 0; i < 13; i++)
{
System.out.println(card[i].getCard() + "\t" + card[i+13].getCard()
+ "\t" + card[i+26].getCard() + "\t" + card[i+39].getCard());
}
}
/**
* Print out a subset of the deck to test the deal method.
*/
public void testDeal(int cardNumber)
{
ArrayList<Card> hand = new ArrayList<Card>();// hold a
hand of cards.
int index = 0;
while(index < cardNumber)
{
hand.add(deal());
index++;
}
Iterator<Card> it = hand.iterator();
while(it.hasNext())
{
Card thisCard = it.next();
System.out.println(thisCard.getCard());
}
}
}
/**
* Represents a single playing card.
*
* @author Derek Green, Mar. 26, 04
* @revised by Allyson Anderson, Nov. 1, 06
*/
public class Card
{
private String suit;
private String face;
/**
* Constructor for objects of class Card.
*/
public Card(String suit, String face)
{
this.suit = suit;
this.face = face;
}
/**
* Returns the suit of the card
*/
public String getSuit()
{
return suit;
}
/**
* Returns the face of the card
*/
public String getFace()
{
return face;
}
/**
* Returns the suit and face of the card as a single String
*/
public String getCard()
{
return face + "\t" + suit;
}
}
In: Computer Science
Radix sort
Come up with an unsorted array of numbers (integer array). Sort the
numbers in ascending order and descending order and display them
using radix sort.
First sort in ascending, then reset the array to its original order
and finally sort the array again in descending order.
C++ program
thanks
In: Computer Science
Write a JAVA program that allow a user to enter 2 number, starting point and end point. For example a user me enter 1 and
100. Your program will
Add numbers from 1 to 100, add all the even number, and add all the odd numbers
Output:
The sum of number 1 to 100 is:
The sum of even number 1 to 100 is:
The sum of odd number 1 to 100 is:
In: Computer Science
Hi. Are you familiar with deunions? The objective of the task is to undo the last union operation in a weighted quick-union find implementation, of which I have partly written here (see below). I push the unions on a stack. The code is not finished though, and far from perfect. Can you point out my mistakes and figure out how to create the deunion-operation correctly?
Best regards,
Eirik
public class UFwithDeunion {
private int[] id; //parent link (site indexed)
private int[] sz; // size of component for roots (site indexed)
private int count; //number of components
Stack stack = new Stack();
//maa bruke weighted-quick union for at det skal kjoere i ¨log N kjoeretid
public UFwithDeunion(int n) {
count = n;
id = new int[n];
for (int i = 0; i < n; i++)
id[i] = i;
}
//set the total number of elements
public static int setSize(int n){
sz = new int[n];
for (int i = 0; i < n; i++)
sz[i] = 1;
}
//return an identifier for the set containing a
public static int find(int a){ //follow links to find a root
while (a != id[a])
a = id[a]; //pop
return a;
//merge the set containing a with the set containing b
public static void union(int a, int b){
int i = find(a);
int j = find(b);
if (i == j) return;
//make smaller root point to larger one
if (sz[i] < sz[j]) {
id[i] = j; sz[j] += sz[i];
stack.push(id[i]);
}
else {
id[j] = i; sz[i] += sz[j];
stack.push(id[j]);
}
}
// undo the last union operation
public static void deUnion(){
stack.pop();
//sz--;
}
//Return the number of elements in the set containing a
public static int elementsInSet(int a){
int sum = 0;
for (int i : id) {
if (a == id[i])
sum++;
}
return sum;
}In: Computer Science
MATLAB Question
Write a script to plot the function 'x times sine-squared of x' over a user-specified interval. It should prompt the user to enter the starting and stopping values of x, perform the calculation, and plot the result. Test the script using start/stop values 28 and 42.
In: Computer Science