I am trying to write a python code to create a function that returns all possible dimensions (reshaping) for an input matrix, can someone explains the math and write a python code with explaining all the steps and give me a test cases, and please explain if there is more than one approach. so if we have 1*8 matrix we should return 1*8, 2*4,4*2,8*1
def reshaping(M) should return a n ORDERED list AND the all possible reshaped matrices
In: Computer Science
#include <iostream>
using namespace std;
string* callMe(string*& s){
static string* str = new string{"Chiqita Banana"};
str = s;
return str;
}
int main()
{
string* s = new string{"Hey Google"};
string* str = callMe(s);
cout << "Call me \'" + *str +"\'";
return 0;
}
1. What is the output or the error of this program?
Call me 'Hey Google'
2. And please explain the data flow in detail (to memory level)?
Please help question 2 with explanation, thank you!
In: Computer Science
You are given two classes for implementing a simple binary tree of capable of storing number, count the number of leaves and computes the height of a binary tree.
You can add on additional parameters or functions as you wish, but the program must apply the chapter objectives.
class BTreeNode { //node for the binary tree items
public:
BTreeNode(double x, BTreeNode *leftp = NULL, BTreNode *rightp = NULL) {
value = x;
left = leftp;
right = rightp;
}
private:
double value;
BTreeNode *left, *right;
friend class BST; //BST has friend status
};
class BST { //binary tree class
public:
int height() { //returns the tree height
return height(tree);
}
void insert(double x); //inserts numbers into the binary tree
void inorder(vector<double> &v) { //appends all nodes in subtree
inorder(v, tree);
}
int leafCounter() { //counts the number of leaves
return leafCounter(tree);
}
BST() {
tree = NULL;
}
private:
void inorder(vector<double>&tlist, BTreeNode *t); //storing nodes in a subtree
int leafCounter(BTreeNode *t); //counts the number of leaves
static int height(BTreeNode *t); //calculates the height of the tree
BTreeNode *tree;
}
In: Computer Science
hello please correct this code
print("The Miles Per Gallon program")
print()
Trips = []
trip = 0
while 1:
print("Do you want to add a trip from a csv file or Enter it manually? 1 for csv 2 for entering it manually")
method = int(input())
if method == 1:
print("Enter the filename")
fileName = input()
try:
with open(fileName, 'r') as myFile1:
reader = csv.reader(myFile1)
Trips = list(reader)
print("Miles Driven Gallons Used \tMPG")
for i in Trips:
for j in i:
print(j, end=" ")
print()
except IOError:
print ("Could not read file:", fileName)
elif method == 2:
while 1:
miles_driven = input("Enter miles driven: ")
try:
val = int(miles_driven)
break
except ValueError:
print("No.. input string is not an Integer. It's a string")
while 1:
gallons_used = input("Enter gallons of gas used: ")
try:
val2 = int(gallons_used)
break
except ValueError:
print("No.. input string is not an Integer. It's a string")
mpg = val / val2
mpg = round(mpg, 2)
Trips.append([])
Trips[trip].append(miles_driven)
Trips[trip].append(gallons_used)
Trips[trip].append(mpg)
print("Miles Driven Gallons Used \tMPG")
for i in Trips:
for j in i:
print(j, end= " ")
print()
trip += 1
choice = int(input("Do you want to add another trip? 1 for yes 0 for no "))
if choice == 1:
continue
elif choice == 0:
break
myFile = open('trips.csv', 'w')
with myFile:
writer = csv.writer(myFile)
writer.writerows(Trips)
with open('trips.csv', newline='') as myFile:
reader = csv.reader(myFile)
for row in reader:
print(row)
print("Elemnts from the csv file printed which means it was stored successfully")
i need result as
EXAMPLE RUN 1: - Bad filename C:\Files.py The Miles Per Gallon
program
Would you like to read trips from a file? y/n: y Enter the csv
filename containing trip data: test Trips not read from file - file
not found: test Would you like to enter trip data? y/n: y Enter
miles driven: 100 Enter gallons of gas used: 10 1. Miles: 100.0
Gallons of Gas: 10.0 Mpg: 10.0
Would you like to continue? y/n: y Enter miles driven: 50 Enter
gallons of gas used: 5 1. Miles: 100.0 Gallons of Gas: 10.0 Mpg:
10.0 2. Miles: 50.0 Gallons of Gas: 5.0 Mpg: 10.0
Would you like to continue? y/n: n
EXAMPLE RUN 2: Good filename and good inputs
C:\y The Miles Per Gallon program
Would you like to read trips from a file? y/n: y Enter the csv
filename containing trip data: trips.csv Trips: 1. Miles: 100.0
Gallons of Gas: 10.0 Mpg: 10.0 2. Miles: 50.0 Gallons of Gas: 5.0
Mpg: 10.0
Would you like to enter trip data? y/n: y Enter miles driven: 75
Enter gallons of gas used: 4 1. Miles: 100.0 Gallons of Gas: 10.0
Mpg: 10.0 2. Miles: 50.0 Gallons of Gas: 5.0 Mpg: 10.0 3. Miles:
75.0 Gallons of Gas: 4.0 Mpg: 18.75
Would you like to continue? y/n: n
c:\\
EXAMPLE RUN 3: Good Filename – bad user inputs
The Miles Per Gallon program
Would you like to read trips from a file? y/n: y Enter the csv
filename containing trip data: trips.csv Trips: 1. Miles: 100.0
Gallons of Gas: 10.0 Mpg: 10.0 2. Miles: 50.0 Gallons of Gas: 5.0
Mpg: 10.0 3. Miles: 75.0 Gallons of Gas: 4.0 Mpg: 18.75
In: Computer Science
Submission Question 3: Polymorphism
Problem
You are writing software for a company’s human resources department. As part of the requirements, it would like to have a function that calculates the salary of an individual based on the position he or she holds, years of service, and hours worked.
This program will demonstrate the following:
Solving the Problem
Step 1
The first thing that you must determine is what attributes are common to all employees and what methods they can share. Can salary be easily calculated by the same method without some additional input from the user? By using polymorphism, you can make one method that calculates salaries for different groups. First, determine the base class and what method needs to be implemented by the child classes. By making the calcSalary() method abstract, it will be a required method of the child classes.
Step 2
You can then define the child classes that inherit the shared attributes from the base Employee class but also inherit the requirement that they implement from the calcSalary() method. Each employee type will have a different set of attributes and a different method of calculating the salary, but the same method call will be used to calculate it.
Step 3
You can now create a list to hold all employee types and populate it.
Step 4
Because you used polymorphism in the classes, you can now use one loop to calculate and output the salaries of the employees.
Documentation Guidelines:
Use Python Programming. Use good programming style (e.g., indentation for readability) and document each of your program parts with the following items (the items shown between the '<' and '>' angle brackets are only placeholders. You should replace the placeholders and the comments between them with your specific information). Your cover sheet should have some of the same information, but what follows should be at the top of each program's sheet of source code. Some lines of code should have an explanation of what is to be accomplished, this will allow someone supporting your code years later to comprehend your purpose. Be brief and to the point. Start your design by writing comment lines of pseudocode. Once that is complete, begin adding executable lines. Finally run and test your program.
Deliverable(s):
Your deliverable should be a Word document with screenshots showing the source code and running results, and discuss the issues that you had for this project related to AWS and/or Python IDE and how you solved them for all of the programs listed above as well as the inputs and outputs from running them. Submit a cover sheet with the hardcopy of your work.
In: Computer Science
Using Java
Prime numbers. Write a program that prompts the user for an integer and then prints out all prime numbers up to that integer. For example, when the user enters 20, the program should print 2 3 5 7 11 13 17 19 Recall that a number is a prime number if it is not divisible by any number except 1 and itself. Use a class PrimeGenerator with methods nextPrime and isPrime. Supply a class PrimePrinter whose main method reads a user input, constructs a PrimeGenerator object, and prints the primes. Submit the Java file and screenshot of the output in zip file.
In: Computer Science
What advantages does the memory hierarchy provide? Explain.
In: Computer Science
Fill in the classes to represent salaried and hourly employees. Salaried employees are paid for forty hours no matter how much they actually work. Hourly employees are paid their hourly rate up to forty hours of work, and 1.5 times their normal rate for overtime.
Employee.java
public abstract class Employee {
protected double payRate;
public Employee(double payRate) {
this.payRate = payRate;
}
abstract public double computePay(double hours);
}
HourlyEmployee.java
public class HourlyEmployee extends Employee {
public HourlyEmployee(double payRate) {
}
public double computePay(double hours) {
return 0;
}
}
SalariedEmployee.java
public class SalariedEmployee extends Employee {
public SalariedEmployee(double payRate) {
}
public double computePay(double hours) {
return 0;
}
}
In: Computer Science
Using a pseudocode example, explain the wait and signal operations of a binary semaphore.
In: Computer Science
This problem is about java program and please show the detail comment and code in each class. Thank you!
Create four classes with the following UML diagrams:
(The "-" means private and the testBankAccount()
testMobilePhone() testChocolate() testStudent() all static
+-----------------------------+
| BankAccount |
+-----------------------------+
| - money: int |
+-----------------------------+
| + BankAccount(int money) |
| + getMoney(): int |
| + setMoney(int money): void |
| + testBankAccount(): void |
+-----------------------------+
+------------------------------------------------+
| MobilePhone |
+------------------------------------------------+
| - number: int |
| - account: BankAccount |
+------------------------------------------------+
| + MobilePhone(int number, BankAccount account) |
| + getNumber(): int |
| + payMoney(int amount): boolean |
| + testMobilePhone(): void |
+------------------------------------------------+
A mobile phone has a phone number and is connected to a bank
account. The owner of the mobile phone can use the mobile phone to
pay money: if amount is not negative and if the
bank account connected to the mobile phone has enough money in it
then the money in the bank account is decreased by
amount and the payMoney method
must return true, otherwise nothing changes for
the bank account and the method must return
false.
+-----------------------------+
| Chocolate |
+-----------------------------+
| - weight: double |
+-----------------------------+
| + Chocolate(double weight) |
| + getWeight(): double |
| + buy(int money): void |
| + eat(double amount): void |
| + testChocolate(): void |
+-----------------------------+
If the constructor of the Chocolate class is given
a negative weight as argument then the weight must be changed
to
0.0 Kg.
When buying chocolate, the weight of chocolate
increases, with the price of chocolate being RMB 100 per 1.5 Kg. It
is
not possible to buy a negative amount of chocolate, so in that case
the buy method must print a message
"Cannot
buy negative amount of chocolate" and nothing else
happens.
It is not possible to eat more chocolate than there is chocolate,
so in that case the eat method must print a message
"Cannot eat nonexistent chocolate, only XXX Kg
available" (where XXX is replaced with
the current weight of chocolate) and nothing else happens.
+-----------------------------------+
| Student |
+-----------------------------------+
| - name: String |
| - phone: MobilePhone |
| - chocolate: Chocolate |
+-----------------------------------+
| + Student(String name, int money) |
| + getName(): String |
| + getChocolateWeight(): double |
| + hungry(int money): void |
| + testStudent(): void |
+-----------------------------------+
When a student is created, the student has 0.0 Kg of chocolate and
a mobile phone which is connected to a bank
account with money in it. Use your student ID
number as the phone number for the mobile phone.
When the student is hungry, the student first tries to use the
mobile phone to pay the money amount. If the
payment is
successful then the student buys the chocolate corresponding to the
same money amount of the payment and then the
student eats half of the weight of chocolate that has just been
bought (not half of the total weight of chocolate). If the
payment is not successful then the hungry method
must print a message "Student is still hungry!"
and
nothing else happens.
Each class has a static test method that contains tests for all the
constructors and all the methods of the class. For each
class, test the simple methods first and the more complicated
methods next. For each constructor and each method,
make sure that you test every possible case.
Add to your software a Start class with a
main method that calls the test method of each of
the four classes, to test
everything in your software.
In: Computer Science
Implementing IPv4 and IPv6 Addressing
.
In: Computer Science
When a kernel thread dies, what OS data structures are updated?
In: Computer Science
Consider the University Admission Process case description below In order to apply for admission, students first fill in an online form. Online applications are recorded in an information system to which all staff members involved in the admissions process have access. After a student has submitted the online form, a PDF document is generated and the student is requested to download it, sign it, and send it by post together with the required documents, which include: • certified copies of previous degree and academic transcripts • results of English language test • curriculum vitae • two reference letters When these documents are received by the admissions office, an officer checks the completeness of the documents. If any document is missing, an email is sent to the student. The student has to send the missing documents by post. Assuming the application is complete, the admissions office sends the certified copies of the degrees to an academic recognition agency, which checks the degrees and gives an assessment of their validity and equivalence in terms of local education standards. This agency requires that all documents be sent to it by post, and that all documents be certified copies of the originals. The agency sends back its assessment to the university by post as well. Assuming the degree verification is successful, the English language test results are then checked online by an officer at the admissions office. If the validity of the English language test results cannot be verified, the application is rejected (such notifications of rejection are sent by email). Once all documents of a given student have been validated, the admissions office forwards these documents by internal mail to the corresponding academic committee responsible for deciding whether to offer admission or not. The committee makes its decision based on the academic degrees and transcripts, the CV, and the reference letters. The committee meets once every three months to examine all applications that are ready for academic assessment at the time of the meeting. At the end of the committee meeting, the chair of the committee notifies the admissions office of the selection outcomes. This notification includes a list of admitted and rejected candidates. A few days later, the admissions office notifies the outcome to each candidate via email. Additionally, successful candidates are sent a confirmation letter by post. What steps can you extract from this process? Classify these steps into VA, BVA, and NVA.
In: Computer Science
In a few paragraphs
There are 2 very different view components that are commonly used in Express; Jade and Handlebars. Briefly describe which of these two you would prefer to use and why.
In: Computer Science
3. Please complete the example given in lecture;
Programs to display pyramid and inverted pyramid using * or # and
digits
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
Press “1” button add 1 into the pyramid.
Press “1” to move number 1 to next cell (if it is the end of the
triangle, loopback)
Press “2” to move number 1 to previous cell (if it is the end of
the triangle, loopback)
First press
1
* * *
* * * * *
* * * * * * *
* * * * * * * * *
Second press
*
1 * *
* * * * *
* * * * * * *
* * * * * * * * *
Eighth press
*
* * *
* * * 1 *
* * * * * * *
* * * * * * * * *
Please write in cpp
In: Computer Science