def isPower(x, y):
"""
>>> isPower(4, 64)
3
>>> isPower(5, 81)
-1
>>> isPower(7, 16807)
5
"""
# --- YOU CODE STARTS HERE
def isPower(x, y):
num = x
count = 1
while x < y:
x *= num
count += 1
if x == y:
return count
return -1
def translate(translation, txt):
"""
>>> myDict = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left', '1': 'one'}
>>> text = 'Up down left Right forward 1 time'
>>> translate(myDict, text)
'down up right left forward one time'
"""
# --- YOU CODE STARTS HERE
def translate(translationDict, txt):
words = txt.lower().split()
for i in range(len(words)):
if words[i] in translationDict:
words[i] = translationDict[words[i]]
return ' '.join(words)
def onlyTwo(x, y, z):
"""
>>> onlyTwo(1, 2, 3)
13
>>> onlyTwo(3, 3, 2)
18
>>> onlyTwo(5, 5, 5)
50
"""
# --- YOU CODE STARTS HERE
def onlyTwo(x, y, z):
m1 = max(x, y, z)
m2 = (x + y + z) - min(x, y, z) - m1
return m1 * m1 + m2 * m2
def largeFactor(num):
"""
>>> largeFactor(15)
5
>>> largeFactor(24)
12
>>> largeFactor(7)
1
"""
# --- YOU CODE STARTS HERE
def largeFactor(num):
n = num - 1
while n >= 1:
if num % n == 0:
return n
n -= 1
def hailstone(num):
"""
>>> hailstone(5)
[5, 16, 8, 4, 2, 1]
>>> hailstone(6)
[6, 3, 10, 5, 16, 8, 4, 2, 1]
"""
# --- YOU CODE STARTS HERE
def hailstone(num):
result = []
while num > 1:
result.append(num)
if num % 2 == 0:
num = num // 2
else:
num = 3 * num + 1
result.append(num)
return result
if any wrong with my code
In: Computer Science
What is the minimum length in hop by hop extension header in ipv6 ?
In: Computer Science
In this assignment, you are expected to rewrite the program from assignment7 using structs. That is, instead of using multiple arrays (one for each field, you need to create a single array of the datatype you should create as a struct).
So, write a C++ program (use struct and dynamic memory allocation) that reads N customer records from a text file (customers.txt) such as each record has 4 fields (pieces of information) as shown below:
Account Number (integer)
Customer full name (string)
Customer email (string)
Account Balance (double)
The program is expected to print the records in the format shown below, sorted in decreasing order based on the account balance:
Account Number : 1201077
Name : Jonathan I. Maletic
Email : [email protected]
Balance : 10,000.17
-------------------------------------
Note: The records stored in the following format (4 lines for each account). You need to create a text file that contains sample records as explained in class:
First Line is the account number
Second Line is full name
Third line is email
Forth line is the available balance
Important Note: You must create a struct called (Customer) with enough members (to hold record information) and use it to declare a dynamic array to store all the records (information) read from the file. Then sort the array and then print it. Use the example shared in class (see the slides) as a model for your program.
|
Example (data saved in text file) |
Output: |
|
1201077 Jonathan I. Maletic 10,000.17 1991999 John Smith 5,000.11 1333333 Bill Bultman 120,000.00 |
Account Number : 1333333 Name : Bill Bultman Email : [email protected] Balance : 120,000.00 ------------------------------------- Account Number : 1201077 Name : Jonathan I. Maletic Email : [email protected] Balance : 10,000.17 ------------------------------------- Account Number : 1991999 Name : John Smith Email : [email protected] Balance : 5,000.11 ------------------------------------- |
In: Computer Science
This is C++, please insert screenshot of output please.
Part1: Palindrome detector
Write a program that will test if some string is a palindrome
In: Computer Science
Problem 1 (Ransom Note Problem) in python
A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words.
Here is how your program should work to simulate the ransom problem:
Example: If the magazine string is “programming problems are weird”
If the ransom note is: “no see” your program should print true as all the characters in “no see” exist in the magazine string.
If the ransom note is “no show” your program should print false as not all the characters in “no show” exist in the magazine string as you can see the character ‘h’ does not exist.
In: Computer Science
1. What are some drawbacks to crowd sourced answers?
2. Do people generally utilize the diversity of sources on the Internet effectively?
3. How reliant are we and how reliant should we be on getting our news from social media?
In: Computer Science
Can anyone just check my code and tell me why the program doesn't show the end date & stops at the date before the end date? Tell me how i can fix it.
Question:
Write a program compare.cpp that asks the user to input two dates (the beginning and the end of the interval). The program should check each day in the interval and report which basin had higher elevation on that day by printing “East” or “West”, or print “Equal” if both basins are at the same level.
My code:
#include
#include
#include
#include
using namespace std;
int main()
{
string date;
string starting_date;
string ending_date;
double eastSt;
double eastEl;
double westSt;
double westEl;
int dateRange=0;
cout<< "Enter the starting date" << endl;
cin>> starting_date;
cout<< "Enter the ending date" << endl;
cin>> ending_date;
ifstream fin("Current_Reservoir_Levels.tsv");
if (fin.fail())
{
cerr << "File cannot be opened for reading." << endl;
exit(1);
}
string junk;
getline(fin, junk);
while(fin >> date >> eastSt >> eastEl >> westSt >> westEl)
{
fin.ignore(INT_MAX, '\n');
if (date == starting_date)
{
dateRange = 1;
}
if (date == ending_date)
{
dateRange= 0;
}
if (dateRange == 1)
{
if(eastEl > westEl)
{
cout<< date << " "<< "East " <
}
else if (eastEl < westEl)
{
cout<< date << " " << "West" <
}
else if (eastEl == westEl )
{
cout<< date << " " << "Equal" <
}
}
}
return 0;
}
Expected output
01/17/2018 West 01/18/2018 West 01/19/2018 West 01/20/2018 West 01/21/2018 West 01/22/2018 West 01/23/2018 West
Received output:
01/17/2018 West 01/18/2018 West 01/19/2018 West 01/20/2018 West 01/21/2018 West 01/22/2018 West
*************** F.H**************
In: Computer Science
Hello, I keep getting the error C4430: missing type specifier -
int assumed. Note: C++ does not support default-int for my code.
What am I doing wrong? I only have #include
<iostream>
int read_num(void);
main()
{
int num1, num2, max;
//find maximum of two 2 numbers
num1 = read_num();
num2 = read_num();
if (num1 > num2)
{
max = num1;
}
else
{
max = num2;
}
printf("the maximum number is: %d\n", max);
return;
}
int read_num(void)
{
int num;
printf("Enter a number: ");
scanf_s("%d", &num);
return (num);
}
In: Computer Science
1. Describe the basic components of network security and the differences between wired and wireless network security best practices.
In: Computer Science
Instruction
This task is about using the Java Collections Framework to accomplish some basic textprocessing tasks. These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to efficiently accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each of them. Unless specified otherwise, sorted order refers to the natural sorted order on Strings, as defined by String.compareTo(s). Part 0 in the assignment is an example specification and solution.
Part0
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Part0 {
/**
* Read lines one at a time from r. After reading all
lines, output
* all lines to w, outputting duplicate lines only
once. Note: the order
* of the output is unspecified and may have nothing to
do with the order
* that lines appear in r.
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt(BufferedReader r, PrintWriter
w) throws IOException {
Set<String> s = new HashSet<>();
for (String line = r.readLine(); line != null; line =
r.readLine()) {
s.add(line);
}
for (String text : s) {
w.println(text);
}
}
/**
* The driver. Open a BufferedReader and a PrintWriter,
either from System.in
* and System.out or from filenames specified on the
command line, then call doIt.
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader
r;
PrintWriter
w;
if (args.length
== 0) {
r = new BufferedReader(new
InputStreamReader(System.in));
w = new PrintWriter(System.out);
} else if
(args.length == 1) {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(new
FileWriter(args[1]));
}
long start =
System.nanoTime();
doIt(r,
w);
w.flush();
long stop =
System.nanoTime();
System.out.println("Execution time: " + 10e-9 *
(stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);
}
}
}
Question 6
[5 marks] Read the input one line at a time and output the current line if and only if it is not a suffix of some previous line. For example, if the some line is "0xdeadbeef" and some subsequent line is "beef", then the subsequent line should not be output.
Template code
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Part6 {
/**
* Your code goes here - see Part0 for an example
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt(BufferedReader r, PrintWriter
w) throws IOException {
// Your code goes here - see Part0
for an example
}
/**
* The driver. Open a BufferedReader and a PrintWriter,
either from System.in
* and System.out or from filenames specified on the
command line, then call doIt.
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader
r;
PrintWriter
w;
if (args.length
== 0) {
r = new BufferedReader(new
InputStreamReader(System.in));
w = new PrintWriter(System.out);
} else if
(args.length == 1) {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new
FileReader(args[0]));
w = new PrintWriter(new
FileWriter(args[1]));
}
long start =
System.nanoTime();
doIt(r,
w);
w.flush();
long stop =
System.nanoTime();
System.out.println("Execution time: " + 10e-9 *
(stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);
}
}
}
In: Computer Science
1. Briefly explain the principle of least privilege and how it should be applied. 2. Explain what describes a truly secure password.
In: Computer Science
Summary
In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop.
Instructions
// NewMultiply.java - This program prints the numbers 0 through
10 along
// with these values multiplied by 2 and by 10.
// Input: None.
// Output: Prints the numbers 0 through 10 along with their values
multiplied by 2 and by 10.
public class NewMultiply
{
public static void main(String args[])
{
String head1 = "Number: ";
String head2 = "Multiplied by 2: ";
String head3 = "Multiplied by 10: ";
int numberCounter; // Numbers 0 through 10.
int byTen; // Stores the number multiplied by 10.
int byTwo; // Stores the number multiplied by 2.
final int NUM_LOOPS = 10; // Constant used to control loop.
// This is the work done in the housekeeping() method
System.out.println("0 through 10 multiplied by 2 and by 10" +
"\n");
// This is the work done in the detailLoop() method
// Write for loop
// This is the work done in the endOfJob() method
System.exit(0);
} // End of main() method.
} // End of NewMultiply class.
In: Computer Science
1. Briefly but completely explain the two most significant differences you discern from Windows and Linux file management.
2. Explain why Windows compatibility may cause issues for users.
In: Computer Science
Using the combination of HTML and PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 1000 numbers, such as:
71636269561882670428252483600823257530420752963450
85861560789112949495459501737958331952853208805511
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
96983520312774506326239578318016984801869478851843
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
05886116467109405077541002256983155200055935729725
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
62229893423380308135336276614282806444486645238749
73167176531330624919225119674426574742355349194934
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
Your code should contain a PHP function that, accepting the string of 1000 numbers in input, is able to:
1) Find the 5 adjacent numbers that multiplied together give the largest product.
2) Given the product from above, computes the sum of the factorial of each term of such product
Example, if the product is 5046, computes 5! + 0! + 4! + 6!
NOTE:
In: Computer Science
How would you reply to this discussion:
Cloud Computing is a way to store massive amounts of information on remote servers. Unlike saving information on your local hard drive or flash drive, cloud storage is almost like a magical place that keeps (so we hope) your information safe and secure. A couple of different cloud computing examples are.
1. Communication: these would be examples of Skype or WhatsApp. I have used both applications, though I haven't used skype in many years, I currently use WhatsApp daily,
2. Backup and Recovery: Large storage to save your information. I always like to say, It's somewhere in the cloud. Examples, Dropbox, Google Drive, and Amazon S3. Out of these three, I have only used Dropbox, this was used during my Web Design class.
3. Social Networking: We all know about social networking, we all may use them on a daily basis. Also, social networking is the most popular of cloud computing. Some examples are Facebook, LinkedIn and Instagram to name a few.
This week I actually learn a lot. Back in my computer help desk days, I remember building a computer by imaging. But it was different to see the different way to divide the disk space. Very interesting.
In: Computer Science