Complete the function, MycountWords in C++, which will count the number of words in a string. We will have different word separators(such as newline(\n), spaces, special symbols(? | \ , . : ;) ) That will separate the words in the giving istringstream. Remember if a words is separated by a hyphen and followed by a new line, they're still one word. The function has an option to be sensitive to case and also avoid duplicates. for duplicates, this is a boolean value that checks whether a word is repeated or not if its set to true and sensitive case is if the word count is sensitive to case and differentiates two words based on their case. even though they have different cases, they are the same word hence duplicates.
complete this function based on the description above.
unsigned int MycountWords(istringstream & iss, bool Duplicate=false, bool SenstiveCase =false) {
}
In: Computer Science
Questions about logic.
Please Solve them ALL! (I have the right to ask the last question.)
Please write in a legible and annotated way, thank you.
Q1A)
Let P(x) be the statement “x can swim” and let Q(x) be the
statement “x can play the guitar.” Express each of these sentences
in terms of P(x), Q(x), quantifiers, and logical connectives. The
domain for quantifiers consists of all students in your
school.
a) No student in your school can swim or can play the guitar.
b) Every student in your school either can swim or can play the
guitar.
c) There is a student in your school who can swim and who play the
guitar.
d) There is a student in your school who can swim but who cannot
play the guitar.
Q1B)
Translate in two ways each of these statements into logical
expressions using predicates, quantifiers, and logical connectives.
First, let the domain consist of the students in your class and
second, let it consist of all people.
a) Everyone in your class has a computer.
b) Somebody in your class has seen a foreign movie.
c) There is a person in your class who cannot play the
guitar.
d) All students in your class can program.
e) Nobody in your class wants to have the flu.
In: Computer Science
UsePython (import numpy as np) use containers (Branching if statement, while loop, for loop, numpy Array)
Implement an algorithm to guess a random number that the computer generates. The random number must be an integer between 1 and 1000 (inclusive). For each unsuccessful attempt, the program must let the user know whether to deal with a higher number or more. low. There is no limit on the number of attempts, the game only ends when the user succeeds. The user starts the game with $ 1000 and for each unsuccessful attempt loses $ 100. If you repeat any number of those who had already entered, they lose $ 200 instead of $ 100. If you don't follow the immediate instruction, you lose $ 200 instead of $ 100 (for example, if the program says to try a higher number, but you enter a higher number low to the previous one). In each unsuccessful attempt the program must tell the user how much money he has left (the figure can be negative). If the user hits the number and still has money, the program should congratulate him and tell him how much he won. If the user hits the number and owes money, the program must “bully” him and charge him. If the user hits the number by closing at $ 0 (neither wins nor owes), the program must let them know. In your report present 4 "print screens" of the execution of your program that result in 4 different results and their respective desktop tests (note that this is a special case where you have to run the program before the desktop test as there is no way I can control the random number that will come out in each run).
In: Computer Science
QUESTION 1
Which of the following programming languages does NOT support parametric polymorphism?
Java |
||
C++ |
||
Python |
||
C# |
10 points
QUESTION 2
Which of the following programming languages does NOT support operator overloading?
C# |
||
Python |
||
C |
||
C++ |
10 points
QUESTION 3
In a language that allows nested subprograms, the programming language has to choose a referencing environment for the executing the passed subprogram when a subprogram is passed as a parameter. Which of the following is NOT a choice?
just in time binding |
||
shallow binding |
||
ad hoc binding |
||
deep binding |
10 points
QUESTION 4
Which of the following is necessary for recursion to take place via subprogram calls?
static local variables |
||
stack dynamic local variables |
||
type checking |
||
returning values from a function |
10 points
QUESTION 5
Which of the following is NOT a concern when corresponding the actual parameters to the formal parameters?
default parameters |
||
variable number of parameters |
||
return type |
||
positional parameters v. keyword parameter |
10 points
QUESTION 6
Which of the following is NOT an inout mode of parameter passing?
pass by reference |
||
pass by result |
||
pass by name |
||
pass by value-result |
10 points
QUESTION 7
Which of the following is never used to distinguish between two subprograms in any programming language?
return type |
||
subprogram name |
||
parameter names |
||
parameter profiles |
10 points
QUESTION 8
Which of the following types of subprograms exhibit ad hoc polymorphism?
OOP languages |
||
generic subprograms |
||
overloaded subprograms |
||
typeless languages |
10 points
QUESTION 9
In which type of language is a closure never necessary?
static scoped language that does NOT support nested subprograms |
||
dynamically scoped language that does NOT support nested subprograms |
||
static scoped language that does support nested subprograms |
||
dynamically scoped language that does support nested subprograms |
10 points
QUESTION 10
In what way are coroutines the same as all other programs?
only one coroutine is actually in execution at any given time |
||
multiple entry points |
||
have control statements which suspend execution of the subprogram |
||
maintain their status between executions |
10 points
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
In: Computer Science
What is the complexity of the given code as a function of the problem size n? Show all of the details of your analysis.
for (int i = 0; i < 2*n; i++)
{
if (i == n)
{
for (int j = 0; j < i; j++)
for (int k = 0; k < i; k++)
O(1)
}
else
{
for (int j = 0; j < i; j++)
O(1)
}
}
In: Computer Science
Part E (3 marks): What is the shape of a BST that is O(n) to delete the root? Draw an example with at least 8 nodes.
In: Computer Science
In: Computer Science
Using python programming language, compare the four tasks.
1. For the following exercises you will be writing a program that implements Euler’s method (pronounced ‘oy-ler’). It may be the case that you have not yet encountered Euler’s method in the course. Euler’s method can be found in Chapter 10.2 of your notes, which gives a good description of why this algorithm works. But for our purposes, we only need to know the algorithm itself - so there’s no need to worry if you are yet to understand it.
Euler’s method is used to approximate a function when only the derivative and a particular value is known. Given an initial value y and a corresponding x value, a derivative f’(x), and a step size h, the next value for y is calculated using the following formula:
next y = current y + f'(x)*h
If you want to calculate more steps, just reuse the formula but with your new y value. The new x value is also updated to x+h.
Task: To start, write a function called fdash(x), that returns the value of the derivative at x. The formula for the derivative which we will be using as a placeholder is:
fdash = 0.05x * e^(0.05x)
Round the output to 5 decimal places. Do not print anything, call your function, or ask for any input.
2. Recall the formula for Euler’s method is:
next y = current y + f'(x)*h
Task: Write a function called onestep(x, y, h) that calculates the next y value using Euler’s method with the given x, y and h values. The derivative is the same as used in the previous exercise. Copy paste your function from the previous exercise and use it in your onestep function.
Round the output to 5 decimal places. Do not print anything, call your onestep function, or ask for any input. You should have two functions defined in your code (onestep and fdash).
3. Recall that after one step of Euler’s function is calculated, the new x value is also updated to x+h. Note that it happens in that orde.r First the next y value is found, then the corresponding x value is updated.
Task: Write a function called eulers(x, y, h, n) that uses euler’s method n times with the given x, y and h values. It will return the final y value. Remember to copy paste your onestep and fdash functions. You are encouraged to use them in your eulers function, but it is up to you.
The fdash and onestep functions already round their output, so you will not need to do any rounding inside the eulers function.
Hint: One way of implementing this function is to use a while loop.
If you need help with Euler’s method:
The following example of Euler’s method is given in case you do not understand how it works with multiple steps:
F dash: 2x + 2
Initial x: 1
Initial y: 4
Step size (h): 0.5
Number of steps (n): 3
Step 1:
Fdash = 2*1 + 2 = 2 + 2 = 4
Value of y at step 1: new y = 4 + 4*0.5 = 4 + 2 = 6
New x value = 1 + 0.5 = 1.5
Step 2:
Fdash = 2*1.5 + 2 = 3 + 2 = 5
Value of y at step 2: new y = 6 + 5*0.5 = 6 + 2.5 = 8.5
New x value = 1.5 + 0.5 = 2
Step 3:
Fdash = 2*2 + 2 = 4 + 2 = 6
Value of y at step 3: new y = 8.5 + 6*0.5 = 8.5 + 3 = 11.5
New x value = 2 + 0.5 = 2.5
So our final value for y is 11.5 after 3 steps (at x = 2.5). For interest, one function with this derivative is y = x**2+2*x+1. At x = 1, y is equal to 4, like in this example. At x = 2.5 (which is our final x value), the value of y is 12.25. This is pretty close to our approximated value of 11.5.
4. An asteroid has been spotted travelling through our solar system. One astrophysicist has predicted that it will collide with Earth in exactly 215 days, using a new method for modelling trajectories. The researcher has asked you and others to verify their claim using a variety of methods. You have been tasked with modelling the asteroid’s trajectory using Euler’s method.
For an asteroid to collide with Earth, it needs to have the same x, y, and z coordinates as the Earth in 215 days (x, y, and z represent the three dimensions. Because solar systems are three dimensional!). If any of the final predicted x, y, and z values are different to the Earth’s, then that will mean the asteroid will not collide with Earth in 215 days.
It has already been proven that the asteroid will have the same x and z coordinates as Earth in 215 days. So, you only need to worry about the y dimension.
The equation for the change in y at day t after the asteroid was discovered is:
y'(t) = (-0.05t+5)*exp(0.002t)*0.05
In other words, this equation is the derivative of y(t). The starting y position of the asteroid is 160.195 million kilometers, which occurs at t = 0. The y position of Earth in 215 days (t = 215) is 150 million kilometers.
Task: Write a function called will_it_hit(h), that returns the number 1 if the asteroid is going to hit Earth in 215 days, and 0 otherwise - along with the Euler’s method prediction of the asteroid’s y poistion.
The Earth will be considered ‘hit’ if the asteroid gets within 0.01 million kilometers of Earth (so abs(earthy - asteroidy)<=0.1). The input for the function is h, which indicates the step size in days. So h = 0.5 indicates that there are two steps of Euler’s method per day, resulting in 215/0.5 = 530 steps of Euler’s method.
As with the previous exercises, the output for the fdash and onestep functions should be rounded to 5 decimal places.
Use your code from the previous exercises. The only thing you will need to change is fdash. We have written tests for each of your functions (fdash, onestep, eulers, will_it_hit), to help you understand where errors might be. Good luck!
Note: All units for the y location of the asteroid should be in millions of kilometers. For example, will_it_hit(5) should give output (0, 151.72445).
In: Computer Science
please do it in C++, will up vote!! please add snap shots of result and explanation.
You are to create a recursive function to perform a linear search through an array.
How Program Works
Program has array size of 5000
Load values into the array, equal to its index value. Index 5 has value 5, index 123 has value 123.
Pass array, key, and size to the recursive function:
int recursiveLinearSearch(int array[],int key, const int size, bool & methodStatus)
User enters key to search for, recursive function calls itself until the key is found (methodStatus is true), print out the key and number of function calls when control is returned to the main
Handle situation of key not found (return number of function calls AND methodStatus of false) – print not found message and number of calls in the main
Function returns a count of how many recursive calls were made
Value returned is the number of calls made to that point, that is, when item is found the value returned is 1 with preceding functions adding 1 to the return value until the actual number of recursive function calls are counted).
Determine smallest key value that causes stack-overflow to occur, even if you need to make array larger than 5000.
Test cases need to include, biggest possible key value, “not found” message, and a stack overflow condition.
In: Computer Science
in java
Write a class named “Stock” to model a stock. The properties and
methods of the class are shown in figure below. The method “
percentage ” computes the percentage of the change of the current
price vs the previous closing price. Write a program to test the
“Stock” class. In the program, create a Stock object with the stock
symbol SUND, name Sun Microsystem V, previous closing price of 100.
Set a new current price randomly and display the price
percentage.
Stock
private String symbol
private String name
private double previousClosingPrice
private double currentPrice
public Stock()
public Stock(String symbol, String name)
public String getSymbol()
public String getName()
public double getPreviousClosingPrice()
public double getCurrentPrice()
public void setSymbol(String symbol)
public void setName(String name)
public void setPreviousClosingPrice(double price)
public void setCurrentPrice(double price)
public double percentage()
In: Computer Science
Cryptography-
Run S-DES with key: 1000100111 and plaintext: 01010101
In: Computer Science
Discuss some major problems and issues that can cause (a) network design in general, and (b) LAN design in particular, to fail.
In: Computer Science
Count all nonzero elements, odd numbers and even numbers in a linked list.
Code needed in java through single linked list.
In: Computer Science
JAVA PROGRAM Overview :
You will create a card deck program that allows the player to shuffle a deck of cards and play a game that draws and plays cards until all cards in the deck have been used.
Instructions:
The application must be able to perform the following tasks :
1. At the start of a new game, it shuffles all cards using a deck shuffler
2. The player then draws X number of cards from the deck and 'plays' the cards by displaying them in the UI
3. The played cards are then added to a discard pile.
4. The player draws X new cards and repeats playing and discarding cards.
5. When there are no cards left in the deck, the game should ask the player of they want to play again.
-if the answer is yes, create a new deck with the discard pile and start again
-if the answer is no, end the game with a creative message to the player.
Requirements:
- The player must be able to continue to draw cards without errors.
- It should include different methods for drawing, shuffling and playing cards.
-It must include three arrays of a card, using a custom class that includes { Title: string, Description: String}
In: Computer Science
Type the Python code for all the questions. 1 2 Q1: Using DataFrame, with Figure 1 data, store the hypermarket data for rows and columns. Display the output as shown in Figure 1. 0 ITEMS NAME DISCOUNT 1 Grocery Rice 56 2 Electronics Mobile 25% 3 Food Apple 30% Figure 1 Q2: Update and display the "Rice" discount from 5% to 10%. Your output should be like Figure 2 now. 1 2 0 ITEMS NAME DISCOUNT 1 Grocery Rice 108 2 Electronics Mobile 25% 3 Food Apple 30% Figure 2 NO Q3: Use Figure 3 data to add and display a new column. Your output should be like Figure 3 now. 0 1 2 3 ITEMS NAME DISCOUNT STOCK Grocery Rice 10% 100 Electronics Mobile 25% 3 Food Apple 30% W NO 20 40 Figure 3
In: Computer Science