In: Computer Science
In: Computer Science
Python
#Note: use print() to add spaces between items and when needed
in the receipt
#(e.g. between user entries and between the entries and the
receipt)
#1 Ask the user for a number using the prompt: NUMBER?
# Convert the user entered number to an integer
# Calculate the square of the number and display the result on
screen with the following text before it: Your number squared
is
#2 Ask the user for a first number using the prompt: first
number?
# Ask the user for a second number using the prompt: second
number?
# Convert the two numbers to integers
# Multiply the first number by the second number and display the
result on screen with the following text before it: Result:
"""
#3 Develop a simple food receipt
a. Ask the user for inputs about two food items using the following
prompts in turn. Do not forget to assign each user
entry to a unique variable name:
Item1 name?
Item1 price?
Item1 quantity?
Item2 name?
Item2 price?
Item2 quantity?
b. Convert the price and quantity variables to integers
c. Calculate the total cost for the order by calculating each
item's total price by
multiplying price and quantity for each item and then adding up the
total prices for the two items
d. Display the results using the format:
RECEIPT
You ordered: [item1 name] and [item2 name]
Total cost: $ [total price for both items calculated in 3c
above]
"""
#Start your code below
"""
Enhance your simple food receipt
a. Ask the user for inputs about two food items using the following
prompts in turn. Do not forget to assign each user
entry to a unique variable name:
First item name?
First item price?
First item quantity?
Second item name?
Second item price?
Second item quantity?
Third item name?
Third item price?
Third item quantity?
b. Convert the price and quantity variables to integers
c. Calculate the total cost for the order by calculating each
item's total price by
multiplying price and quantity for each item and then adding up the
total prices for the three items
d. Calculate the total cost plus tax for the order by multiplying
the total cose calculated in c by the tax rate of .09
then adding the tax to the total cost
e. Display the results using the format:
RECEIPT
You ordered: [First item name] [Second item name] [third item
name]
Total cost: $ [total price for all items calculated in 3c
above]
Total cost plus tax: $ {total cost plus tax calculated in 3d
above}
"""
#Start your code below
In: Computer Science
: This exercise will give you a review of Strings and String processing. Create a class called MyString that has one String called word as its attribute and the following methods: Constructor that accepts a String argument and sets the attribute. Method permute that returns a permuted version of word. For this method, exchange random pairs of letters in the String. To get a good permutation, if the length of the String is n, then perform 2n swaps. Use this in an application called Jumble that prompts the user for a word and the required number of jumbled versions and prints the jumbled words. For example, Enter the word: mixed Enter the number of jumbled versions required: 10 xdmei eidmx miexd emdxi idexm demix xdemi ixdme eximd xemdi xdeim Notes: 1. It is tricky to swap two characters in a String. One way to accomplish this is to convert your String into an array of characters, swapping the characters in the array, converting it back to a String and returning it. char[] chars = word.toCharArray(); will convert a String word to a char array chars. String result = new String(chars); converts a char array chars into a String. p 6 2. Use Math.random to generate random numbers. (int)(n*Math.random()) generates a random number between 0 and n-1. java
In: Computer Science
Question 2
4-14 Which of the following terms best describes the following diagram?
Question 2 options:
DMZ |
|
Intranet |
|
Public LAN |
|
Extranet |
Question 3
4-13 Which of the following is the BEST definition of dual-homed?
Question 3 options:
Can filter on two OSI layers |
|
Contains two NICs |
|
Performs filtering and logging |
|
Performs packet and content filtering |
Question 4
4-10 Which of the following is the name for a lower-end (small business grade) firewall appliance that is capable of packet filtering, content filtering, intrusion detection, proxy, and application layer filtering?
Question 4 options:
UTM |
|
All-in-one |
|
SMB device |
|
NGFW |
Question 5
4-11 Which of the following is most often used for protecting a single computer?
Question 5 options:
hardware firewall |
|
virtual firewall |
|
software firewall |
|
firewall appliance |
Question 6
4-7 Which of the following were generation one firewalls capable of?
Question 6 options:
Filtering by IP header |
|
Filtering by session layer header |
|
Filtering by data content |
|
Filtering by protocol being used |
Question 7
4-6 the earliest firewalls were only capable of which of the following kinds of filtering?
Question 7 options:
Application layer |
|
Stateless |
|
Stateful |
|
Circuit layer |
Question 8
4-1 Which of the following were firewalls originally conceived to perform?
Question 8 options:
Block incoming unsolicited traffic |
|
Block outgoing traffic |
|
Both of the above |
|
Neither of the above |
Question 9
4-8 Which of the following is the word describing a firewall that is aware of a packet's place in an established and ongoing conversations
Question 9 options:
Content filter |
|
Proxy |
|
Stateless |
|
Stateful |
Question 10
4-20 Which of the following refers to a software firewall places on a dedicated server to create an internal hardware firewall?
Question 10 options:
Firewall system |
|
Constructed firewall |
|
Spare part firewall (SPF) |
|
Virtual firewall |
In: Computer Science
Word Find A popular diversion in the United States, “word find” (or “word search”) puzzles ask the player to find each of a given set of words in a square table filled with single letters. A word can read horizontally (left or right), vertically (up or down), or along a 45 degree diagonal (in any of the four directions) formed by consecutively adjacent cells of the table; it may wrap around the table’s boundaries, but it must read in the same direction with no zigzagging. The same cell of the table may be used in different words, but, in a given word, the same cell may be used no more than once. Write a computer program for solving this puzzle.
In: Computer Science
Identify and explain both internal and external reasons why change is inevitable in any organization.
In: Computer Science
Map word scanning in C++
For some context, I've been working on a program in which I must
enter in words and clear them of any potential punctuations. If a
word has punctuation in the middle of the word, I must ignore the
letters AFTER the punctuation and delete the punctuation as well.
For example if I enter in "fish_net" I will only get "fish" back. I
must also keep track of the occurrence of each word as well as
number of words.
Here's my problem, I'm using a do while loop to continuously enter
in words and break from it when needed. When I do, my output is
supposed to be separate words, but they are getting merged with
each other and counting it as one word. For example, lets say I
enter in the words: "hello" "there" "done". The INTENDED output
should be the following: hello 1 (newline) there 1 (newline) done
1. However, the output CURRENTLY goes like this: hello 1 (newline)
hellothere 1 (newline) hellotheredone 1. Mind you that the numbers
after the words are the number of occurrences that word is
entered.
#include <iostream>
#include<map>
#include<string>
#include <algorithm>
using namespace std;
void get_words(map<string, int>&);
void print_words(const map<string, int>&);
void clean_entry(const string&, string&);
int main()
{
map<string,int>m;
get_words(m);
print_words(m);
}
void get_words(map<string, int>&m)
{
string word, cleaned_words = "";
cout << "Enter in a string of text: ";
do
{
cin >> word;
clean_entry(word,
cleaned_words);
if (cleaned_words.length() !=
0)
{
m[cleaned_words]++;//inserting clean words into map
}
} while (word != "done");
}
void print_words(const map<string, int>&m)
{
int non_empty_words = 0;
for (auto it = m.begin(); it != m.end(); it++)
{
cout << it->first <<
" " << it->second << endl;
non_empty_words +=
it->second;
}
cout << "Non-empty words: " <<
non_empty_words << endl;
cout << "Words: " << m.size();
}
void clean_entry(const string&words,
string&cleaned_words)
{
int len = words.length();
int i = 0;
while (i < len && ispunct(words[i]))
i++;//parse through initial punctuation (make sure that punctuation
is deleted while leaving word intact if in front or back)
while (i < len &&
!ispunct(words[i]))//while we come across any words with no
punctuation, we add it to cleaned words
{
cleaned_words += words[i];
i++;
}
}
In: Computer Science
Explain briefly how search engines work (What are the major components?).
In: Computer Science
Generational learning experts describe potential
entrepreneurs in four categories, Millenials, Generation X, Baby
Boomers and Silent Generation.
Please distinguish between these generations and state which one is
currently more inclined to start a new venture
In: Computer Science
For a project I have to implement a class called BigInteger, with a representative small set of operations. (working with big integers that is far more digits that java's int data type will allow. Here's the code, including what I have so far. I would appreciate any help. thank you. i'm not sure if what i have is right (the only thing i wrote is under the public static BigInteger parse(String integer) we just have to implement that method.
package bigint;
/** * This class encapsulates a BigInteger, i.e. a positive or negative integer with * any number of digits, which overcomes the computer storage length limitation of * an integer. * */
public class BigInteger {
/** * True if this is a negative integer */
boolean negative;
/** * Number of digits in this integer
*/ int numDigits; /** * Reference to the first node of this integer's linked list representation * NOTE: The linked list stores the Least Significant Digit in the FIRST node. * For instance, the integer 235 would be stored as: * 5 --> 3 --> 2 * * Insignificant digits are not stored. So the integer 00235 will be stored as: * 5 --> 3 --> 2 (No zeros after the last 2) */
DigitNode front; /** * Initializes this integer to a positive number with zero digits, in other * words this is the 0 (zero) valued integer. */
public BigInteger() {
negative = false; numDigits = 0; front = null; }
/** * Parses an input integer string into a corresponding BigInteger instance. * A correctly formatted integer would have an optional sign as the first * character (no sign means positive), and at least one digit character * (including zero). * Examples of correct format, with corresponding values * Format Value * +0 0 * -0 0 * +123 123 * 1023 1023 * 0012 12 * 0 0 * -123 -123 * -001 -1 * +000 0 * * Leading and trailing spaces are ignored. So " +123 " will still parse * correctly, as +123, after ignoring leading and trailing spaces in the input * string. * * Spaces between digits are not ignored. So "12 345" will not parse as * an integer - the input is incorrectly formatted. * * An integer with value 0 will correspond to a null (empty) list - see the BigInteger * constructor * * @param integer Integer string that is to be parsed * @return BigInteger instance that stores the input integer. * @throws IllegalArgumentException If input is incorrectly formatted */
public static BigInteger parse(String integer)
throws IllegalArgumentException {
integer = integer.trim();
BigInteger bigInt = new BigInteger();
boolean negative = false; hasExplicitSign = false; int stringLength;
if(integer != null) {
stringLength = integer.length(); }else { throw new IllegalArgumentException("Please input a valid number"); }
if (stringLength==0) { throw new IllegalArgumentException("Please input a valid number"); } else
if(stringLength == 1 && integer.substring(0,1).compareTo("-") <= 0) {
throw new IllegalArgumentException("Please input a valid number."); } else
if(stringLength>0) {
int lastIndexNeg = -1; int lastIndexPos = -1;
for(int i = 0; i < stringLength; i++) {
char digitOrSign = integer.charAt(i); if(digitOrSign == '-') lastIndexNeg = i; else if(digitOrSign == '+')
lastIndexPos = i;
else if(!Character.isDigit(digitOrSign))
throw new IllegalArgumentException("Please input a valid number.");
if(lastIndexNeg > 0 || lastIndexPos > 0) {
throw new IllegalArgumentException("Please input a valid number.");
if(lastIndexNeg == 0) {
hasExplicitSign = true; negative = true; } else
if(lastIndexPos == 0) { hasExplicitSign = true; } if(hasExplicitSign) {
integer = integer.substring(1); stringLength--; }
if(stringLength==1 && integer.charAt(0) == '0') {
return bigInt; } } int lastDigit = Integer.parseInt(integer.substring(stringLength-1, stringLength));
bigInt.front = new DigitNode(lastDigit, null); } } } } /* IMPLEMENT THIS METHOD */ // following line is a placeholder for compilation return null; } /** * Adds the first and second big integers, and returns the result in a NEW BigInteger object. * DOES NOT MODIFY the input big integers. * * NOTE that either or both of the input big integers could be negative. * (Which means this method can effectively subtract as well.) * * @param first First big integer * @param second Second big integer * @return Result big integer */ public static BigInteger add(BigInteger first, BigInteger second) { /* IMPLEMENT THIS METHOD */ // following line is a placeholder for compilation return null; } /** * Returns the BigInteger obtained by multiplying the first big integer * with the second big integer * * This method DOES NOT MODIFY either of the input big integers * * @param first First big integer * @param second Second big integer * @return A new BigInteger which is the product of the first and second big integers */ public static BigInteger multiply(BigInteger first, BigInteger second) { /* IMPLEMENT THIS METHOD */ // following line is a placeholder for compilation return null; } /* (non-Javadoc) * @see java.lang.Object#toString() */
public String toString() {
if (front == null) { return "0"; }
String retval = front.digit + "";
for (DigitNode curr = front.next; curr != null; curr = curr.next)
{ retval = curr.digit + retval; }
if (negative) { retval = '-' + retval; }
return retval; } }
this is the other class digitalnode.java
package bigint;
/**
* This class encapsulates a linked list for a digit of a big
integer.
public class DigitNode {
/**
* The digit
*/
int digit;
/**
* Pointer to next digit in the linked list
*/
DigitNode next;
/**
* Initializes this digit node with a digit and next
pointer
*
* @param digit Digit
* @param next Next pointer
*/
DigitNode(int digit, DigitNode next) {
this.digit = digit;
this.next = next;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return digit + "";
}
}
In: Computer Science
Can you convert this code (Python) to C++
def decrypt(message, key): decryptedText = "" for i in message: M = ord(i) k = int(key, 16) xor = M ^ k decryptedText += chr(xor) return decryptedText def encrypt(message, key): encryptedText = "" for i in message: M = ord(i) k = int(key, 16) xor = M ^ k encryptedText += chr(xor) return encryptedText # main function userText = input("Enter text: ") userKey = str(input("Enter a key: ")) encryptedMessage = encrypt(userText, userKey) decryptedMessage = decrypt(encryptedMessage, userKey) print("Encrypted message: ", encryptedMessage) print("Decrypted message: ", decryptedMessage)
In: Computer Science
I am having an issue with trying to make my code to have a required output
////////////Input//////////
With computer science, you can work in any industry. 0
//////////Output//////////
Required Output
Enter some text to encrypt\n Enter a key\n Error: Key is divisible by 26. That's a bad key!\n Useless key: 0\n
///////////Cipher.java///////// ------------ My code.
public class Cipher { private String plainText; private int key; public Cipher(String text, int key) throws EmptyPlainText, UselessKeyException { if (text == null || text.length() == 0) { throw new EmptyPlainText("Error: Nothing to encrypt!"); } if (key % 26 == 0) { throw new UselessKeyException(26, "Error: Key is divisible by 26. That's a bad key!"); } this.plainText = text; this.key = key; } public String getPlainText() { return plainText; } public int getKey() { return key; } public String getCipherText() { String cipher = ""; int k = key % 26; char c; int integer; for (int counter = 0; counter < plainText.length(); counter++) { c = plainText.charAt(counter); if (Character.isUpperCase(c)) { integer = c - 'A'; integer += k; integer %= 26; c = (char) (integer + 'A'); } else if (Character.isLowerCase(c)) { integer = c - 'a'; integer += k; integer %= 26; c = (char) (integer + 'a'); } else c += k; cipher += c; } return cipher; } }
///////////CipherDemo/////////
import java.util.Scanner; public class CipherDemo { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter some text to encrypt"); String input = keyboard.nextLine(); System.out.println("Enter a key"); int key = keyboard.nextInt(); try { Cipher c = new Cipher(input, key); System.out.println("Plain text: " + c.getPlainText()); System.out.println("Cipher text: " + c.getCipherText()); System.out.println("Key: " + c.getKey()); } catch (EmptyPlainText e) { System.out.println(e.getMessage()); } catch (UselessKeyException e) { System.out.println(e.getMessage()); System.out.println("Useless key: " + e.getUselessKey()); } } }
In: Computer Science
Why did the Sarbanes–Oxley Act become law? In your opinion, does it provide any real protection to investors? Why or why not?
In: Computer Science
DoubleClick focuses on three main metrics: cost-per-click (CPC), click-through rate (CTR), and transaction conversion rate (TCR). What other metrics can you think of that can be used to measure and compare the performance of different SEM campaigns? Explain
In: Computer Science