In: Computer Science
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
milesHours = miles / hours;
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
1. Rewrite the above program such that function main call a return type function named findMilesPerHours to calculate the number of miles per hours. Finish function prototype, call and function definition.#include <iostream>
#include <iomanip>
// Function prototype here
……………………………………………………………………..
using namespace std;
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
// Function call here
……………………………………………………………………..
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
// Function definition here
……………………………………………………………………..
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototype here
……………………………………………………………………..
int main()
{
float miles; //miles traveled
float hours; //time in hours
float milesPerHour; //calculated miles per hour
cout << "Please input the Miles traveled" << endl;
cin >> miles;
cout << "Please input the hours traveled" << endl;
cin >> hours;
// Function call here
……………………………………………………………………..
cout << fixed << showpoint << setprecision(2);
cout << "Your speed is " << milesPerHour << " miles per hour" << endl;
return 0;
}
// Function definition here
……………………………………………………………………..
In: Computer Science
Amdahl's law: Suppose you ran an application on a single
processor in 1.5 hours. Upon careful examination of the code, you
found out that the application is in fact 90% parallelizable.
a) If you can run this application on a computer with 10
processors, what would be the execution time?
b) If you can run this application on a computer with an unlimited
number of processors, what would be the execution
time?
In: Computer Science
I was given an assignment to write three sections of Code.
1. Look up password
2. Decrypt a password.
3. What website is this password for?
Here's the base code:
import csv
import sys
#The password list - We start with it populated for testing purposes
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]
#The password file name to store the passwords to
passwordFileName = "samplePasswordFile"
#The encryption key for the caesar cypher
encryptionKey=16
#Caesar Cypher Encryption
def passwordEncrypt (unencryptedMessage, key):
#We will start with an empty string as our encryptedMessage
encryptedMessage = ''
#For each symbol in the unencryptedMessage we will add an encrypted symbol into the encryptedMessage
for symbol in unencryptedMessage:
if symbol.isalpha():
num = ord(symbol)
num += key
if symbol.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif symbol.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26
encryptedMessage += chr(num)
else:
encryptedMessage += symbol
return encryptedMessage
def loadPasswordFile(fileName):
with open(fileName, newline='') as csvfile:
passwordreader = csv.reader(csvfile)
passwordList = list(passwordreader)
return passwordList
def savePasswordFile(passwordList, fileName):
with open(fileName, 'w+', newline='') as csvfile:
passwordwriter = csv.writer(csvfile)
passwordwriter.writerows(passwordList)
while True:
print("What would you like to do:")
print(" 1. Open password file")
print(" 2. Lookup a password")
print(" 3. Add a password")
print(" 4. Save password file")
print(" 5. Print the encrypted password list (for testing)")
print(" 6. Quit program")
print("Please enter a number (1-4)")
choice = input()
if(choice == '1'): #Load the password list from a file
passwords = loadPasswordFile(passwordFileName)
if(choice == '2'): #Lookup at password
print("Which website do you want to lookup the password for?")
for keyvalue in passwords:
print(keyvalue[0])
passwordToLookup = input()
####### YOUR CODE HERE ######
#You will need to find the password that matches the website
#You will then need to decrypt the password
#
#1. Create a loop that goes through each item in the password list
# You can consult the reading on lists in Week 5 for ways to loop through a list
#
#2. Check if the name is found. To index a list of lists you use 2 square backet sets
# So passwords[0][1] would mean for the first item in the list get it's 2nd item (remember, lists start at 0)
# So this would be 'XqffoZeo' in the password list given what is predefined at the top of the page.
# If you created a loop using the syntax described in step 1, then i is your 'iterator' in the list so you
# will want to use i in your first set of brackets.
#
#3. If the name is found then decrypt it. Decrypting is that exact reverse operation from encrypting. Take a look at the
# caesar cypher lecture as a reference. You do not need to write your own decryption function, you can reuse passwordEncrypt
#
# Write the above one step at a time. By this I mean, write step 1... but in your loop print out every item in the list
# for testing purposes. Then write step 2, and print out the password but not decrypted. Then write step 3. This way
# you can test easily along the way.
#
####### YOUR CODE HERE ######
if(choice == '3'):
print("What website is this password for?")
website = input()
print("What is the password?")
unencryptedPassword = input()
####### YOUR CODE HERE ######
#You will need to encrypt the password and store it in the list of passwords
#The encryption function is already written for you
#Step 1: You can say encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)]
#the encryptionKey variable is defined already as 16, don't change this
#Step 2: create a list of size 2, first item the website name and the second item the password.
#Step 3: append the list from Step 2 to the password list
####### YOUR CODE HERE ######
if(choice == '4'): #Save the passwords to a file
savePasswordFile(passwords,passwordFileName)
if(choice == '5'): #print out the password list
for keyvalue in passwords:
print(', '.join(keyvalue))
if(choice == '6'): #quit our program
sys.exit()
print()
print()
In: Computer Science
USE R TO WRITE THE CODES!
# 2. More Coin Tosses
Experiment: A coin toss has outcomes {H, T}, with P(H) = .6.
We do independent tosses of the coin until we get a head.
Recall that we computed the sample space for this experiment in class, it has infinite number of outcomes.
Define a random variable "tosses_till_heads" that counts the
number of tosses until we get a heads.
```{r}
```
Use the replicate function, to run 100000 simulations of this
random variable.
```{r}
```
Use these simulations to estimate the probability of getting a head
after 15 tosses. Compare this with the theoretical value computed
in the lectures.
```{r}
```
Compute the probability of getting a head after 50 tosses. What do
you notice?
```{r}
In: Computer Science
Write a C ++ program
that asks the user for the speed of a vehicle (in miles per hour)
and how many hours it has traveled. The program should then use a
loop to display the distance the vehicle has traveled for each hour
of that time period. Here is an example of the output:
What is the speed of the vehicle in mph? 40
How many hours has it traveled? 3
Hour Distance Traveled
--------------------------------
1
40
2
80
3
120
Input Validation: Do not accept a negative number for speed and do
not accept any value less than 1 for time traveled.
Distance
Traveled
The distance a vehicle travels can be calculated as follows:
distance = speed * time
For example, if a train travels 40 miles per hour for 3 hours, the
distance traveled is 120 miles.
In: Computer Science
1. The functional dependencies for the ProAudio relation:
c_id -> f_name, l_name, address, city, state, zip
item_id -> title, price
ord_no -> c_id, order_date
ord_no + item_id -> shipped
zip -> city, state
Original ProAudio relation:
| c_id | f_name | I_name | address | city | state | zip | ord_no | item_id | title | price | order_date | shipped |
| 01 | Jane | Doe | 123 Elm St | Ely | NV | 11111 | 1-1 | 12-31 | More Blues | 8.99 | 12-2-00 | no |
| 02 | Fred | Fish | 321 Oak St | Ely | NV | 11111 | 2-1 | 21-12 | Jazz Songs | 9.99 | 11-9-00 | yes |
| 01 | Jane | Doe | 123 Elm St | Ely | NV | 11111 | 1-2 | 12-21 | The Blues | 8.99 | 12-2-00 | yes |
determining functional dependencies for ProAudio database
Normalization is a set of rules that ensures the proper design of a database. In theory, the higher the normal form, the stronger the design of the database.
Use the file for Functional Dependencies Above to answer the following questions:
Now that you are familiar with the mission statement and the entities and attributes the for ProAudio:
In: Computer Science
After reading the Biography in Context database entries on Bill Gates and Steve Jobs, briefly compare and contrast these two leaders of industry. Considering that while both are quite different, observe some unifying qualities.
In: Computer Science
How would you write the following recursively? This is in Java.
public static String allTrim(String str) {
int j = 0;
int count = 0; // Number of extra spaces
int lspaces = 0;// Number of left spaces
char ch[] = str.toCharArray();
int len = str.length();
StringBuffer bchar = new StringBuffer();
if (ch[0] == ' ') {
while (ch[j] == ' ') {
lspaces++;
j++;
}
}
for (int i = lspaces; i < len; i++) {
if (ch[i] != ' ') {
if (count > 1 || count == 1) {
bchar.append(' ');
count = 0;
}
bchar.append(ch[i]);
} else if (ch[i] == ' ') {
count++;
}
}
return bchar.toString();
}
In: Computer Science
Any ideas?
You work in the IT group of a department store and the
latest analytics shows there is a bug that
allows customers to go over their credit limit. The company's
president has asked you to develop a
new algorithm to solve this problem.
Create your algorithm using pseudocode that determines if a
department store customer has
exceeded their credit limit. Be sure you gather the following
inputs from the user:
• Account number
• Balance of the account
• Total cost of all the products the customer is looking to
purchase
• Allowed credit limit
After you gather the inputs, make sure your algorithm calculates if
the user can purchase the
products and provides a message to the user indicating if the
purchase is approved or declined.
In: Computer Science
Write a single, complete If-else-if segment of code based on a variable called ‘Average’ which will process the following task:
Variable=average;
If (average >=95);
{
messagebox.show(“you made the deans list”);
}
(B) Display "You made the Optimate Society” if Average >= 90
Else if (average>=90);
}
Messagebox.show(“you made the Optimate Society”);
}
(C) Otherwise Display "You need a 90 to make an honors list"
Else if (average <=89);
{
Messagebox.show(“you need a 90 to make an honors list”);
In: Computer Science
Write a program that prompts for the lengths of the sides of a triangle and reports the three angles. Make sure you have a good introduction stating what the program does when it is run, and a helpful prompt for the user when asking for input:
i.e. Here is the generated output from a sample program:
This program computes the angles of a triangle given the lengths of the sides.
What is the length of side 1? <wait for user input>
What is the length of side 2? <wait for user input>
What is the length of side 3? <wait for user input>
angle 1 = <angle in degrees for side 1, side 2, and side 3>
angle 2 = <angle in degrees for side 2, side 3, and side 1>
angle 3 = <angle in degrees for side 3, side 1, and side 2>
Requirements
Your program must have at least 1 function with parameters, that when called with arguements returns a value.
Hints
Save your program as triangle_angles.py and attach it.
In: Computer Science
Which of the following statement will, move the file pointer to the third ‘r’ in the file show below. Assume the newline character is 1 byte. Select all that apply.
With
great
power
comes
great
responsibility
Answers:
Spidey.seekg(-19L, ios:end);
Spidey.seekg(‘r’, ios:beg);
Spidey.seekg(24, ios:cur);
Spidey.seekg(“r?r?r”, ios:beg);
In: Computer Science
Describe PowerShell and give examples of the syntax.
In: Computer Science
You are expected to design a circuit with (3bit)counter and skip
next signal with other necessary control signals to complete your
labwork.
You have to include your gdf file and simulation
file(scf).
Zip/Rar your project files.
In: Computer Science