Python - Please include running time of push(), pop(), and top() methods and tester code for all methods.
Design a stack ADT using a single queue as an instance variable, and only constant additional local memory within the method bodies. What is the running time of the push(), pop(), and top() methods for your design? Implement your modified stack ADT in Python, including tester code to test all its methods.
In: Computer Science
Write a C program that would constantly watch all processes (say once every second), and if it encountered a notepad, it would kill it immediately.
In: Computer Science
When it comes to the passphrase (pre-shared key) for WPA, what would you personally advise when it comes to length? How should one create the passphrase? Please also provide some quantitative justification as well, that is important. Thank you.
In: Computer Science
Create a Java program that allows two players to play Rock,
Paper, Scissors. Player 1 will enter an integer to determine
whether they use rock, paper or scissors. Player 2 will also enter
an integer to determine whether they use rock, paper or scissors.
Use named constants for rock, paper and scissors and set their
values as shown below. Use if-else statements to determine the
results of the game. Use the named constants to compare with the
player 1 and player 2 choices rather than hardcoding the numbers.
Make sure to close your Scanner at the end of your program to avoid
losing a point. When run, the program should look like the
screenshots shown below.
Named constants:
ROCK = 1
PAPER = 2
SCISSORS = 3
Name your Java program RockPaperScissors.java and submit it to
Canvas along with the other files specified in the “Grading”
section below. Make sure your program compiles before submitting it
to avoid losing points.
Example 1:
Player 1 chooses rock.
Player 2 chooses paper.
Player 2 wins!
In: Computer Science
Write a C program called cards.c that simulates some card game logic by comparing the cards from 4 people and determining which person has the best card. The program MUST work as follows:
Eachcardmustberepresentedbyexactlytwocharsrepresenting a rank and a suit. The possible rank options are: '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'. The possiblesuit options are: 'H', 'D', 'S', 'C'. So 6H represents the “6 of hearts”, JC represents the “Jack of Clubs” etc...
YouMUSTwriteafunctioncalledisValidRank(charc)which determines if the given character is one of the ranks mentioned above. It should return a char with a value of 1 if the character is a valid rank and 0 otherwise. Lowercase letters are not valid.
YouMUSTwriteafunctioncalledisValidSuit(charc)whichdeterminesifthegivencharacter is one of the suits mentioned above. It should return a char with a value of 1 if the character is a valid suit and 0 otherwise. Lowercase letters are not valid.
You MUST have a function called getTrump() that returns a char. It should prompt the user for a trump suit, which must be 'H', 'D', 'S' or 'C'. It should be robust, in that any invalid input is not accepted. It should only return from the function when a valid suit has been entered, and it must make use of the isValidRank() function. For any invalid entry, an appropriate error message should be given. Blank entries are invalid and so are lowercase letters.
The main function should first get the trump suit, by calling the above function. It should then enter an infinite loop to do the following: (1) ask for 4 cards from the user, (2) display the 4 cards entered, (3) determine and display which player wins the round (i.e., which one has the “best” card). These steps will be explained below.
6. Whenenteringthecards...yourcode should be robust and handle any input, just like you did in thegetTrump() function. For each of the 4 cards entered, your code should allow the user to enter two characters and then press enter. If the first character (i.e., the rank) is invalid (use the function you wrote earlier), then an appropriate error message should be displayed and the second character (i.e., the suit) should not be prompted for. If it was valid, then the suit character should be prompted for.
Player 1: Enter card
rank andRC
Invalid card, please re-enter Player 1: Enter card rank and4F
Invalid card, please
re-enter Player 1: Enter card rank and6
Invalid card, please re-enter Player 1: Enter card rank andH
Invalid card, please
re-enter Player 1: Enter card rank andJC
Player 2: Enter card rank and6S
Player 3: Enter card rank and
suit (e.g., 2S, TC, KD)
suit (e.g., 2S, TC, KD)
suit (e.g., 2S, TC, KD)
suit (e.g., 2S, TC, KD)
suit (e.g., 2S, TC, KD) suit (e.g., 2S, TC, KD) suit (e.g., 2S, TC, KD)
suit (e.g., 2S, TC, KD)
suit (e.g., 2S, TC, KD) suit (e.g., 2S, TC, KD)
is invalid, another
error message
should be shown. Either way, the
code should keep prompting until a
valid card is entered before moving on
to get the next player’s card. Here is
an example of what you should do à 5H
If it
Invalid card, please
re-enter Player 3: Enter card rank and9d
Invalid card, please re-enter Player 3: Enter card rank and9D
Player 4: Enter card rank and
Once4validcardentrieshavebeenentered,the4cardsshouldbedisplayedlikethis:
JC, 6S, 9D, 5H
You must then determine which card wins the round. That is, which player has the best card. To do this, you must follow these rules:
A card which is of the trump suit always beats a card that is a non-trump suit.
If two cards have the same suit, the one with the higher rank is better. 'A' is the highest
rank and '2' is the lowest.
The card played by player 1 is called the “suit led”. If no other player has a higher ranking card of the same suit as the suit led, and no other player has the trump suit, then player 1 has the best card and wins.
Inyourmainfunction,iftherankofthefirst(orany)playerisa'.'character,thentheprogram should quit. The TA’s will need this functionality in order to test your program.
Show transcribed image text
View comments (1)
In: Computer Science
(1) Convert negative fractional decimal number to 8-bit binary number: – 6.625
Hint: –7 + 0.375
Given the hint above, the fractional number will be divided into
two parts,
- Whole number,
- Fractional part, must be positive
(2) Use 2's complement binary format to convert negative fractional decimal number to 8-bit binary number: – 6.625
(3) Proof to check that your representation calculation for (1) & (2) is correct
In: Computer Science
The Objective is to create a Custom LinkList.
Implement the
following methods
Class Name: CustomLinkList
Methods
void insert (String data) – insert it the item to the
last row void delete() - Deletes the last row
boolean exists() - returns a Boolean if found
String[] toArray()
String getTail() – returns the last record
String getHead () – return the 1st record
Extra Credit
int delete (String data) – delete an item in the
link by position. If an item is successfully
the delete method return the number 1, else return the number 0
In: Computer Science
Code is only reading the last line from the text files. How would I resolve? This is for the Name Search problem in Starting out with Python book. def main(): #open a file for reading infile = open('GirlNames.txt' , 'r') #Read the contents into a list Girls = infile.readlines() #open another file for reading infile = open('BoyNames.txt', 'r') #Read the contents into a lits Boys = infile.readlines() #Get a name to search for Name = input('Enter a name: ') #Determine if name is in list if Name in Girls or Name in Boys: print( Name, "is one of the popular names.") else: print(Name, "was not found in the list.") main()
In: Computer Science
Describe and discuss the benefits and drawbacks of environmental design.
In: Computer Science
Convert the hexadecimal number BAD D00D 60E5 F00l to binary, octal, base-4. Show your work.
In: Computer Science
In: Computer Science
#include<iostream>
using namespace std;
void calcSumAndDiff(int ,int, int &, int &);
void calcSumAndDiff(int n1,int n2, int &sum, int &diff){
sum = n1 + n2;
diff = n1 - n2;
}
int main()
{
int n1,n2,sum,diff;
n1=30;n2=10;
calcSumAndDiff(n1,n2,sum,diff);
cout<<"Sum is
:"<<sum<<endl;
cout<<"Diff is:"<<diff<<endl;
system("pause");
}
In: Computer Science
Write an algorithm in pseudo code to find one element and delete it in a doubly linked list. Your algorithm will print the original list, request the user to put in an element to be deleted, then print the final list after the deletion is done. If the element doesn’t exist in the list, print "XXX is not in the list" where "XXX" should be the one you received from the user.
Use the following as your test cases to evaluate whether your algorithm works correctly:
if you have a linked list: 3<->2<->0,
with user input 5, your algorithm should print "5 is not in the list".
with user input 2, your algorithm should print "3<->0".
if your linked list is empty, with user input 5, your algorithm should print "5 is not in the list".
In: Computer Science
[C++]
Write an algorithm to transfer the elements from queue Q1 to queue Q2, so that the contents in Q2 will be in reverse order as they are in Q1 (e.g. if your queue Q1 has elements A, B, and C from front to rear, your queue Q2 should have C, B, and A from front to rear). Your algorithm must explicitly use an additional stack to solve the problem. Write your algorithm in pseudo code first.
In: Computer Science
Requirements: You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following:
Data:
Constructors:
throw new IllegalArgumentException(<”your meaningful String here”>);
If it is OK, the it should initialize the data (of the new instance being created) to be the same as the Point that was received.
Methods:
public class Point implements PointInterface
When your Point.java compiles, Java will expect all methods in the interface to be implemented and will give a compiler error if they are missing. The compiler error will read “class Point is not abstract and does not implement method ”.
You can actually copy the PointInterface methods definitions into your Point class so it will have the comments and the method headers. If you do this, be sure to take out the ; in the method headers or you will get a “missing method body” syntax error when compiling…
public interface PointInterface
{
// toString
// returns a String representing this instance in the form (x,y)
(WITHOUT a space after the ,)
public String toString();
// distanceTo
// throws a new IllegalArgumentException(
if null is received
// returns the distance from this Point to the Point that was
received
// NOTE: there is a static method in the Math class called hypot
can be useful for this method
public double distanceTo(Point otherPoint);
//equals - returns true if it is equal to what is received (as an Object)
public boolean equals(Object obj);
// inQuadrant
// returns true if this Point is in the quadrant specified
// throws a new IllegalArgumentException if the quadrant is
out of range (not 1-4)
public boolean inQuadrant(int quadrant);
// translate
// changes this Point's x and y value by the what is received (thus
"translating" it)
// returns nothing
public void translate(int xMove, int yMove);
// onXAxis
// returns true if this Point is on the x-axis
public boolean onXAxis();
// onYAxis
// returns true if this Point is to the on the y-axis
public boolean onYAxis();
//=============================================
// The method definitions below are commented out and
// do NOT have to be implemented
// //===========================================
// halfwayTo
// throws a new IllegalArgumentException(
if null is received
// returns a new Point which is halfway to the Point that is
received
//public Point halfwayTo(Point another);
// slopeTo
// throws a new IllegalArgumentException(
if null is received
// returns the slope between this Point and the one that is
received.
// since the slope is (changeInY/changeInX), then first check to see if
changeInX is 0
// if so, then return Double.POSITIVE_INFINITY; (since the
denominator is 0)
//public double slopeTo(Point anotherPoint)
}
In: Computer Science