Using C# visual basics
Can someone show a calculator with a button that does a FOR LOOP about 10x time and does a print out of a name 10x
In: Computer Science
Using C# visual basics
Can someone show a calculator with a button that does a While LOOP about 10x time and does a print out of a name 10x
In: Computer Science
a.) Let T be a binary tree with n nodes. Define the lowest common ancestor (LCA) between two nodes v and w as the lowest node in T that has both v and w as descendants. Given two nodes v and w, write an efficient algorithm, LCA(v, w), for finding the LCA of v and w. Note: A node is a descendant of itself and v.depth gives a depth of a node v.
b.) What is the running time of your algorithm? Give the asymptotic tight bound (Q) of its running time in terms of n and justify your answer.
In: Computer Science
Write and test a Python program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in order from largest to smallest. Note, the sentinel number is not to be considered as one of the numbers, it should not be printed. The program should be able to handle up to 100 input numbers. If the user attempts to enter more than 100 numbers, the program should print an error message and quit.
Also do not use list methods like list.append etc. or import any libraries to solve this problem.
Here is the template to work off of:
# get the numbers and input into the list
def get_numbers(nums):
# stop when -99.0 is entered
i = 0;
while i < 10:
nums[i] = input("Enter a number: ")
if nums[i] == -99.0:
break
i = i + 1
return i # returning the total number of numbers entered
# output all num numbers
def print_numbers(nums, num):
# output each number one line at a time
for i in range(num):
print nums[i]
# output the numbers joining each with a space between on one line
print (" ".join(str(x) for x in nums[0:num]))
# output the list
print nums
#####################
# the "boss" function
#####################
def main():
num_numbers = 0 # initialize num_numbers to 0
a = [0.0] * 10 # initialize a list of 10 floating point values to 0.0
num_numbers = get_numbers(a)
print_numbers(a, num_numbers)
# if python program was executed from this source code
if __name__ == "__main__":
main()
In: Computer Science
In: Computer Science
Program Specifications:
You will be writing a Java program called ASCIIRabbit.java that will print the following ASCII objects. There should be two blank lines between each shape and your output must match identically.
Rabbit In A Hat
--------------------
(^\ /^)
\ V /
(o o)
( (@) )
---------
| |
| |
| |
_______
Rabbit Under A Hat
--------------------
_______
| |
| |
| |
---------
/\"/\
() * ()
("")_("")
Rabbit Wears A Hat
------------------
_______
| |
| |
| |
---------
(o o)
( (@) )
/\"/\
() * ()
("")_("")
Style requirements:
displayRabbitWearsHat(); //prints rabbit wearing hat
/* ***********************************************************************************
displayRabbitWearsHat() - Displays the ASCII image of a rabbit wearing a hat
************************************************************************************ */
public static void displayRabbitWearsHat() {
displayRabbitEars();
displayRabbitFace();
displayHatBottom();
//etc.
Once you think you have your program decomposition properly created, test your program to see if your output matches the sample run from above. When it looks correct and you have it properly documented, submit it for grading.
In: Computer Science
Tip Calculator Instructions
For this project you are to create a tip calculator that will take a decimal/or non decimal amount and calculate the different tip values of that amount:
10% 15% 20%
And display them appropriately. The values will be set to two decimal places. If you have an empty value, then a message will display informing the user of such. When the device is rotated the error message or tip information must continue to be displayed.
in Android/Java
In: Computer Science
Python
class LinkedNode:
# DO NOT MODIFY THIS CLASS #
__slots__ = 'value', 'next'
def __init__(self, value, next=None):
"""
DO NOT EDIT
Initialize a node
:param value: value of the node
:param next: pointer to the next node in the LinkedList, default is None
"""
self.value = value # element at the node
self.next = next # reference to next node in the LinkedList
def __repr__(self):
"""
DO NOT EDIT
String representation of a node
:return: string of value
"""
return str(self.value)
__str__ = __repr__
# IMPLEMENT THESE FUNCTIONS - DO NOT MODIFY FUNCTION SIGNATURES #
def insert(value, node=None):
pass
def to_string(node):
pass
def remove(value, node):
pass
def remove_all(value, node):
pass
def search(value, node):
pass
def length(node):
pass
def sum_list(node):
pass
def count(value, node):
pass
def reverse(node):
pass
def remove_fake_requests(head):
pass
Testcases:
import unittest
from LinkedList import insert, remove, remove_all, to_string, search, sum_list, \
count, reverse, length, remove_fake_requests
class TestProject2(unittest.TestCase):
def test_insert(self):
linked_list = insert(0)
insert(1, linked_list)
insert(2, linked_list)
for i in range(0, 3):
assert linked_list.value == i
linked_list = linked_list.next
def test_to_string(self):
list1 = insert(0)
insert(1, list1)
insert(2, list1)
insert(3, list1)
assert to_string(list1) == "0, 1, 2, 3"
def test_length(self):
list1 = insert(1)
insert(2, list1)
insert(3, list1)
assert length(list1) == 3
def test_search(self):
list1 = insert(0)
insert(1, list1)
insert(2, list1)
assert search(2, list1)
assert not search(3, list1)
def test_count(self):
list1 = insert(0)
insert(1, list1)
insert(2, list1)
assert count(0, list1) == 1
assert count(1, list1) == 1
assert count(2, list1) == 1
def test_sum_list(self):
list1 = insert(0)
insert(1, list1)
insert(2, list1)
insert(3, list1)
assert sum_list(list1) == 6
def test_remove(self):
list1 = insert(0)
insert(1, list1)
insert(2, list1)
insert(3, list1)
list1 = remove(1, list1)
for i in [0, 2, 3]:
assert list1.value == i
list1 = list1.next
assert list1 == None
def test_remove_all(self):
list1 = insert(0)
insert(1, list1)
insert(0, list1)
insert(2, list1)
insert(3, list1)
insert(0, list1)
list1 = remove_all(0, list1)
test_list = list1
for i in [1, 2, 3]:
assert test_list.value == i
test_list = test_list.next
assert test_list == None
def test_reverse(self):
list1 = insert(0)
insert(1, list1)
insert(2, list1)
insert(3, list1)
list1 = reverse(list1)
for i in [3, 2, 1, 0]:
assert list1.value == i
list1 = list1.next
def test_fake_requests(self):
requests = insert(170144)
insert(567384, requests)
insert(604853, requests)
insert(783456, requests)
insert(783456, requests)
insert(903421, requests)
real_requests = remove_fake_requests(requests)
for i in [170144, 567384, 604853, 903421]:
assert real_requests.value == i
real_requests = real_requests.next
if __name__ == "__main__":
unittest.main()
Thanks!
In: Computer Science
The program Nadha Skolar wrote is supposed to read an integer value supplied by the user that should be between 1-30. Using the value supplied (let's call it n), three different summation formulas should be calculated using three different methods. Nadha Skolar was supposed to write a program to read the user's input, ensure that it is a value between 1-30 and then call the appropriate methods to calculate the summations and print the results:
Sample Runs:
Run #1 (bad value for n):
Enter a number between 1-30 for the value of n: 0 <--- user enters the number for n Program cannot continue. n must be a value 1-30. <--- use a println
Run #2 (bad value for n):
Enter a number between 1-30 for the value of n: 31 <--- user enters the number for n Program cannot continue. n must be a value 1-30. <--- use a println
Run #3:
Enter a number between 1-30 for the value of n: 3 <--- user enters the value for n The summation of the first n numbers is: 6 The summation of the n odd numbers is: 9 The summation of n numbers squared is: 14 <--- use a println
Tips:
import java.util.*;
/* Name: NadhaSkolar Solution
public class NadhaStrikesAgain { //my best work yet! I have just
learned about methods!
public static void main(String[] args) {
//get the value for n
Scanner scnr = new Scanner(System.in);
int n = getN();
//ensure n is usable
if ((n <= 0) && (n > 30)){
System.out.println("Program cannot continue. n must be a value
1-30.");
}
int sum = summationN(n);
int sumodd = sumofOddN(sum);
int sumSquares = sumOfSquaresN(n);
displayResults(sumodd, sum, sumSquares); //print them out
}
}
// ************************************************
// DESCRIPTION - getN() - prompts for n and returns value to
main
// ************************************************
public static void getN(Scanner scnr) {
//prompt for a number,
System.out.print("Enter a number between 1-30 for the value of n:
");
int n = scnr.nextInt();
return n;
}
// ************************************************
// DESCRIPTION - addOdd() computes summation of first "num" odd
numbers using the formula n^2
// ************************************************
public static double sumofOddN(int num) {
return(num^2);
}
// ************************************************
// DESCRIPTION - summation() - computes and returns the summation
of i from to N
// ************************************************
public static int summationN(int num) {
return(num * num + 1 / 2);
}
// ************************************************
// DESCRIPTION - sumOfSquares() - computes and returns the sum of
squares of first "num" numbers
// ************************************************
public static int sumOfSquaresN(int n) {
return((num * (num + 1) * (2 * num + 1) / 6));
}
// ************************************************
// DESCRIPTION - displayResults() - displays the various
summations
// ************************************************
public static void displayResults(int sum, int oddSum, int
sumSquares) {
System.out.println();
System.out.println("The summation of the first n numbers is: " +
sum);
System.out.println("The summation of the n odd numbers is: " +
oddSum);
System.out.println("The summation of n numbers squared is: " +
sumSquares);
}
}
}
In: Computer Science
Instructions
Write a Circle class (Circle.java) that has the following fields:
- radius (double)
- PI (final double initialized to 3.1415) // no need to have setters or getters for this
Include the following methods:
- Constructor (accepts radius of circle as an argument)
- Constructor (no argument that sets radius to 0.0)
- setRadius (set method for radius field)
- getRadius (get method for radius field)
- calcArea (calculates and returns area of circle: area = PI * radius * radius)
- calcDiameter (calculates and returns diameter of circle: diameter = radius * 2)
- calcCircumference (calculates and returns circumference of circle: circumference = 2* PI * radius)
Write a test program (TestCircle.java) that will ask user for the radius, creates the circle object, and then displays the area, diameter, and circumference.
Make sure to create 2 circle object instances - one with the radius as an argument, one without but sets the radius with the setRadius() method.
Thank you so much for your help!!
In: Computer Science
Create 2 more batch files called devTracker.bat and
showTracker.bat as follows:
devTracker.bat
a. This batch logs an entry into a log file called
C:\myTemp\devTracker.log
b. The entry in the log file should indicate the date and time of
the VS launch as well as a message indicating
that you started Visual Studio. Please log all of this information
on 1 line in the devTracker.log file
c. After making this log entry, devTracker.bat should run
myStart.bat for you
showTracker.bat
d. Create another batch file called showTracker.bat that displays
the contents of the devTracker.log
file in the command prompt window.
In: Computer Science
| Java Prorgramming |
|
Description In this assignment, you'll be URL encoding of a line of text. Web browsers URL encode certain values when sending information in requests to web servers (URL stands for Uniform Resource Locator). Your program needs to perform the following steps:
To convert a String to URL encoded format, each character is examined in turn:
Use a for loop which increments it's index variable from 0 up to the last character position in the input string. Each iteration of the loop retrieves the character at the 'index' position of the input string (call the String class charAt() method on the input string). Use if statements to test the value of the character to see if it needs to be encoded. If encoding is not required, just concatenate it to the output encoded String. If encoding is required, concatenate the encoded value to the output encoded String. For example, if the input character is a blank, you want to concatenate a '+' character to the output encoded String (as described above). Note: one technique to determine if a character is one that remains the same is to first create an initialized String containing all of the letters (both upper and lower case), digits, and other special characters that remain the same as described above. Then, call the String indexOf method on that String, passing the character to be tested. If -1 is returned from indexOf, the character was not one of those that remains the same when URL encoding. For those characters that need to be converted into hex format (%xy above), you can call the pre-defined static Integer.toHexString method, passing the character as an argument. It returns the hex value of the character as a String, which you can concatenate to the encoded output String with the accompanying '%' symbol: String hexValue =
Integer.toHexString(srcChar); Values that are URL encoded in this manner can be URL decoded by reversing the process. This is typically done by a web server upon receiving a request from a browser. Sample Output Enter a line of text to be URL encoded Test Data Use all the following test data to test your program, plus an example of your own: This should have hex 2f for / Getting started Before you start writing Java code, it's usually a good idea to 'outline' the logic you're trying to implement first. Once you've determined the logic needed, then start writing Java code. Implement it incrementally, getting something compiled and working as soon as possible, then add new code to already working code. If something breaks, you'll know to look at the code you just added as the likely culprit. To help you get started with this homework, here's an outline of the logic you'll need (sometime referred to as 'pseudo-code'): Prompt for the line of input. if (the character is a blank) Print the encoded output string. Once you understand this logic, start writing your Java code. An example of the steps you could take are as follows:
With this much done, if you read in a line containing "hello", you'd get output something like this from the temporary output statement within the loop: char 0 is h Once you've got this compiled and working, starting adding the if/else-if/else logic inside the loop to build the encoded output string. I have this so far.What am I doing wrong here,please let me know. The code has to fit this requirement. For those characters that need to be converted into hex format (%xy above), you can call the pre-defined static Integer.toHexString method, passing the character as an argument. It returns the hex value of the character as a String, which you can concatenate to the encoded output String with the accompanying '%' symbol: String hexValue =
Integer.toHexString(srcChar); Values that are URL encoded in this manner can be URL decoded by reversing the process. This is typically done by a web server upon receiving a request from a browser. I don't how to fit the last requirement here is my code so far import java.util.Scanner; public class URLEncoding { public static final String
Notencodedchars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~*'()";
} System.out.println("Length in chars is :" + encodedString.toString().length()); } }
|
In: Computer Science
As it relates to C#:
Though the function of switch case and else if ladder is same, there are a number of difference between switch case and else if ladder, Explain the differences in two areas such (memory consumption, speed of processing, variable requirement) etc.
In: Computer Science
Please code in c# (C-Sharp)
Write a program that will ask the user for their name. If the user does not input anything, display a
warning before continuing. The program will then ask the user whether they want to have an addition,
subtraction, multiplication, or division problem. Once the user indicates their choice, the program will
display 2 randomly generated numbers from 1 to 9 in a math problem matching the user’s choice.
Example: user selects addition, the equation presented is:
(random number from 1 to 9) + (random number from 1 to 9)
The user will then input an answer as a whole number. If the answer they entered is not a whole
number, tell the user their input is invalid and end the program. If the input is valid, check to see if it is
the correct answer. If correct, congratulate the user by name. If incorrect, output the correct answer.
Tasks
1) The program needs to contain the following
a.
A comment header containing your name and a brief description of the program
b. At least 5 comments besides the comment header explaining what your code does
c.
A string variable that captures the user’s name
d. A way to validate user input to determine if they entered an empty string
i. Warn the user if they enter an empty string
ii. Continue the program after warning the user
e. A prompt for what type of quiz the user wants
f.
Display of a quiz matching the type the user requested
g.
A prompt for an answer in the form of a whole number
i. A message if the user enters an invalid number
1. Do not check the user’s answer if their input is invalid
ii. If input is valid:
1. Check the answer
2. If the answer is correct, congratulate the user by name
3. If incorrect, output the correct answer
h. “Press enter to continue” and Console.ReadLine(); at the end of your code
i. Note: if you write a try-catch statement, these lines will be after your last catch
2) Upload a completed .cs file onto the Assignment 4 submission folder and a word document
containing the following six (6) screenshots:
a.
The warning displayed when the user enters a blank value for the name
b. One test run for each equation with valid input
i. Answer 2 quizzes correctly
ii. Answer 2 quizzes incorrectly
c.
One test run with invalid input
In: Computer Science
Write C functions to do each of the following. Make sure your function has exactly the same name, parameters, and return type as specified here. Please place all of the functions in a single .c file and write a main() to test them.
int process(const char *input_filename, const char *output_filename) — reads the file named input_filename and processes it, putting results in output_filename. The input file consists of lines of the form "number operation number," for example:
15 - 4 3.38 / 2.288 2 ^ -5 35.2 + 38
The possible operations are +, -, *, /, and ^ (power). Your function should calculate the value of each line's expression and save it (one to a line) to the output file. For example, the input file shown above would result in an output file of
11.000000 1.477273 0.031250 73.200000
The return value of the function should be the number of calculations that it did (4 for this example file).
(Hints: fscanf() returns the constant value EOF when the end of file is reached. The pow(x, y) function defined in <math.h> calculates xy; you will need to add -lm to the command line when compiling your code to link the math library.)
In: Computer Science