Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed.
For example, ‘This line has extra space characters'
'This line has extra space characters’
• Function name: reduceWhitespace
• Number of parameters: one string line
• Return value: one string line The main file should handle the file operations to read from a .txt file you create and call the function from the module you create.
In main you should also print out your text from the file before the function call and print the result after the function call, showing that the function works. Additionally, write the lines with reduce whitespaces into a text file.
Your function should also include the specification (docstring).
Note: the code will be tested by giving it a .txt file, so you should prompt the user for the text file.
Lab 9 Part 2:
In the same module, write a Python function named countAllLetters that is given a string line and returns a list containing every letter and character in the line and the number of times that each letter/character appears (with upper/lower case letters counted together).
For example,
‘This is a short line’ -> [(‘t’,2), (‘h’,2), (‘i’,3), (‘s’,3), (‘ ‘,4), (‘a’,1),
(‘o’,1), (‘r’,1), (‘l’,1), (‘n’,1), (‘e’,1)]
• Function name: countAllLetters
• Number of parameters: one string line
• Return value: a list
The main file should handle the file operations to read from a new .txt file you create and call the function from the module you create. In main, you should print out the text you read from the file, then call the function and then print out the resulting list, showing that the function works. You do not need to write the output into a text file.
Your function should also include the specification (docstring).
Note: the code will be tested by giving it a .txt file, so you should prompt the user for the text file.
Please zip both files
In: Computer Science
IN MY SQL:
- Display each Author’s ID, first and last names and the total number of pages for all of the Books they have written.
- Display each Book genre as well as the number of Books written in that genre with the column header “Number Of Books”
- Display the Author’s first and last name, as well as their ID, and the Book title and number of pages for all of the books they have written that have more than the average number of pages for all of the books that have been written, listed by author’s first and last name along with the book title, and the book’s number of pages.
- Display the Author’s or Authors’ ID, first and last name of the Author who has the most Books in the Coastal Publishing database.
LINK TO WHAT THE SETUP AND INSERTS LOOK LIKE:
https://docs.google.com/document/d/1Qb30rS-g03pUBBFGBRwq-f9L8CsHY0Dz_HKpt_lt9uM/edit?usp=sharing
In: Computer Science
// Sunrise Freight charges standard
// per-pound shipping prices to the five states they serve
// –- IL IN OH MI WI
// -- 0.60 0.55 0.70 0.65 0.67
// Modify this program to reduce its size
// by using arrays
start
Declarations
string state
num pounds
string foundIt
string BAD_STATE_MSG = "Sorry, we do not ship to ”
string FINISH = “XXX”
getReady()
while state <> FINISH
findPrice()
endwhile
finishUp()
stop
getReady()
output "Enter state or ", FINISH, " to quit"
input state
return
findPrice()
foundIt = "N"
if state = "IL" then
price = 0.60
foundIt = "Y"
else
if state = "IN" then
price = 0.55
foundIt = "Y"
else
if state = "MI" then
price = 0.70
foundIt = "Y"
else
if state = "OH" then
price = 0.65
foundIt = "Y"
else
if state = "WI" then
price = 0.67
foundIt = "Y"
endif
endif
endif
endif
if foundIt = "N" then
output BAD_STATE_MSG, state
else
output “Enter pounds “
input pounds
output “Cost per pound to ship to ”, state, “ is ”, price
output “Total cost is ”, price * pounds
endif
output "Enter next state or ", FINISH, " to quit"
input state
return
finishUp()
output "End of job"
return
In: Computer Science
Suppose that we want to make change for n cents using the least number of coins. The coins are of denominations c 0 , c 1 , . . . , c k for some integers c > 1, and k ≥ 1. (a) Design a greedy algorithm to solve this problem. (b) Prove that your algorithm finds an optimal solution by showing the greedy-choice property and optimal substructure for it. Clearly state each property and then prove them.
In: Computer Science
I am working java project. I need to write methods for text game. I'm working on chest class.
Description : You should start your work by implementing the Chest class (a skeleton is provided for you). It needs to store whether it is locked or not, a String describing the contents, and which key it was locked with. The method stubs for this class are provided with comments, be sure to implement them the way they are described. You should not add any more methods to this class.
public class Chest {
/*
* Instance variables go here, you're responsible for
choosing
* which ones are needed and naming them
*/
/**
* This method is used by the Map class, you won't need
to call it yourself
* It should result in this chest being locked and
storing which key locked it.
*/
public void lock(Key theKey) {
Key rightKey = theKey;
}
/**
* If theKey is the same key that was used to lock this
chest, then
* the chest is unlocked. Otherwise this method does
nothing.
*/
public void unLock(Key theKey) {
}
/**
* Should return true if the chest is locked, false
otherwise
*/
public boolean isLocked() {
}
/**
* Return a string describing the contents of the
chest.
*/
public String getContents() {
}
/**
* Set the contents of the chest to this string. You
should not need to call
* this method in your program (though you have to
implement it anyway).
*/
public void setContents(String contents) {
}
}
In: Computer Science
Programming assignment (100 pts): In the C++ programming language write a program capable of playing Tic-Tac-Toe against the user. Your program should use OOP concepts in its design. You can use ASCII art to generate and display the 3x3 playing board. The program should randomly decide who goes first computer or user. Your program should know and inform the user if an illegal move was made (cell already occupied). The program should also announce if one of the players wins or if a draw is achieved. While it is desirable for your program to play a strong game, this is not an Artificial Intelligence course so if your program does not play at a world champion level you will not be penalized for it.
I've been looking at other post for this question and nothing is working.
In: Computer Science
Please write a half page summary on the following topic: How does product liability affect IT?
In: Computer Science
why are which letters, such as A, B, C, ..., or signs, such as #, *, •, ..., are not allowed to be sent on a URL to a Web server.
In: Computer Science
//Java Language
Read an integer number from the user. If the number is not positive, change its sign.
1 Count the digits of the number
2 Count the odd digits of the number
3 Calculate the sum of the digit values of the
number
In: Computer Science
Design a class named BankAccount to hold the following data for a bank account:
Balance
Number of deposits this month
Number of withdrawals
Annual interest rate
Monthly service charges
The class should have the following methods:
Constructor:
The constructor should accept arguments for the balance and annual interest rate.
deposit:
A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits.
withdraw:
A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals.
calcInterest:
A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:
Monthly Interest Rate 5 (Annual Interest Rate / 12)
Monthly Interest 5 Balance * Monthly Interest Rate
Balance 5 Balance 1 Monthly Interest
monthlyProcess:
A method that subtracts the monthly service charges from the balance, calls the calcInterest method and then sets the variables that hold the number of withdrawals, number of deposits, and monthly service charges to zero.
Next, design a SavingsAccount class that extends the BankAccount class. The SavingsAccount class should have a status field to represent an active or inactive account. If the balance of a savings account falls below $25, it becomes inactive. (The status field could be a boolean variable.) No more withdrawals may be made until the balance is raised above $25, at which time the account becomes active again. The savings account class should have the following methods:
withdraw:
A method that determines whether the account is inactive before a withdrawal is made. (No withdrawal will be allowed if the account is not active.) A withdrawal is then made by calling the superclass version of the method.
deposit:
A method that determines whether the account is inactive before a deposit is made. If the account is inactive and the deposit brings the balance above $25, the account becomes active again. A deposit is then made by calling the superclass version of the method.
monthlyProcess:
Before the superclass method is called, this method checks the number of withdrawals. If the number of withdrawals for the month is more than 4, a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges. (Don’t forget to check the account balance after the service charge is taken. If the balance falls below $25, the account becomes inactive.)
Input
100
0.03
2.5
Where,
First line represents the balance.
Second line represents the interest rate.
Third line represents the monthly service charge.
Output
Balance: $100.00
Number of deposits: 0
Number of withdrawals: 0
Account Status: Active
Balance: $170.00
Number of deposits: 3
Number of withdrawals: 0
Account Status: Active
Balance: $20.00
Number of deposits: 3
Number of withdrawals: 2
Account Status: Incative
Balance: $17.54
Number of deposits: 0
Number of withdrawals: 0
Account Status: Incative
# Use the provided template for the demo class to fill the missing code to input data and output result as shown above. Do not change the withdraw and deposit code!
In: Computer Science
Code needed in Java
The purpose of the application is to generate some reports about
the people of the university. So a user of the application should
be able to view information about the people in the university and
generate summaries. As in implementation these are separated into
two major categories, employee and students, we will be
implementing these classes.
The system should have three classes: Person,
Employee and Student.Employees
and students are subclasses of persons and therefore, they inherit
some fields and methods from the superclass Person. What Employee
class has as an extra is a field called job which is a
String value that indicates the position of the employee at the
university. The possible values are ‘Faculty’ and ‘Staff’ and the
rest of the input should be rejected. Another significant field is
UIN (you may assume it to be an integer).Students also
have a similar structure. A field called level, gives
information regarding the student. Possible values are
‘Undergraduate’ and ‘Graduate’ and the rest of the input should be
rejected. Also A number should be implemented (you may
assume A number to be a string).
Once you create these classes write your test class with main
method.
The output of such an application would look like:
Person’s first name is Triss, last name is Merigold. She
is 25 years old.
Person’s first name is Sigismund, last name is Dijkstra. He
is 37 years old. His UIN is 793942 and serves the university as a
staff.
Person’s first name is Keira, last name is Metz. She is 19
years old. Her A-number is A021318 and she is an undergraduate
student
In: Computer Science
Using Python Programming
PROBLEM 3 - OLD MACDONALD: Write a program to print the lyrics
of the song ”Old MacDonald”. Your program should print the lyrics
using five different animals (i.e., cow, sheep, dog, cat ,turkey)
using the example verse below. For this problem you are required to
write then make use of a function getVerse that takes two string
parameters: (1) the name of an animal and (2) the sound that animal
makes. The function should not print anything if the name of the
animal is not one of the five above, or if there is a mismatch
between the animal and the sound. In your program, call your
function 5 times, passing each time to the function a different
combination of animal name and sound. The five different animals and
their associated sounds are the followings:
Animal Sound
cow moo
sheep baaa
dog woof
cat meow
turkey gobble gobble
In: Computer Science
In: Computer Science
About Cache, computer organization, computer architecture, computer science.
Cache Question:
A[0] is at memory address 0x0FED CBA0. Array B[] is right after array A[] in the data memory.
Both arrays have 10 integers
Based on memory address for A[0] of 32 bits, i know that the cache index and tag is 27 bits, offset is 4 bits and index is 1 bit.
Q: Will the tag and cache index change for A[8] and B[8]? And how will it change?
I personally feel that tag and cache index will not change for A[8]. But i'm not too sure about B[8]
Q: Does the cache behaviour affect the A[8] and B[8]?
E.g. Direct mapped cache vs 2-way set-associative cache
In: Computer Science
IN JAVA, For this exercise, you will create your own example of using a generic method. First write a program that calls a method to multiply two integers and return the integer result. Then modify that program to make the method generic, calling it with two generic data types (T1 and T2) and then returning the result in the same type (also needs to be generic). Demonstrate your program by calling the method two times, once with an integer and once with a double. In your main program, display the results of the method call showing both an integer output and a decimal output. Submit code for both your original method (non-generic) and your revised method (generic), along with execution screenshots.
In: Computer Science