Answer:
1
def dict_intersect(d1,d2): #create dictionary
d3={} #dictionaries
for key1,value1 in d1.items(): #iterate through the loop
if key1 in d2: #checking condition
d3[key1]=(d1[key1],d2[key1]) #add the items into the dictionary
return d 3
print(dict_intersect({'a': 'apple', 'b': 'banana'}, {'b': 'bee', 'c': 'cat'})) #display
2
def consolidate(*l1): #create consolidate
d3={} # create dictionary
for k in l1: #iterate through the loop
for number in k: #iterate through the loop d3[number]=d3.get(number,0)+1 #increment the value
return d 3 #return
print(consolidate([1,2,3], [1,1,1], [2,4], [1])) #display
Explanation:
1
Following are the description of program
Create a dictionary i.e"dict_intersect(d1,d2) " in this dictionary created a dictionary d3 .After that iterated the loop and check the condition .If the condition is true then add the items into the dictionary and return the dictionary d3 .Finally print them that are specified in the given question .2
Following are the description of program
Create a dictionary consolidate inside that created a dictionary "d3" .After that iterated the loop outer as well as inner loop and increment the value of items .Return the d3 dictionary and print the dictionary as specified in the given question .
what is computer aided design
Which of the following is true about operating system.
a. acts as an intermediary between the computer user and the computer hardware.
b. program that manages the computer hardware.
c. provides a basis for application progra
Answer:
google kis kam ka hai us se puch lo
Consider that a large online company that provides a widely used search engine, social network, and/or news service is considering banning ads for the following products and services from its site: e-cigarettes, abortion clinics, ice cream, and sugared soft drinks. Which, if any, do you think they should ban? Give reasons. In particular, if you select some but not all, explain the criteria for distinguishing.
Answer:
I think that they should ban ads for all four products. These products, e-cigarettes, abortion clinics, ice cream, and sugared soft drinks, are all discreet adult products that should not be advertised because of their health hazards. Since the "large online company provides a widely used search engine, social network, and/or news service, which are mainly patronized by younger people, such ads that promote products injurious to individual health should be banned. Those who really need or want these products know where they could get them. Therefore, the products should not be made easily accessible to all people. Nor, should ads promote their patronage among the general population.
Explanation:
Advertisements create lasting and powerful images which glamourize some products, thereby causing the general population, especially children, to want to consume them without any discrimination of their health implications. If online banning is then contemplated, there should not be any distinguishing among the four products: e-cigarettes, abortion clinics, ice cream, and sugared soft drinks.
A vSphere Administrator is receiving complaints a database VM is experiencing performance issues. The VM is a member of the high priority resource pool and the cluster has not experienced contention.
Which condition should be checked to address immediate performance concerns?
A. VM snapshots
B. VMFS version
C. Resource Pool share value
D. Configured CPU shares
Answer:
C. Resource Pool share value.
Explanation:
The vSphere is a term used to describe the VMware’s virtualization cloud platform. The vSphere comprises of the following, vCenter Server, ESXi, Virtual Machine File System (VMFS) and vCenter Client.
If a vSphere Administrator receive complaints that a database Virtual Machine (VM) is experiencing performance issues and the Virtual Machine (VM) is a member of the high priority resource pool and the cluster has not experienced contention.
In order to address immediate performance concerns, the vSphere Administrator should check the Resource Pool share value.
VMware resource pool refers to the aggregated central processing unit and memory allocated to a Virtual Machine (VM) for flexible management of the resources.
Also, the vSphere Administrator should install VMware tools to check which processes are having high CPU usage by using vimtop, as well as checking if vCenter Server is swapping.
Write a program that asks the user to enter either an "African" or a "European" swallow. The programâs behaviour should mimic the program below. If the user enters something øther than "African" or "European", the program shøuld insult the user like the example below.
Sample Output #1:
What kind of swallow?
African
Yes, it could grip it by the husk.
Sample Output #2:
What kind of swallow?
European
A five-ounce bird could not carry a one-pound coconut.
Sample Output #3:
What kind of swallow?
Spanish
You really are not fit to be a king.
Answer:
The programming language is not stater; However, I'll answer this question using C++.
This program does not use comments (See explanation)
See Attachment for program file
Program starts here
#include <iostream>
using namespace std;
int main()
{
string response;
cout<<"What kind of swallow?\n";
cin>>response;
for(int i =0; i<response.length();i++)
{
response[i]=toupper(response[i]);
}
if(response == "AFRICAN")
{
cout<<"Yes, it could grip it by the husk.";
}
else if(response == "EUROPEAN")
{
cout<<"A five-ounce bird could not carry a one-pound coconut.";
}
else
{
cout<<"You really are not fit to be a king.";
}
return 0;
}
Explanation:
string response; -> A string variable to hold user input is declared
cout<<"What kind of swallow?\n"; -> prompts user for input
cin>>response; -> user input is stored here
The following iteration converts user input to uppercase; so that the program will work for inputs like African, AFRICAN, AFriCAN, etc.
for(int i =0; i<response.length();i++)
{
response[i]=toupper(response[i]);
}
The following if statement prints "Yes, it could grip it by the husk." if user input is AFRICAN
if(response == "AFRICAN")
{
cout<<"Yes, it could grip it by the husk.";
}
Otherwise, if user input is EUROPEAN, it prints; "A five-ounce bird could not carry a one-pound coconut."
else if(response == "EUROPEAN")
{
cout<<"A five-ounce bird could not carry a one-pound coconut.";
}
Lastly; for every inputs different from AFRICAN and EUROPEAN, the program displays "You really are not fit to be a king."
else
{
cout<<"You really are not fit to be a king.";
}
An introduction to object-oriented programming.
Write a GUI program named EggsInteractiveGUI that allows a user to input the number of eggs produced in a month by each of five chickens. Sum the eggs, then display the total in dozens and eggs. For example, a total of 127 eggs is 10 dozen and 7 eggs.
Answer:
The csharp program is given below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button6_Click(object sender, EventArgs e)
{
int total = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text) + Convert.ToInt32(textBox3.Text) + Convert.ToInt32(textBox4.Text) + Convert.ToInt32(textBox5.Text));
int dozen = total / 12;
int eggs = total % 12;
textBox6.Text = dozen.ToString();
textBox7.Text = eggs.ToString();
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
}
private void button8_Click(object sender, EventArgs e)
{
Close();
}
}
}
Explanation:
1. The integer variables are declared for total eggs, number of dozens and number of eggs.
2. The input of each text box is converted into integer by using the Convert.ToInt32() method on the value of that particular text box.
3. All the inputs are added and the sum is assigned to variable, total.
4. The number of dozens are obtained by dividing total by 12 and assigning the value to the variable, dozen.
5. The number of extra eggs are obtained by taking the modulus of total and 12 and the value is assigned to the variable, eggs.
6. The integer values in the variables, dozen and eggs, are converted into string using the ToString() function with that particular value.
dozen.ToString();
eggs.ToString();
7. The text boxes are assigned the respective values of dozens and number of eggs.
textBox6.Text = dozen.ToString();
textBox7.Text = eggs.ToString();
8. Two additional buttons, clear and exit, are also added.
9. The clear button erases the contents of all the text boxes. The Text property of each textbox is set to “” thereby clearing all the text fields.
10. The exit button closes the application using Close() function.
11. The program is made in visual studio and the output is attached.
In this challenge you will use the file regex_replace_challenge_student.py to:
Write a regular expression that will replace all occurrences of:
regular-expression
regular:expression
regular&expression
In the string: This is a string to search for a regular expression like regular expression or regular-expression or regular:expression or regular&expression
Assign the regular expression to a variable named pattern
Using the sub() method from the re package substitute all occurrences of the 'pattern' with 'substitution'
Assign the outcome of the sub() method to a variable called replace_result
Output to the console replace_results
Regular Expression Replace Challenge
The Python statement containing the string to search for the regular expression occurrence is below. search_string=’’’This is a string to search for a regular expression like regular expression or regular-expression or regular:expression or regular&expression’’’
Write a regular expression that will find all occurrences of:
a. regular expression
b. regular-expression
c. regular:expression
d. regular&expression in search_string
Assign the regular expression to a variable named pattern
The Python string below is used for substitution substitution="regular expression"
Using the sub() method from the re package substitute all occurrences of the ‘pattern’ with ‘substitution’
Assign the outcome of the sub() method to a variable called replace_result
Output to the console replace_results
import re
#The string to search for the regular expression occurrence (This is provided to the student)
search_string='''This is a string to search for a regular expression like regular expression or
regular-expression or regular:expression or regular&expression'''
#1. Write a regular expression that will find all occurrances of:
# a. regular expression
# b. regular-expression
# c. regular:expression
# d. regular&expression
# in search_string
#2. Assign the regular expression to a variable named pattern
#The string to use for subsitution (This is provided to the student)
substitution="regular expression"
#3. Using the sub() method from the re package substitute all occurrences of the 'pattern' with 'substitution'
#4. Assign the outcome of the sub() method to a variable called replace_result
#5. Output to the console replace_results
Answer:
Please follow the code indentation for the python program.
Explanation:
Describe and list advantages and disadvantages of each of the following backup types:
full, differential, incremental, selective, CPD, and cloud.
Answer:
Full back up
It creates complete copy of the source of data. This feature made it to the best back up with good speed of recovery of the data and simplicity.However, because it is needed for backing up of a lot of data, it is time consuming process,Besides it also disturbs the routine application of the technologist infrastructure. In addition large capacity storage is needed for the storage of the large volume of back up with each new creation.
Incremental back up: back up work at high speed thus saves time, Little storage capacity is needed. This type of back up can be run as many time as wished.
However, the restoration of data takes time, due to the time spent for restoration of initial back up and the incremental.
Differential Back up has very fast back up operation, because it only requires two pieces of back up.This is however slower compare to the Incremental.
The selective back up enable selection of certain type of file or folders for back up.
it can only be used to back up folders only when important data are needed only.Thus the storage capacity is low.
CPD eliminates back up window and reduces the recovery point objective.However, it has issue of compatibility with the resources to back up.,it is also expensive because its solutions are disk based.
Cloud based is affordable and save cost,It is easier to access. it is efficient,it can be access remotely for convenience.
However, Internet sources and some bandwidth must be available for access., always depends on third party providers,There is also problems encountered when switching providers.
Explanation:
During an investigation of a cybercrime, the law enforcement officers came across a computer that had the hard drive encrypted. Chose the best course of action they should take to access the data on that drive.
a. Use image filtering techniques to see what's behing the encrypted files.
b. Try to convince the owner of the computer to give you to decryption key/password.
c. Identify the encryption algorithm and attempt a brute force attack to get access to the file.
d. Disconnect the hard drive from power so the encryption key can be exposed on the next power up.
e. Try to copy the drive bit by bit so you can see the files in each directory.
Answer:
b. Try to convince the owner of the computer to give you to decryption key/password.
Explanation:
Encrypted hard drives have maximum security and high data protection. to access them you need to enter a password to unlock them.
The image filtering technique is a method that serves to selectively highlight information contained in an image, for which it does not work.
The encryption algorithm is a component used for the security of electronic data transport, not to access data on an encrypted hard drive.
The encryption key is used in encryption algorithms to transform a message and cannot be exposed by disconnecting the hard drive from its power source.
What program is best for teaching young people code?
What did Aristotle teach?
Philosophy, I beleive. He tought Sikander liturature and eloquence, but his most famous teachings were of philosophy.
Aristotle taught the world science. He was considered the best scientists of his time.
You have recently resolved a problem in which a user could not print to a particular shared printer by upgrading her workstation's client software. Which of the following might be an unintended consequence of your solution?
a. The user complains that word-processing files on her hard disk take longer to open.
b. The user is no longer able to log on to the network.
c. The shared printer no longer allows users to print double-sided documents.
d. The shared printer no longer responds to form-feed commands from the print server.
Answer:
B - The user is no longer able to log on to the network
Explanation:
Write a program that reads a list of words. Then, the program outputs those words and their frequencies. Ex: If the input is: hey hi Mark hi mark the output is: hey 1 hi 2 Mark 1 hi 2 mark 1
Answer:
#Declare variable to get the input
#list from the user
input_list = input()
#split the list into words by space
list = input_list.split()
#Begin for-loop to iterate each word
#to get the word frequency
for word in list:
#get the frequency for each word
frequency=list.count(word)
#print word and frequency
print(word,frequency)
Explanation:
This program that we are told to write will be done by using python programming language/ High-level programming language.
The question wants us to write a program in which the output will be as below;
hey 1
hi 2
Mark 1
hi 2
mark 1
Just by imputing hey hi mark hi mark.
Just copy and run the code below.
#Declare variable to get the input
#list from the user
input_list = input()
#split the list into words by space
list = input_list.split()
#Begin for-loop to iterate each word
#to get the word frequency
for word in list:
#get the frequency for each word
frequency=list.count(word)
#print word and frequency
print(word,frequency)
In this exercise we have to use the knowledge in computational language in python to write the following code:
We have the code can be found in the attached image.
So in an easier way we have that the code is
input_list = input()
list = input_list.split()
for word in list:
frequency=list.count(word)
print(word,frequency)
See more about python at brainly.com/question/18502436
Write a Python program that can compare the unit (perlb) cost of sugar sold in packages with different weights and prices. The program prompts the user to enter the weight and price of package 1, then does the same for package 2, and displays the results to indicate sugar in which package has a better price. It is assumed that the weight of all packages is measured in lb. The program should check to be sure that both the inputs of weight and price are both positive values.
Answer:
This program is written using python
It uses less comments (See explanation section for more explanation)
Also, see attachments for proper view of the source code
Program starts here
#Prompt user for price of package 1
price1 = int(input("Enter Price 1: "))
while(price1 <= 0):
price1 = int(input("Enter Price 1: "))
#Prompt user for weight of package 1
weight1 = int(input("Enter Weight 1: "))
while(weight1 <= 0):
weight1 = int(input("Enter Weight 1: "))
#Calculate Unit of Package 1
unit1 = float(price1/weight1)
print("Unit cost of Package 1: "+str(unit1))
#Prompt user for price of package 2
price2 = int(input("Enter Price 2: "))
while(price2 <= 0):
price2 = int(input("Enter Price 2: "))
#Prompt user for weight of package 2
weight2 = int(input("Enter Weight 2: "))
while(weight2 <= 0):
weight2 = int(input("Enter Weight 2: "))
#Calculate Unit of Package 2
unit2 = float(price2/weight2)
print("Unit cost of Package 2: "+str(unit2))
#Compare units
if unit1 > unit2:
print("Package 1 has a better price")
elif unit1 == unit2:
print("Both Packages have the same price")
else:
print("Package 2 has a better price")
Explanation:
price1 = int(input("Enter Price 1: ")) -> This line prompts the user for price of package 1
The following while statement is executed until user inputs a value greater than 1 for price
while(price1 <= 0):
price1 = int(input("Enter Price 1: "))
weight1 = int(input("Enter Weight 1: ")) -> This line prompts the user for weight of package 1
The following while statement is executed until user inputs a value greater than 1 for weight
while(weight1 <= 0):
weight1 = int(input("Enter Weight 1: "))
unit1 = float(price1/weight1) -> This line calculates the unit cost (per weight) of package 1
print("Unit cost of Package 1: "+str(unit1)) -> The unit cost of package 1 is printed using this print statement
price2 = int(input("Enter Price 2: ")) -> This line prompts the user for price of package 2
The following while statement is executed until user inputs a value greater than 1 for price
while(price2 <= 0):
price2 = int(input("Enter Price 2: "))
weight2 = int(input("Enter Weight 2: ")) -> This line prompts the user for weight of package 2
The following while statement is executed until user inputs a value greater than 1 for weight
while(weight2 <= 0):
weight2 = int(input("Enter Weight 2: "))
unit2 = float(price2/weight) -> This line calculates the unit cost (per weight) of package 2
print("Unit cost of Package 2: "+str(unit2)) -> The unit cost of package 2 is printed using this print statement
The following if statements compares and prints which package has a better unit cost
If unit cost of package 1 is greater than that of package 2, then package 1 has a better priceIf unit cost of both packages are equal then they both have the same priceIf unit cost of package 2 is greater than that of package 1, then package 2 has a better priceif unit1 > unit2:
print("Package 1 has a better price")
elif unit1 == unit2:
print("Both Packages have the same price")
else:
print("Package 2 has a better price")
Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $5,000 in sales in a week receives $200 plus 9% of $5,000, or a total of $650. Write an app (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson's salary is an integer). a) $200–299
b) $300–399
c) $400–499
d) $500–599
e) $600–699
f) $700–799
g) $800–899
h) $900–999
i) $1000 and over
Summarize the results in tabular format.
Answer: Provided in the explanation section
Explanation:
import java.util.Scanner;
public class commission
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int totals[]={0,0,0,0,0,0,0,0,0};
int n,sales,i,index;
double salary;
System.out.print("how many salesmen do you have? ");
n=input.nextInt();
for(i=1;i<=n;i++)
{System.out.print("Salesman "+i+" enter sales: ");
sales=input.nextInt();
salary=200+(int)(.09*sales);
System.out.printf("Salary=$%.2f\n",salary);
index=(int)salary/100-2;
if(index>8)
index=8;
totals[index]++;
}
System.out.println("SUMMARY\nSALES\t\tCOUNT");
for(i=0;i<8;i++)
System.out.println("$"+(i*100+200)+"-"+(i*100+299)+"\t"+totals[i]);
System.out.println("$1000 and over\t"+totals[i]);
}
}
cheers i hope this helped !!
Consider a recurrent neural network that listens to a audio speech sample, and classifies it according to whose voice it is. What network architecture is the best fit for this problem
Answer:
Many-to-one (multiple inputs, single output)
Explanation:
Solution
In the case of a recurrent neural network that listens to a audio speech sample, and classifies it according to whose voice it is, the RNN will listen to the audio and will give result by doing classification.
There will be a single output, for the classified or say identified person.
The RNN will take a stream of input as the input is a audio speech sample.
Therefore, there will be multiple inputs to the RNN and a single output, making the best fit Architecture to be of type Many-to-one(multiple inputs, single output).
A new operating system uses passwords that consist of three characters. Each character must be a digit between 0 and 9. For example, three distinct possible passwords are 123, 416, and 999. The system uses 32-bit salt values. The system also allows one login attempt every second and never locks out users regardless of how many failed attempts occur. If an adversary has obtained a copy of the password file and conducts an offline brute-force attack by trying every password combination until the adversary obtains username and password combination. The use of a 32-bit salt value
Answer:
Brute force is technique that is used for cracking password
In this case the system uses only three characters(0-9). By applying Brute force attack in "hit and try" manner we easily crack the password.
Explanation:
Solution
There are a wide variety of password cracking mechanisms.Brute force is one of the popular password cracking technique.Brute force attack is generally used to crack small passwords.
In the given example the system uses only three characters(0-9).By using Brute force attack in "hit and try" manner we easily crack the password.There are only 10 possible passwords for this type of system.Because we can arrange 0-9 only in 10 ways.But for Systems with long passwords it is difficult to find it in hit and try manner.But instead of having plain password each password have a random salt value.
In a system of 32 bit salt value there are 2^32 different key values.
By increasing the salt value from 32 bits to 64 bits there are 2^64 different key values.It increases the time taken to crack a password for an attacker.so by changing salt value from 32 to 64 bits will make it more harder for the adversary's attack to be successful.
Given main(), define the Team class (in file Team.java). For class method getWinPercentage(), the formula is:teamWins / (teamWins + teamLosses)Note: Use casting to prevent integer division.Ex: If the input is:Ravens133 where Ravens is the team's name, 13 is number of team wins, and 3 is the number of team losses, the output is:Congratulations, Team Ravens has a winning average!If the input is Angels 80 82, the output is:Team Angels has a losing average.Here is class WinningTeam:import java.util.Scanner;public class WinningTeam {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);Team team = new Team();String name = scnr.next();int wins = scnr.nextInt();int losses = scnr.nextInt();team.setTeamName(name);team.setTeamWins(wins);team.setTeamLosses(losses);if (team.getWinPercentage() >= 0.5) {System.out.println("Congratulations, Team " + team.getTeamName() +" has a winning average!");}else {System.out.println("Team " + team.getTeamName() +" has a losing average.");}}}
Answer:
Explanation:
public class Team {
private String teamName;
private int teamWins;
private int teamLosses;
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public int getTeamWins() {
return teamWins;
}
public void setTeamWins(int teamWins) {
this.teamWins = teamWins;
}
public int getTeamLosses() {
return teamLosses;
}
public void setTeamLosses(int teamLosses) {
this.teamLosses = teamLosses;
}
public double getWinPercentage() {
return teamWins / (double) (teamWins + teamLosses);
}
}
Following are the Java program to define the Team class and calculate its value:
Class Definition:class Team //defining the class Team
{
private String teamName;//defining String variable
private int teamWins, teamLosses;//defining integer variable
//defining the set method to set value the input value
public void setTeamName(String teamName)//defining setTeamName method that takes one String parameter
{
this.teamName = teamName;//using this keyword that sets value in teamName
}
public void setTeamWins(int teamWins) //defining setTeamWins method that takes one integer parameter
{
this.teamWins = teamWins;//using this keyword that sets value in teamWins
}
public void setTeamLosses(int teamLosses)//defining setTeamLosses method that takes one integer parameter
{
this.teamLosses = teamLosses;//using this keyword that sets value in teamLosses
}
//defining the get method that returns the input value
public String getTeamName() //defining getTeamName method
{
return teamName;//return teamName value
}
public int getTeamWins() //defining getTeamWins method
{
return teamWins;//return teamWins value
}
public int getTeamLosses() //defining getTeamLosses method
{
return teamLosses;//return teamLosses value
}
public double getWinPercentage()//defining getWinPercentage method
{
return ((teamWins * 1.0) / (teamWins + teamLosses));//using the return keyword that returns percentage value
}
}
Please find the complete code in the attached file and its output file in the attached file.
Class definition:
Defining the class "Team".Inside the class two integer variable "teamWins, teamLosses" and one string variable "teamName" is declared.In the next step, the get and set method is defined, in which the set method is used to set the value, and the get method is used to return the value.Find out more about the Class here:
brainly.com/question/17001900
Write a Java program that reads from the user four grades between 0 and 100. The program the, on separate ines, prints out the entered grades followed by the highest grade, lowest grade, and averages of all four grades. Make sure to properly label your output. Use escape characters to line up the outputs after the labels.
Answer:
import java.util.*;
public class Grade {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double[] grades = new double[4];
for (int i=0; i<4; i++){
System.out.print("Enter a grade: ");
grades[i] = input.nextDouble();
}
double lowest = grades[0];
double highest = grades[0];
double total = 0;
for (int i=0; i<4; i++){
System.out.println("Grade " + (i+1) + " is: " + grades[i]);
if(grades[i] >= highest)
highest = grades[i];
if(grades[i] <= lowest)
lowest = grades[i];
total += grades[i];
}
double average = total/4;
System.out.println("The highest grade is: " + highest);
System.out.println("The lowest grade is: " + lowest);
System.out.println("The average is: " + average);
}
}
Explanation:
Ask the user for the grades and put them in the grades array using a for loop
Create another for loop. Inside the loop, print the grades. Find highest and lowest grades in the grades array using if-structure. Also, add each grade to the total.
When the loop is done, calculate the average, divide the total by 4.
Print the highest grade, lowest grade and average.
Larry sees someone he finds annoying walking toward him. Larry purposely looks away and tries to engage in conversation with someone else. Which type of eye behavior is Larry using?
a. mutual lookingb. one-sided lookingc. gaze aversiond. civil inattentione. staring
Answer:
one-sided looking
Explanation:
Larry purposely looks away
In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Hill cipher where the Hill matrix can be any size from 2 x 2 up to 9 x 9. The program can be written using one of the following: C, C++, or Java. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below.Command Line Parameters1. Your program compile and run from the command line.2. The program executable must be named "hillcipher" (all lowercase, no spaces or file extension).3. Input the required file names as command line parameters. Your program may NOT prompt the user to enter the file names. The first parameter must be the name of the encryption key file, as described below. The second parameter must be the name of the file to be encrypted, as also described below. The sample run command near the end of this document contains an example of how the parameters will be entered.4. Your program should open the two files, echo the input to the screen, make the necessary calculations, and then output the ciphertext to the console (terminal) screen in the format described below.Note: If the plaintext file to be encrypted doesn't have the proper number of alphabetic characters, pad the last block as necessary with the letter 'X'. It is necessary for us to do this so we can know what outputs to expect for our test inputs.
Answer: Provided in the explanation section
Explanation:
C++ Code
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
// read plain text from file
void readPlaneText(char *file,char *txt,int &size){
ifstream inp;
inp.open(file);
// index initialize to 0 for first character
int index=0;
char ch;
if(!inp.fail()){
// read each character from file
while(!inp.eof()){
inp.get(ch);
txt[index++]=ch;
}
}
// size of message
size=index-1;
}
// read key
int **readKey(char *file,int **key,int &size){
ifstream ink;
//
ink.open(file);
if(!ink.fail()){
// read first line as size
ink>>size;
// create 2 d arry
key=new int*[size];
for(int i=0;i<size;i++){
key[i]=new int[size];
}
// read data in 2d matrix
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
ink>>key[i][j];
}
}
}
return key;
}
// print message
void printText(string txt,char *msg,int size){
cout<<txt<<":\n\n";
for(int i=0;i<size;i++){
cout<<msg[i];
}
}
// print key
void printKey(int **key,int size){
cout<<"\n\nKey matrix:\n\n";
for(int i=0;i<size;i++){
for(int j=0;j<size;j++){
cout<<key[i][j]<<" ";
}
cout<<endl;
}
}
void encrypt(char *txt,int size,int **key,int kSize,char *ctxt){
int *data=new int[kSize];
for(int i=0;i<size;i=i+kSize){
// read key size concecutive data
for(int a=0;a<kSize;a++){
data[a]=txt[i+a]-'a';
}
// cipher operation
for(int a=0;a<kSize;a++){
int total=0;
for(int b=0;b<kSize;b++){
total+=key[a][b]*data[b];
}
total=total%26;
ctxt[i+a]=(char)('a'+total);
}
}
}
int main(int argc,char **argv){
char text[10000];
char ctext[10000];
int **key;
int keySize;
int size;
// input
key=readKey(argv[1],key,keySize);
readPlaneText(argv[2],text,size);
encrypt(text,size,key,keySize,ctext);
// output
printKey(key,keySize);
cout<<endl<<endl;
printText("Plaintext",text,size);
cout<<endl<<endl;
printText("Ciphertext",ctext,size);
return 0;
}
cheers i hope this helped !!!
The following if statement uses an overloaded > operator to determine whether the price of a Car object is more than $5000. Car is a struct and myCar is an object of Car. Each Cor object has two variables: id (int) and price (float). As you can see in the following code, the ID of myCar is 12345 and the price is $6,000. Car myCar - [12345, 6000.); float price - 5000; if (myCar > price) cout << "My car price is more than $5,000/n": Which one of the following function prototypes is correct syntax to overload the > operator based on the if statement above. void operator> float price: O bool operator>(Car & car, float price): bool operator (float amt): bool operator> Car & your Car): None of the above
Answer:
The correct syntax to overload is bool operator (float amt): so, the third statement is right.
Explanation:
Solution
From the given question we have to find which statements is correct for the following function prototype.
Now,
Since the price of a Car object is above $5000, the car here is considered a struct and myCar is an object of Car
Both Car object consists of two variables which are id (int) and price (float)
Thus, from the given example the corresponding code says that the ID of myCar is represented as follows:
myCar - [12345, 6000);
The float price = 5000
Then,
cout << "My car price is more than $5,000/n"
Therefore the following statement bool operator (float amt): is the right syntax to overload.
a. A programmer wrote a software delay loop that counts the variable (unsigned int counter) from 0 up to 40,000 to create a small delay. If the user wishes to double the delay, can they simply increase the upperbound to 80,000?
b. If the code contains a delay loop and we noticed that no delay is being created at run-time. What should we suspect during debugging?
Answer:
Explanation:
The objective here is to determine if the programmer can simply increase the upperbound to 80,000.
Of course Yes, The programmer can simply increase the delay by doubling the upperbound by 80000. The representation can be illustrated as:
( int : i = 0; i < 40,000; i ++ )
{
// delay code
}
Which can be modified as:
( int : i = 0; i < 80,000; i ++ )
{
// delay code
}
b) If the code contains a delay loop and we noticed that no delay is being created at run-time. What should we suspect during debugging?
Assuming there is no delay being created at the run-time,
The code is illustrated as:
For ( int : i = 0 ; i < 0 ; i ++ )
{
// delay code which wont
//execute since code delay is zero
}
we ought to check whether the loop is being satisfied or not. At the Initial value of loop variable, is there any break or exit statement is being executed in between loop. Thus, the aforementioned delay loop wont be executed since the loop wont be executed for any value of i.
import java.util.Scanner; public class ArraySum { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); final int NUM_ELEMENTS = 8; // Number of elements int[] userVals = new int[NUM_ELEMENTS]; // User numbers int i = 0; // Loop index int sumVal = 0; // For computing sum // Prompt user to populate array System.out.println("Enter " + NUM_ELEMENTS + " integer values..."); for (i = 0; i < NUM_ELEMENTS; ++i) { System.out.print("Value: "); userVals[i] = scnr.nextInt(); } // Determine sum sumVal = 0; for (i = 0; i < NUM_ELEMENTS; ++i) { sumVal = sumVal + userVals[i]; } System.out.println("Sum: " + sumVal); return; } }
Answer:
There's nothing wrong with the question you posted except that it's not well presented or arranged.
When properly formatted, the program will be error free and it'll run properly.
The programming language used in the question is Java programming lamguage.
in java, the sign ";" signifies the end of each line and lines that begins with // represent comments. Using this understanding of end of lines and comments, the formatted code goes thus
import java.util.Scanner;
public class Arraysum {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
final int NUM_ELEMENTS = 8;
// Number of elements
int[] userVals = new int[NUM_ELEMENTS];
// User numbers
int i = 0;
// Loop index
int sumVal = 0;
// For computing sum
// Prompt user to populate array
System.out.println("Enter " + NUM_ELEMENTS + " integer values...");
for (i = 0; i < NUM_ELEMENTS; ++i) {
System.out.print("Value: ");
userVals[i] = scnr.nextInt();
}
// Determine sum
sumVal = 0;
for (i = 0; i < NUM_ELEMENTS; ++i)
{
sumVal = sumVal + userVals[i];
}
System.out.println("Sum: " + sumVal); return;
}
}
Also, see attachment for source file
Write a function called unzip that takes as parameter a sequence (list or tuple) called seq of tuples with two elements. The function must return a tuple where the first element is a list with the first members of the seq tuple and the second element is a list with the second members of the seq tuple.
This example clarifies what is required:
Ist =[(1, "one"), (2, "two"), (3, "three")]
tup= unzip(Lst) lst tup
print(tup)
#prints ([1, 2, 3], ['one', two','three'7)
Answer:
Here is the function unzip:
def unzip(lst):
result= zip(*lst)
return list(result)
The complete program in Python is given below:
def unzip(lst):
result= zip(*lst)
return list(result)
lst =[(1, "one"), (2, "two"), (3, "three")]
tup= unzip(lst)
print(tup)
Explanation:
Here zip() function is used in the unzip function. The return type of zip() function is a zip object. This means the function returns the iterator of tuples. This function can be used as its own inverse by using the * operator.
If you do not want to use zip() function then the above program can also be implemented as following which uses a for loop for elements in the given list (lst). This can make a pair of lists (2 tuple) instead of list of tuples:
def unzip(lst):
output = ([ a for a,b in lst ], [ b for a,b in lst ])
return output
lst =[(1, "one"), (2, "two"), (3, "three")]
tup= unzip(lst)
print(tup)
The programs along with their output are attached.
Which of the following statements about CASE is not true?CASE tools provide automated graphics facilities for producing charts.CASE tools reduce the need for end user participation in systems development.CASE tools have capabilities for validating design diagrams and specifications.CASE tools support collaboration among team members.CASE tools facilitate the creation of clear documentation
Answer:
CASE tools reduce the need for end user participation in systems development.
Explanation:
CASE is an acronym for Computer-aided Software Engineering and it comprises of software application tools that provide users with automated assistance for Software Development Life Cycle (planning, analysing, designing, testing, implementation and maintenance). The CASE tools helps software developers in reducing or cutting down of the cost and time of software development, as well as the enhancement of the software quality.
Some other benefits of using the CASE tools are;
- CASE tools provide automated graphics facilities for producing charts.
- CASE tools have capabilities for validating design diagrams and specifications.
- CASE tools support collaboration among team members.
- CASE tools facilitate the creation of clear documentation.
- CASE tools checks for consistency, syntax errors and completeness.
The CASE tools can be grouped as, requirement and structure analysis, software design, test-case and code generation, reverse engineering, and document production tools.
Examples of CASE tools are flowchart maker, visible analyst (VA), dreamweaver, net-beans, microsoft visio, adobe illustrator and photoshop etc.
Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex:
Initial scores: 10, 20, 30, 40
Scores after the loop: 30, 50, 70, 40
The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.
SAMPLE OUTPUT:
#include
int main(void) {
const int SCORES_SIZE = 4;
int bonusScores[SCORES_SIZE];
int i = 0;
bonusScores[0] = 10;
bonusScores[1] = 20;
bonusScores[2] = 30;
bonusScores[3] = 40;
/* Your solution goes here */
for (i = 0; i < SCORES_SIZE; ++i) {
printf("%d ", bonusScores[i]);
}
printf("\n");
return 0;
}
Answer:
Replace /* Your solution goes here */ with the following lines of code
for(i = 0;i<SCORES_SIZE-1;i++)
{
bonusScores[i]+=bonusScores[i+1];
}
Explanation:
The above iteration starts from the index element (element at 0) and stops at the second to the last element (last - 1).
Using an iterative variable, i
It adds the current element (element at i) with the next element; element at i + 1.
The full code becomes
#include<iostream>
using namespace std;
int main(void) {
const int SCORES_SIZE = 4;
int bonusScores[SCORES_SIZE];
int i = 0;
bonusScores[0] = 10;
bonusScores[1] = 20;
bonusScores[2] = 30;
bonusScores[3] = 40;
for(i = 0;i<SCORES_SIZE-1;i++)
{
bonusScores[i]+=bonusScores[i+1];
}
/* Your solution goes here */
for (i = 0; i < SCORES_SIZE; ++i) {
printf("%d ", bonusScores[i]);
}
printf("\n");
return 0;
}
See attachment for .cpp file
Answer:int main() {
const int SCORES_SIZE = 4;
int bonusScores[SCORES_SIZE];
int i;
for (i = 0; i < SCORES_SIZE; ++i) {
cin >> bonusScores[i];
}
for (i = 0; i < SCORES_SIZE-1; ++i){
bonusScores[i] += bonusScores[i+1];
}
for (i = 0; i < SCORES_SIZE; ++i) {
cout << bonusScores[i] << " ";
}
cout << endl;
return 0;
}
Explanation: SCORES_SIZE -1 will prevent the for loop from going past the last value in the array. bonusScores[i] += will add the value of bonusScores[i+1] to the original bonusScores[i].
for example, i = 1; 1 < SCORES_SIZE - 1 ; bonusScores[1] += bonusScores[1+1} becomes{ bonusScores[1] + bonusScores{2];
web pages with personal or biograpic information are called
Answer:
Web pages with personal or biographic information are called. a. Social Networking sites. c.
Explanation:
Type a statement using srand() to seed random number generation using variable seedVal. Then type two statements using rand() to print two random integers between (and including) 0 and 9. End with a newline. Ex: 5 7 Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, after calling srand() once, do not call srand() again. (Notes)
GIVEN:
#include
#include // Enables use of rand()
#include // Enables use of time()
int main(void) {
int seedVal = 0;
/* Your solution goes here */
return 0;
}
2). Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline. Ex:
101
133
Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, srand() has already been called; do not call srand() again.
GIVEN:
#include
#include // Enables use of rand()
#include // Enables use of time()
int main(void) {
int seedVal = 0;
seedVal = 4;
srand(seedVal);
/* Your solution goes here */
return 0;
}
Answer:
1. The solution to question 1 is as follows;
srand(seedVal);
cout<<rand()%10<<endl;
cout<<rand()%10<<endl;
2. The solution to question 2 is as follows
cout<<100+rand()%50 <<endl;
cout<<100+rand()%50 <<endl;
Explanation:
The general syntax to generate random number between interval is
Random Number = Lower Limit + rand() % (Upper Limit - Lower Limit + 1)
In 1;
The solution starts by calling srand(seedVal);
The next two statements is explained as follows
To print two random integers between intervals of 0 and 9 using rand()"
Here, the lower limit = 0
the upper limit = 9
By substituting these values in the formula above; the random number will be generated as thus;
Random Number = 0 + rand() % (9 - 0 + 1)
Random Number = 0 + rand() % (10)
Random Number = rand() % (10)
So, the instruction to generate the two random variables is rand() % (10)
2.
Similar to 1 above
To print two random integers between intervals of 100 and 149 using rand()"
Here, the lower limit = 100
upper limit = 149
By substituting these values in the formula above; the random number will be generated as thus;
Random Number = 100 + rand() % (149 - 100 + 1)
Random Number = 100 + rand() % (50)
So, the instruction to generate the two random variables is 100 + rand() % (50)
Write a program in python that can compare the unit (perlb) cost of sugar sold in packages with different weights and prices. The program prompts the user to enter the weight and price of package 1, then does the same for package 2, and displays the results to indicate sugar in which package has a better price. It is assumed that the weight of all packages is measured in lb. The program should check to be sure that both the inputs of weight and price are both positive values.
Answer:
weight1 = float(input("Enter the weight of first package: "))
price1 = float(input("Enter the price of first package: "))
weight2 = float(input("Enter the weight of second package: "))
price2 = float(input("Enter the price of second package: "))
if weight1 > 0 and price1 > 0 and weight2 > 0 and price2 > 0:
unit_cost1 = price1 / weight1
unit_cost2 = price2 / weight2
if unit_cost1 < unit_cost2:
print("Package 1 has a better price.")
else:
print("Package 2 has a better price.")
else:
print("All the entered values must be positive!")
Explanation:
*The code is in Python.
Ask the user to enter the weight and the price of the packages
Check if the all the values are greater than 0. If they are, calculate the unit price of the packages, divide the prices by weights. Then, compare the unit prices. The package with a smaller unit price has a better price.
If all the entered values are not greater than 0, print a warning message