In: Computer Science
Has protection for proprietary software gone too far, as some critics suggest? (b) If not, why? (c) If so, what are the implications for innovation and competition in the computer industry? (d) How can we achieve an appropriate balance between those who hold legal rights to proprietary information and ordinary users who wish to access, share, and communicate that information? Defend your answer. Please elaborate (beyond a yes or no answer) and provide your “theoretical” rationale in support of your responses. (knowledge)
In: Computer Science
In: Computer Science
Write a .m function file on MATLAB that reads the parameters stored in the file missile data.txt into MATLAB. The function should have the following declaration: function [X0, Y0, Z0, m0, mf, Thmag0, theta, phi, Tburn] = read input( input filename, M id) where input filename is a string variable denoting the name of the file to be read and M_id is an integer which denotes the missile ID. The outputs are the initial position (X0, Y0, Z0), initial and landing mass (m0, mf), initial thrust magnitude (Thmag0), aunch angles (theta and phi) and burn time (T burn). When the input M_id is not available in the file, the function should set all outputs to NaN and display an error warning message to screen. Use "importdata" or "textscan" function to read the parameters.
The text file is:
# Missile parameters in the following order from left to right: # Missile ID # Initial position in X0, Y0, Z0 coordinate (m) # Initial mass and landing mass: m0 and mf (kg) # Initial thrust magnitude Thmag0 (N) # Direction angle (degree): theta, phi # Burn time Tburn (s) 1 0.12 29999.14 1.54 700 90 100000.00 -41.24 52.01 11.11 2 0.15 0.54 2.54 700 90 101000.00 32.65 53.02 11.05 3 0.10 101.43 2.43 700 90 99000.00 20.18 53.62 11.09 4 0.16 29812.45 2.12 700 90 96000.00 -15.65 50.51 11.13 5 0.11 15432.98 0.15 700 90 90000.00 5.86 49.07 11.02 6 0.14 29934.54 2.24 700 90 85000.00 -25.34 51.52 11.05 7 0.13 212.43 1.23 700 90 80000.00 10.24 50.05 11.98
In: Computer Science
Hello Everyone,
Can anyone tell me why my program will not run? I am trying to work on abstract base classes... not sure what is going on.
import math
from abc import ABC
from abc import abstractmethod
#TODO: convert this to an ABC
class Shape(ABC):
def __init__(self):
self.name = ""
def display(self):
print("{} - {:.2f}".format(self.name, self.get_area()))
#TODO: Add an abstractmethod here called get_area
@abstractmethod
def get_area(self):
if self.name == "Circle":
get_area()= 3.14 * radius * radius
else:
get_area() = self.length * self.width
#TODO: Create a Circle class here that derives from Shape
class Circle(Shape):
def __init__(self):
super().__init__()
self.name = "Circle"
self.radius = 0.0
get_area()
#TODO: Create a Rectangle class here that derives from Shape
class Rectangle(Shape):
def __init__(self):
super().__init__()
self.name = "Rectangle"
self.length = 0.0
self.width = 0.0
get_area()
def main():
#TODO: Declare your list of shapes here
s = Shape()
c = Circle()
r = Rectangle()
radius = []
length = []
width = []
command = ""
while command != "q":
command = input("Please enter 'c' for circle, 'r' for rectangle or 'q' to quit: ")
if command == "c":
radius = float(input("Enter the radius: "))
#TODO: Declare your Circle here, set its radius, and
# add it to the list
self.name = "Circle"
radius.apphend
return radius
elif command == "r":
length = float(input("Enter the length: "))
width = float(input("Enter the width: "))
#TODO: Declare your Rectangle here, set its length
# and width, and add it to the list
self.name = "Rectangle"
return length, width
length.apphend
width.apphend
# Done entering shapes, now lets print them all out:
s.display()
#TODO: Loop through each shape in the list, and call its display function
for i in Shape():
s.display()
if __name__ == "__main__":
main()
In: Computer Science
Write a C program, char.c, which prints the numerical value of
the special character constants given below. Don’t just look up the
codes and print them directly from your program. You should have
your program output the values of the character constants by using
them as string literals within your printf() statements.
Your output should be presented in a neat, orderly, tabular format
as shown below:
Char Constant Description Value '\n' newline '\t' horizontal tab
'\v' vertical tab '\b' backspace '\r' carriage return '\f' form
feed '\\' backslash '\'' single quote (apostrophe) '\"' double
quote '\0' null
Use the following guidelines to develop your program:
Declare your variables with appropriate data types.
Assign values to your variables.
Perform your calculations.
Generate appropriate output.
Points to Remember: Make sure you are creating a C program and not
a C++ program. The .c suffix to your source code will invoke the C
compiler while the .cpp suffix will invoke the C++ compiler. As
this is a class in C and not C++, please make sure your source code
uses the .c suffix. You should not be using any global variables in
your program. A global variable is a variable declared outside of
main().
Output from your program should be sent to the terminal window
(your screen) as well as the requested csis.txt output file. Be
sure to read the document on Capturing Program Output. Your full
name and Palomar ID number must appear as a comment in the source
file that contains main().
In: Computer Science
In each regional branch of Marc-Lu sales company, every salesclerk has a monthly base salary. The salesclerk also takes a bonus at the end of each month based on the following criteria: If the salesclerk has been with the company for three or less years, the bonus is $100 for each year that he or she has worked there. If the salesperson has been with the company for more than three years and less or five years, the bonus is $200 for each year that he or she has worked there otherwise the bonus is $ 300. The salesclerk can also earn an extra bonus as follows: If the total sale made by the salesclerk for the month is more than $ 5,000 but less than $10,000 he or she receives a 3% commission on the sale. If the total sale made by the salesclerk for the month is at least $ 10,000 he or she receives a 6% commission on the sale.
a) Design an algorithm that calculates the monthly payment of a salesclerk at given regional branch.
b) List all the variables required to write this program.
c) Use the algorithm in (a) to write a complete C++ program to calculate monthly payment of a salesclerk at a given regional branch.
In: Computer Science
A system of caves is a group of connected underground tunnels. Design an ADT for a cave and a cave system. An archaeologist should be able to add a newly discovered cave to a cave system. He/she can enter this system through only one cave and exit the system only through a different cave. Duplicate caves – based on GPS coordinates – are not permitted. Archaeologists should also be able to list the caves in a given cave system.
File Submission
• Cave.java
Cave object containing Cave Name and Cave GPS coordinates (Latitude and Longitude) and any other appropriate attributes if needed
• CaveInterface.java
Interface containing method definition to add and remove caves
• CaveStack.java
Stack implementation of CaveInterface.java
• CaveStackDemo.java
Demonstrate adding, removing and listing caves. Prompt the user for various cave names and GPS coordinates to show your implementation.
In: Computer Science
JavaScript Form Validation
Name: a text box where the content must start with 1 upper case characters and no special character (i.e. !, @, #, $, %, &, *). Number is not allowed. The text box must not be empty.
Module code: a text box where the content must start with 3 lower
case alphabets and follows by 4 digits where the first digit cannot
be zero. This textbox can be empty.
All validation error messages must be italic and in red colour and besides the HTML element.
There should be a validation error displayed for every error.
Example:
If the user enters a number and special characters in the Name textbox, a message should say on the side "Numbers are not allowed!" in red and italic.
If the user leaves the name Textbox empty after submission, there should be an error message on the side saying "Name cannot be empty!"
If the user enters uppercase characters followed by the number starting with zero in the Module code TextBox, a message should say on the side "Content must start with 3 lower case alphabets!" followed by "First digit cannot be zero!"
In: Computer Science
C++ file=.class definitions.h
Define a Fraction class with num and den as its private data. Include a constructor to initialize the fraction to 0/1, a copy constructor, a destructor, and overloading functions to overload the assignment operator =, the comparison operators <, >, ==, !=, arithmetic operators +, +=, -, -=, *, *=, /, /=, as well as friend functions (non-member) to overload << and >> to output and input a fraction (see book example). Also, include a private member function called reduce() that gets called after arithmetic operations to reduce the frraction. +, -, *, / must return the result of the operation; e.g.: the sum or difference of the two fractions. +=, -=, *= and /= must assign the result of the operation to the object that's invoking the operation; i.e.: frac1 += frac2 must modify frac1 to make it equal to the sum of the two fractions, but frac1 + frac2 must simply return the sum.
If n1/d1 and n2/d2 are two fractions, their sum fraction's numertor is: n1 * d2 + n2 * d1 and its denominator is d1 * d2. To compare the two fractions, you can compare n1 * d2 with n2 * d1.
In: Computer Science
What is the difference between analytical skills and research skills?
In: Computer Science
Write a function to check whether string s1 is a substring of string s2. The function returns the first index in s2 if there is a match. Otherwise, return -1. For example, the function should return 2 if s1 is "to" and s2 is "October". If s1 is "andy" and s2 is "candy", then the function should return 1. The function prototype is as follows: int indexOf(const char *s1, const char *s2).
In: Computer Science
Project 4 – The Nearest Neighbors Classification Algorithm This project will require you to implement a version of the Nearest Neighbors classification algorithm. This version, the Three Nearest Neighbors (or 3NN for short), is one of the more intuitive classification algorithms, and one of the easier ones to code. This Nearest Neighbors family of algorithms is useful because it does not require any special “training” to work. You simply need previous data to compare to. What is classification? With classification, the goal is to use previously collected data to train an algorithm to correctly classify future data. If I have a data set on the measurements of the sepal (the part of a flower that encloses a petal) length and width of two kinds of irises, setosa and versicolor, I can use that data to predict what kind of iris another flower is from sepal measurements alone. Our classification algorithm would be trained to draw a line between the two regions we can see in the scatterplot, as so: Figure 1 Figure 2 Deciding that future data on one side of the line should be setosa, and the other side should be versicolor. Note that we would not expect such a classifier to be perfect: You can see that one of the data points for setosa is on the versicolor side of the boundary in this example. Rather, we would expect the classification algorithm to work an acceptable amount of the time. What is acceptable depends on the application. Definitions Training Data – Data used when implementing the classification algorithm to draw boundaries. In the above example, the x and o data points are the training data. Class – Different categories that training data has been divided into. In the above example, setosa and versicolor are classes. Test Data – Data for which we do not know the class. We will use the classification algorithm to help us guess which class it might come from. Data Space – The data involved with training and testing, in all of its demensions Nearest Neighbors Classifier The nearest neighbor classifier is relatively straightforward. First, it takes all of the dimensions of training data available and normalizes each dimension. An incoming piece of test data is also normalized based on the means and standard deviations of the training data. Once both test and training data are normalized, we wind up with a data space that might look like this: In the nearest neighbors algorithm, we look at the Euclidian distance between the test data and the training data. We then look at the closest K neighbors, where K is determined before training. In this example, and in this project, K = 3. Those closest neighbors then “vote,” with the class that has the largest number of closest neighbors being assigned as the class of the test data. Figure 3 In the above example (test data was sepal length 6 cm, sepal width 4cm), the 3NN algorithm classifies the test data as setosa: Because the three closest neighbors are all of the class setosa. In another test data case, with sepal length 5.75 cm and sepal width 3.5 cm, we also find that the class is setosa: As two of the three closest neighbors are of that class. In a third test data case, with sepal length as 5.2 cm and sepal width as 2.9 cm, we find the class is versicolor: Figure 4 Figure 5 As two of the three closest neighbors are of that class. Inputs and Outputs In this project, you will implement the 3NN algorithm in a MATLAB function. This algorithm will only work with data that is in 2 dimensions with 2 classes. This function will have two inputs: dataSet – A structure with the following fields: - data1 – A numerical array of doubles, the first dimension of a data set, of length N - data2 – A numerical array of doubles, the second dimension of a data set, also of length N - label – A cell array, the class labels of your data set. Each element is a vector string. Also of length N - name1 – A string with the first possible class label - name2 – A string with the second possible class label testData – A 1 x 2 array of doubles, where the first element is the value of your test data in dimension 1, and the second element is the value of your test data in dimension 2. This function will have one output: winner – A string with the label of the class assigned to testData. Your function should also produce a plot of the normalized Data space similar to figure 3. To create a plot of points instead of lines, use the following inputs to plot: plot(x,y,'Marker','o','LineStyle','none') Where the string after the input “Marker” determines the shape of each point, and “ ‘LineStyle’, ‘none’ “ prevents any lines from being drawn between points. Methods Figure 6 Please use the following methods to implement the 3NN algorithm: Step 1 Normalize both dimensions of your training data set. Then normalize your test data using the mean and standard deviation of your training data. You now have enough data to generate the required plot. Step 2 Find the Euclidian distance between your test data and all training data using the Pythagorean theorem with your normalized data. Step 3 Find the three points in the training dataset that are closest to your test data. Step 4 Have the three nearest neighbors “vote” to see which class has more representation in the nearest neighbors. Hint: This is where you will want to use the label, name1, and name2 fields. Use the result of voting to set the output. Testing Code I have prepared three test datasets for you, that you can find in the files: - iris.mat, which is the data set in the above examples - diabetes.mat, which is blood glucose and ages of patients 5 years prior for people with and without diabetes - wheat.mat, which is the area and compactness of the kernals of two varieties of wheat seed You should be able to use your visualizations to check whether your nearest neighbors algorithms are working properly. Hint: Try choosing test data in some of the less “crowded” locations of your data space.
In: Computer Science
Task 1: This is the instructions for the previous set, where we worked with list of lists as character records, (there is already a solved Chegg for task 1 (J. [40 points]). I need help with the code of converting isInrecord(), AddToRecord(), createRecord(), and frequencies() from task J to use dictionaries instead of lists (as is asked in task A, which is located below the line of ########).
J. [40 points]
This tasks includes working with lists and
lists of lists.
For this task, you'll keep track of how many times a certain value occurs in a set of data. You'll be tracking and counting characters, i.e. how many times any letter, digit, or punctuation mark appears in a string. You'll be writing Python code to create and work with such character records. What is a character record? It's the information about how many times any character (in a string or text) appears in that string or text. Let's look at this example:
For Task J, you'll be representing the data structure for character records as a list of pairs (i.e. lists of two-item lists). The first item in each pair is the character, and the second is an integer representing how many times that character appears in some particular string. So if ['e',20] is in the list, that means that there are 20 lowercase e's in the string. Here's an example of such a data structure: [['K',1],['o',3],['k',1],['m',1],['?',1]], which represents a string with 1 K, 3 o's, 1 k, 1 m, and 1 question mark (perhaps "Kokomo?"?). Any time you see the words "character record" in Task J, you can assume it refers to a list of pairs like this (where the first item in the pair is a one-character string and the second is an integer).
steps in Task J:?
1 |
# a *character record* is a list of two-item lists where... |
[1]This is in addition to another writing
requirement:
all functions you write for A201/A597 must have a correctly and
well-defined docstring, including a signature and a purpose
statement.
?
1 |
myCharRecord = [['K',1],['o',3],['k',1],['m',1],['?',1]] |
?
1 2 |
myCharRecord [['K',1],['o',4],['k',1],['m',1],['?',1]] |
?
1 2 |
myCharRecord [['K',1],['o',4],['k',1],['m',1],['?',1],['X',1]] |
#################################################################################################################################################
?
1 |
# a *character record* is a dictionary where... |
Note[1]This is in addition to the usual
requirement:
all functions you write for A201/A597 must have a correctly and
well-defined docstring, including a signature and a purpose
statement.
############################# my code that needs to be converted from list of list into dictionaries (they can be modified as much as needed )############################
def isInRecord(char,charRec):
""" returns True if character is in character Record, otherwise
false
string, charRecord -> Boolean Value"""
for i in charRec:
if i[0]==char:
return True
return False
def addToRecord(char,charRec):
""" returns new character record with updated frequency of each
character occurance
character, charRecord(myCharRecord) -> list of character
records"""
check=False
for i in charRec:
if i[0]==char:
check=True
if not check:
charRec.append([char,1])
myCharRecord = [['K',1],['o',3],['k',1],['m',1],['?',1]]
def createRecord(pString):
""" returns character records for argument entered
string -> list of character records"""
aList=[]
for i in pString:
addToRecord(i,aList)
return aList
def frequencies(char,charRec):
""" returns number for frequency of character in charRec list
character, charRecord -> integer"""
for i in charRec:
if i[0]==char:
return i[1]
return 0
In: Computer Science
a Composite class representing arithmetic expression.
Participants:
Q. Create a code implementing a pattern, Implementing Composite implies multiple class. By my estimate, at least 3. In minimal Composite implementation, classes have two methods (or a constructor and 1 method). extensive coding is not required. (using Java)
In: Computer Science