Python 3.7:
Give the following sample code, write the following
programs:
• An iterator class called Iteratefirstn that implements __iter__()
and __next__() methods where next method should raise an exception
for the cur index if it is passed the last element otherwise set
cur index to the next index and advance the index by one, i.e. cur,
num = num, num+1. Instantiate the class to calculate the sum of
1000000 elements similar to the example.
• Instead of implementing the class, write a generator function
that does the same thing.
Sample code:
def firstn(n):
num, nums = 0, []
while num < n:
nums.append(num)
num += 1
return nums
sum_of_first_n = sum(firstn(1000000))
In: Computer Science
JAVA
I need to make it that I can expand the stack for everytime a push operation is performed that would normally cause an overflow, returning a false value. Should accompany 3 nodes initially.
DriverStack.java
public class DriverStack {
public static void main (String[] args)
{
Stack s = new Stack(3);
Listing l;
Listing l1 = new Listing ("Bill", "1st Avenue", "123 4567");
Listing l2 = new Listing ("Alec", "2nd Avenue", "456 4567");
Listing l3 = new Listing ("James", "3rd Avenue", "367 8896");
Listing l4 = new Listing ("Nico", "4th Avenue", "322 1156");
System.out.println(s.pop());
System.out.println(s.push(l1));
System.out.println(s.push(l2));
System.out.println(s.push(l3));
System.out.println(s.push(l4));
System.out.println("\n");
System.out.println("----------------All listings with one over
flow----------------" + "\n");
s.showAll(); //shows listings
System.out.println("----------------Tries to pop the Listing
'1'----------------" + "\n");
//Three pop operations
l = s.pop();
System.out.println(l.toString());
l = s.pop();
System.out.println(l.toString());
l = s.pop();
System.out.println(l.toString());
l = s.pop(); //will try to pop an already empty stack
System.out.println(l);
System.exit(0);
}
}
Stack.java
public class Stack
{
private Listing[] data;
private int top;
private int size;
public Stack()
{
top = -1;
size = 3;
data = new Listing[3];
}
public Stack (int n)
{
top = -1;
size = n;
data = new Listing[n];
}
public void settop()
{
top=-1;
}
public boolean push(Listing newNode)
{
if(top == size - 1)
return false; //overflow
else
{
top = top + 1;
data[top] = newNode.deepCopy();
return true;
}
}
public Listing pop()
{
int topLocation;
if(top == -1)
return null; //underflow error
else
{
topLocation = top;
top = top - 1;
return data[topLocation];
}
}
public void showAll()
{
for (int i = top; i >= 0; i--)
System.out.println(data[i].toString());
}
public void initialStack()
{
top = -1;
}
public boolean StackEmpty()
{
if(top == -1)
return true;
else
return false;
}
public boolean StackFull()
{
if(top == size-1)
return true;
else
return false;
}
public Listing peek()
{
if(StackEmpty())
{
System.out.println("Stack is underflow");
return null;
}
else
{
return data[top];
}
}
}
There is one more class called Listing but I dont think anything needs done with that.
Please comment next to the new code that was added, Thank you!
In: Computer Science
4NCA:
4.1 List ways in which secret keys can be distributed to two communicating parties.
4.2 What is the difference between a session key and a master key?
4.3 What is a key distribution center?
4.4 What entities constitute a full-service Kerberos environment?
4.5 In the context of Kerberos, what is a realm?
4.6 What are the principal differences between version 4 and version 5 of Kerberos?
In: Computer Science
4DCA:
Compare and contrast two difference cloud computing services (Amazon Web Service and Microsoft Azure). Explain the differences and the similarities and select your choice of providers if you had to make the decision for your business. Write up a comparison on the services offered
In: Computer Science
Why is it important to manage one's own website from a security point of view given the times we live in?
In: Computer Science
Write a Java program (name it LargestOccurenceCount) that reads from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the sentinel loop). The program should ignore any negative input and should continue to run.
Hint: to remember/save entered (good) values, you can concatenate them into a string (separated by spaces) that you can output later on.
Sample runs showing input prompts and outputs are (DO NOT read inputs as String type):
Enter positive integers (0 to quit): 3 4 5 -9 4 2 5 1 -5 2 5 0
You entered: 3 4 5 4 2 5 1 2 5
Largest value: 5
Occurrences: 3 times
Enter positive integers (0 to quit): 3 7 5 -4 4 2 -5 5 1 7 7 0
You entered: 3 7 5 4 2 5 1 7 7
Largest value: 7
Occurrences: 3 times
Document your code, and organize and space out your outputs as shown. Design your program such that it allows the user to re-run the program with different inputs in the same run (i.e., use a sentinel loop structure).
In: Computer Science
Using C++, write a program to calculate the height and velocity of a ball thrown upward at a user-specified height and speed in 10 seconds. Position (h) and velocity (v) of the ball as a function of time are given by the equations: h(t) =(1/2)gt2 + v0t + h0 v(t) = gt + v0
In: Computer Science
Take the code below, add the parameter validation as prompted by the highlighted comments.
#include <iostream>
using namespace std;
// Prototype (Wait, what's this? Hmmm... how would you find out?
)
void calculateBill(double, int);
int main()
{
// local variables
int numMonths = 10;
double rate = 25.99;
// Perform a test for $25.99 membership.
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";
// Perform a test for 70.50 membership.
numMonths = 5;
rate = 70.50;
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";
// Perform a test for $-5 membership.
numMonths = 5;
rate = -5;
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill <<
"\n";
//// What should you add to your function now?
// Perform a test for -10 months. Keep -5 to make sure you added
that input validation
numMonths = -10;
rate = -5;
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill <<
"\n";
//// What should you add to your function now?
return 0;
}
//*****************************************************************
// Definition of function calculateBilll. The memberRate parameter
holds *
// the monthly membership rate and the months parameter holds the
*
// number of months. The function displays the total charges.
*
//*****************************************************************
double calculateBill(double memberRate, int months)
{
return (memberRate * months);
}
In: Computer Science
C++ program
Overloaded
Hospital
Write a c++ program that computes and displays the charges for a
patient’s hospital stay. First, the program should ask if the
patient was admitted as an inpatient or an outpatient. If the
patient was an inpatient, the following data should be entered:
The program should ask for the following data if the patient was an
outpatient:
The program should use two overloaded functions to calculate the
total charges. One of the functions should accept arguments for the
inpatient data, while the other function accepts arguments for
outpatient information. Both functions should return the total
charges.
Input Validation: Do not accept
negative numbers for any data.
In: Computer Science
Write a computer program using C++ that computes the value of a Lagrange Polynomial and accepts, as input: (n+1) data points (x0, f(x0)), (x1, f(x1)),...(xn, f(xn)).. at value x, which the polynomial is to evaluated. As output, the program should produce a statement that reads, "f(x) = (the value of f(x))". As a test, use the data values (1,2);(-1,1);(0,0);(2,4);(-2,3)
In: Computer Science
Make an abstrakt about the topic " 6lowpan on network "، and should not be copy pasted from Google.
In: Computer Science
Write a Java program (name it PasswordTest) that reads from the user a string input (representing a password) and determines whether the password is “Valid Password” or “Invalid Password”. A valid password has at least 7 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order to render a verdict. For example, CS5000/01 is invalid password; however, Cs5000/01 is a valid password. The program should display the entered password and the judgment as shown in the following sample runs:
Entered Password: CS5000/01
Verdict: Invalid Password
Entered Password: Cs5000/011
Verdict: Valid Password
Entered Password: MyOldDogK9
Verdict: Invalid Password
Entered Password: MyOldDogK9#
Verdict: Valid Password
Entered Password: Ab1#
Verdict: Invalid Password
Document your code, and organize and space out your outputs as shown. Design your program such that it allows the user to re-run the program with different inputs in the same run (i.e., use a sentinel loop structure).
In: Computer Science
Assignment Requirements
You have been working as a technology associate in the information systems department at Corporation Techs for almost three months now. Yesterday, you got an e-mail, which specified that a security breach has occurred in your company. The other members of your team also received such e-mails. You checked the firewall logs and it confirmed the security breach.
Later, your team took corrective actions in the environment. They isolated the incident and assessed the damage. Today, your manager calls you and asks you to create an executive summary report detailing the events to be presented to executive management. You need to include a summary of corrective options, which may be in the form of architectural adjustments or other configuration changes that will prevent the reoccurrence of this incident in the future.
Tasks
You need to create a post-incident executive summary report that addresses a security breach. Include an overview of actions taken at each phase of the incident response. Also include suggestions for corrective modifications that would prevent the incident from reoccurring.
In: Computer Science
using python 3
2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000.
3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False.
4. In your main Python program write a for loop that counts from 1 to 1000 and calls this YesNo function inside the for loop and will print "The number xx is divisible by both 2 and 7 but not 70, or that are divisible by 57" if the YesNo function returns True. Otherwise it prints nothing. Note the print statement also prints the number where the xx is above.
In: Computer Science
Simple shell scripting
Write a Bash shell script called strcount.sh that counts the number of occurances of a given string within a file. The scripts takes two arguments: the name of the file to check and the string to count occurances of. If the file is not found (or not readable), the script should print the error message Cannot access file and exit with code -1. Otherwise, the script should print the number of occurances of the given string and exit with code 0. If the user fails to specify two arguments, the script should print the error message Usage: strcount.sh <file> <string> and exit with code -1.
Thus, if I have the following file penguins.txt:
Galapagos penguin Erect-crested penguin Subantarctic gentoo penguin Royal penguin Humboldt penguin Eastern rockhopper penguin Fiordland penguin Allied king penguin Ellsworth's gentoo penguin White-flippered penguin Cook Strait little penguin Chatham Island little penguin
Then the output should be the following:
ekrell@ekrell-desktop:~$ ./strcount.sh penguins.txt little 2
Or if the file does not exist:
ekrell@ekrell-desktop:~$ ./strcount.sh badfile.txt little Cannot access file
Or if the user fails to specify two arguments:
ekrell@ekrell-desktop:~$ ./strcount.sh Usage: strcount.sh <file> <string>
Write your script here
<- ... -> <- ... -> <- ... -> <- Add as many lines as you need ->
Credit
Material adopted from http://faculty.smu.edu/hdeshon/
In: Computer Science