Program: Drawing a half arrow
This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width.
(1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt)
(2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow base. (1 pt)
(3) Modify the given program to use a loop to output an arrow head of width arrowHeadWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow head. (2 pts)
(4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width. (1 pt)
while (arrowHeadWidth <= arrowBaseWidth) {
// Prompt user for a valid arrow head value
}
Example output for arrowBaseHeight = 5, arrowBaseWidth = 2, and arrowHeadWidth = 4:
Enter arrow base height: 5 Enter arrow base width: 2 Enter arrow head width: 4 ** ** ** ** ** **** *** ** *
In: Computer Science
5.24 (Diamond Printing Program) Write an application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single new- line character. Maximize your use of repetition (with nested for statements), and minimize the number of output statements."
Example for 2.24:
*
***
*****
*******
*********
*******
*****
***
*
In: Computer Science
Need these written in Java script please
Problem 1:
Given an array A[0 ... n-1], where each element of the array represents a vote in the election. Assume that each vote is given as integers representing the ID of the chosen candidate. Write the code determining who wins the election.
Problem 2:
How do we find the number which appeared maximum number of times in an array?
In: Computer Science
PLEASE CREATE A PROGRAM IN PSEUDOCODE AND C#
Back in my Day! Kids who grew up in the late 70s didn’t have a lot of options for video games, but they did have “Choose your own Adventure” books. These books were cool and let the reader make meaningful decisions. If they chose choice “A”, they would turn to a page of the book and continue their adventure. If they chose choice “B”, they would turn to a different page and read a different adventure. Your task is to design (pseudocode) and implement (source code) for a story that has four different outcomes based on two different user inputs. See appendix for checking string equality.
Sample run 1:
It is a dark and stormy night. Do you want to take an umbrella? (Y/N): Y
Good - you have an umbrella.
You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your umbrella or run? ((F)ight/(R)un): F
You take out your umbrella and jab it into the wolf's paw! It runs away and you live another day.
Sample run 2:
It is a dark and stormy night. Do you want to take an umbrella? (Y/N): Y
Good - you have an umbrella.
You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your umbrella or run? ((F)ight/(R)un): R
You begin running so fast, the umbrella opens and you fly away like Mary Poppins. You're a little embarrassed, but you see the wolf fading off in the distance.
Sample run 3:
It is a dark and stormy night. Do you want to take an umbrella? (Y/N): N
You decide not to take an umbrella.
You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your hands or run? ((F)ight/(R)un): F
You begin fighting the wolf only to realize you had just eaten a McGrease® meal earlier. You fall dead from rigorous exercise, having had a heart attack.
Sample run 4:
It is a dark and stormy night. Do you want to take an umbrella? (Y/N): N
You decide not to take an umbrella.
You start to walk down a path and hear a scream. You realize that the person screaming is YOU because you see a wolf! Do you fight with your hands or run? ((F)ight/(R)un): R
Are you serious? You can't outrun a wolf! The wolf catches you and you are somewhat relieved because you don't have to worry about that Calculus exam…
In: Computer Science
What is the proper way to define an assembly code in in-line assembler x86 for this case:
multiplication without using mul/imul, using hexadecimal numbers for "shl" instruction.
In: Computer Science
The following functions have been calculated as the runtime complexity of various algorithms. Identify the Big-O complexity, and provide witness values to support your answer. Clearly highlight your answer and show any working out you do.
i. f(n) = 13 + 3n2 – 9n ii.
f(n) = 3n.log2n + 7n
iii. f(n) = nn + 2n5 – 7
iv. f(n) = 2log2n + 4n
v. f(n) = 20 + 2n4 – n2 +n
vi. f(n) = 7n3/4 +3n
In: Computer Science
If you execute the code shown below and the user enters the
following sales amounts for Region 1: 25000, 30000, 10000, –1,
then, the value stored in totRegSales when the inner loop ends will
be __________.
int sales = 0;
int region = 1;
int totRegSales = 0;
while (region < 3)
{
cout << "First sales amount for Region "
<< region << ": ";
cin >> sales;
while (sales > 0)
{
totRegSales = totRegSales + sales;
cout << "Next sales amount for Region "
<< region << ": ";
cin >> sales;
} //end while
cout << endl << "Region " << region << " sales: $"
<< totRegSales << endl << endl;
region = region + 1;
totRegSales = 0;
} //end while
cout << "End of program" << endl;
65000
55000
-1
0
In: Computer Science
Write a FORTRAN program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average.
An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade is any score that is not an F, but is at least 10% less than the average. Any scores that are within 10% of the average (either less than or greater than) are C's.
In: Computer Science
In: Computer Science
Define the following key terms
1. Routing
2. Connectionless
3. Best-effort delivery
4. Maximum transmission unit (MTU)
5. Fragmentation
6. Internet Control Message Protocol (ICMP)
7. Network Address Translation (NAT)
8. Media independent
9. Loopback interface
10. Default gateway
In: Computer Science
1) Represent -34 and +67 in the following ways: a) 8 bit sign and magnitude representation with MSB as sign bit. b) 8 bit 1’s complement representation. c) 8 bit 2’s complement representation. 2) Convert the decimal numbers 40 and 20 into 8-bit unsigned binary representation and add the two numbers.
In: Computer Science
Python Chemicals can be described as either acids or bases. The pH scale measures the concentration of hydrogen ions in a chemical to determine just how acidic or basic it is. For this task you are going to determine whether a chemical is acidic or basic based on its pH value, and how strongly it has that property. Remember, don't call input() or print() anywhere, just use the parameters provided and return statements.
You must have at least one conditional in each function. You cannot import any module. A couple of the tasks have individual restrictions; note them, as we will remove points for any task that does not follow the requirements.
def chemical_strength(pH): Accepts one floating point parameter for the pH value, and then:
Determines if the pH value is valid (pH must be between 0 and 14 inclusive).
You’ll return the string "bad measurement" if pH value doesn't make sense.
Determines a description of the chemical based on its pH value.
o A pH of less than 7 is an acidic chemical, however, we will be more specific:
▪ a pH value less than or equal to 1 is a "very strong
acid"
▪ a pH value between 1 and 4 (exclusive) is a "strong acid"
▪ a pH value of exactly 4 is a "plain acid"
▪ a pH between 4 and 6 (exclusive) is a "weak acid"
▪ a pH value greater than or equal to 6 is a "very weak
acid"
o A pH of more than 7 is a basic chemical, however, we will be more
specific:
▪ a pH value less than or equal to 8 is a "very weak base"
▪ a pH value between 8 and 10 (exclusive) is a "weak base"
▪ a pH value of exactly 10 is a "plain base"
▪ a pH value between 10 and 13 (exclusive) is a "strong base"▪ a pH
value greater than or equal to 13 is a "very strong base"
o If the pH is exactly 7, the chemical is simply "neutral"
Returns the strength description as a string, e.g. "weak acid", "very strong base" etc.• Examples:
o #pH is in between 4 and 6
chem_strength(4.7) → 'weak acid'
o # pH is outside of the valid pH range chem_strength(15.43) → 'bad measurement'
In: Computer Science
Using the pumping lemma for regular languages, show that
language is not regular.
b) L3= {0n 1m, m = n+2 } Language= {0,1}
In: Computer Science
Let's look at the auditing system in Windows Server 2008. What are the characteristics? How do you set it up?
In: Computer Science
This game is simpler than the normal game of war, but the object is to have a card with a higher value than the dealer. The user makes a bet. Then, both the user and the computer draw a card. If the user’s card has a larger value than the computer’s card, then the user wins, and gets the value of their bet added to their total. Otherwise, the computer wins, and the user loses their bet. After each round, discard the cards. Keep playing until the user runs out of money, or until they say they don’t want to play anymore.
Card class - the class representing a single card in a deck. Every card has three properties. The first is a “suit,” which is either “Hearts”, “Diamonds,” “Spades”, or “Clubs”. A card also has a color, where Hearts and Diamonds are red, and Spades and Clubs are black. Finally, each card has a value from 1-13 (inclusive). Some values have special names: the 1 is an Ace, 11 is a Jack, 12 is a Queen, and 13 is a King.
Your first job is to design a class for a card, with each of these properties. It should have these methods:
public Card(int value, String suit) - initializes the Card and it’s variables. For example, Card(12, “Hearts”) will create a red 12 of hearts.
public int getValue( ) - returns value of the card
public String getColor( ) - returns color of the card
public String getSuit( ) - returns suit of the card
public String toString() - returns string representation of the card, E.G. “King of Hearts.”
Or “7 of clubs”
DECK CLASS
In an entire deck, there are 52 cards, each of the 13 values for the four different suits. You should implement a class to handle all of the logistics of the deck, so that as a user of the class, all you have to do is pick cards from the deck, and then discard them once you’re done with them. This class has a bit more logic in it, so here’s what you have to do.
public Deck()
This method will initialize the deck - creating an array of each of the 52 possible cards. After generating them, you should also shuffle them in the array (shuffling method is defined below). This method should also initialize a discard pile array, which currently has nothing in it. You may want to initialize other variables too, to assist with your other methods.
public void shuffle()
This method shuffles all of the items in the deck. You can be creative with your shuffling algorithm, but I suggest you implement this one (the first algorithm under “The Modern Algorithm”). This is in “pseudo code,” which means it’s not in a real programming language, so it will be your job to convert this into real java code. Make sure if there are some “null” elements in your deck, that you don’t shuffle them into the deck.
public Card drawNextCard()
This method will give you the next card in the deck. Initially, this will be the card at index 0, then index 1, then index 2... up until index 51. After index 51, drawNextCard should take all of the cards in the discard pile, put them in the deck array, empty the discard pile, shuffle them, and then return the first one.
public void discard(Card c)
This method will add the card into the discard pile. Initially it will add the card to the first index of the discard pile, then the second index, etc...
Hints:
Remember that assignments for Arrays are by reference. If you want the deck to be a copy
of everything in the discard pile, you can just do:
currentDeck = discardPile.clone();
Then to empty the discard pile, you can just say: discardPile = new
Card[52];
Be careful with shuffling that you don’t accidentally shuffle “null” objects into the deck. This won’t happen in the beginning when the deck is full, but when you’re making the contents of the discard pile into the new deck, there will probably be some “null” elements at the end.
Feel free to add any other methods to these classes.
CLIENT CODE
Once you have these classes done, and have tested them to make sure they work, you can start using these objects to write the game in our casino, in a new file Casino.java.
you should have a main method that allows the users to play these games. There are many choices that are left up to you regarding the design of the game. For example, what do you do when the user runs out of money. How do you decide how much the user starts with? Will you implement a betting minimum and maximum?
In: Computer Science