Let’s represent 61 students sitting in a row as a simple string, 61 characters long. Students not wearing a mask are represented by the space character. Students wearing a mask are represented by an asterisk (*). On the first day, only one student, sitting in the middle of the row is wearing a mask. Our initial string looks like this: " * " Students will decide whether to wear a mask the next day according to the following rule: If a student is sitting next to exactly one student wearing a mask (on the left or the right) then they will wear a mask to the next class. Otherwise they won’t wear a mask the next day. How does the mask-wearing behavior change over time. Generate the subsequent strings for 100 subsequent classes. Embed your output inside your code as a triple-quoted string. Here are the first few classes: " * " " * * " " * * " " * * * * " (should look like a pyramid with space in middle of third row)
In: Computer Science
First, download the Lab05.s file as usual. This lab is fully written, including main and all other subprograms.
However, there are numerous errors scattered throughout the program, and your task is to locate each one and fix it. These range from syntax errors (errors that show up when you try to load the file into QtSpim) to logic errors (errors that either cause the program to crash at runtime, or causes the program to do the wrong thing.)
There are 23 total errors that you will need to locate and fix. Some helpful hints:
sort_array
has no errors in it at all. Do not fix anything
in
sort_array
!Once you've fixed all the errors and run the program with some test input a few times, the lab can be submitted.
In: Computer Science
You have a job that you really dislike. You have just gone to interview for a job that you really like, and the interview went well, but the result will not be known until a month later, and there is no way you can find out any more information about it before then. In the meantime, another employer offers you a job that is better than your current job, but it demands your acceptance in a week or the offer will be withdrawn forever. Clearly describe how do you can use decision tree analysis and utility theory to help you make the decision about the offer that is better than your current job but not as good as the job you really like. Your answer should be a set of instructions or a computational procedure that the decision-maker can follow with an example.
1. CLEARLY STATE A QUANTITATIVE PROCEDURE USING THE DECISION TREE ANALYSIS AND UTILITY THEORY.
In: Computer Science
Exercise #1: Write MARIE assembly language code to input 3 values into variables x, y, and z, calculate x + y -z, and outputs the result. Run your code in the simulator and submit a screen shot of your program run and the code.
//x + y -z
ORG 100
INPUT
STORE X
INPUT
STORE Y
INPUT
STORE Z
LOAD X
ADD Y
SUBT Z
OUTPUT
Halt
X, Dec 0
Y, DEC 0
Z, DEC 0
Exercise #2: Write MARIE assembly language code to implement the following algorithm:
Y = 0;
X = 1;
While X < 10 do
Y = Y + X;
X = X + 1;
Endwhile;
So this code calculates the sum of integers between 1 and 9, and
stores the result in Y. So after executing the code, the value
stored in Y should be decimal 45 i.e. Hexacimal 2D.
ORG 100
Load X
Store One
Test, Subt Ten
Skipcond 400
Jump Loop
Jump Done
Loop, Load Y
ADD X
STORE Y
Load X
Add One
Store X
Jump Test
Done, Halt
X, DEC 1
Y, DEC 0
Ten, DEC 10
One, DEC 1
Output:
Input is X = 10, Y = 15, Z = 13
ITS PROGRAMMING
In: Computer Science
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
struct Point{
int x, y;
bool operator==(const Point& p2) {
return this->x == p2.x and this->y == p2.y;
}
bool operator!=(const Point& p2) {
return this->x != p2.x or this->y != p2.y;
}
friend ostream &operator<<( ostream &out, const Point
&P ) {
out << "(" << P.x << ", " << P.y <<
")";
return out;
}
friend istream &operator>>( istream &in, Point
&P ) {
char d1, d2, d3;
// input format: (1, 2)
in >> d1 >> P.x >> d2 >> P.y >>
d3;
return in;
}
};
int main()
{
vector<Point> original_points;
cout << "Enter points :\n";
Point P;
// loop continues until any error occurs
while(cin>>P)
{
// if any input error occurs, exit the loop keeping the valid
points in vector
if(cin.fail()){
cin.clear(); // back in 'normal' operation mode
cin.ignore(100,'\n'); // and remove the bad input
}
original_points.push_back(P);
}
ofstream out("mydata.txt");
cout << "You entered the points:\n";
for(Point p: original_points)
{
cout << p << '\n';
out << p << '\n';
}
out.close();
ifstream in("mydata.txt");
vector<Point> processed_points;
// loop to read the data from input file
while( in >> P )
{
// if input file read error occurs, exit the loop
if(in.fail())
{
in.clear(); // back in 'normal' operation mode
in.ignore(100,'\n'); // and remove the bad input
}
processed_points.push_back(P);
}
int n = original_points.size();
for(int i=0; i<n; i++)
{
if(original_points[i] == processed_points[i])
{
cout << "Points at index " << i << " are
same\n"
<< original_points[i] << " "
<< processed_points[i] << '\n';
}
if(original_points[i] != processed_points[i])
{
cout << "Points at index " << i << " are not
same\n"
<< original_points[i] << " "
<< processed_points[i] << '\n';
}
}
return 0;
}
Depend on this code, if the user enters the wrong input like
(8.5,8.7) change in to (8,8) then let the user enter another input
again the user enter like (er,yu) ignore this input and let the
user enter another input the user wants to terminate use file
termination. is there anybody can help
In: Computer Science
Add a new function that takes a phrase as an argument and counts each unique word in the phrase. The function should return a list of lists, where each sub-list is a unique [word, count] pair. Hint: A well-written list comprehension can solve this in a single line of code, but this approach is not required.
In: Computer Science
This is an assignment that I'm having trouble figuring out in python:
Modify Node class so it has a field called frequency and initialize it as one.
Add a search function. If a number is in the list, return its frequency.
Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add it to the beginning of the list.
Modify Delete function. When you delete a node, reduce its frequency. If frequency becomes zero, remove the node from the list.
Modify Print function to print out all the numbers with their frequency in the list.
The program that we are suppose to modify:
class Node:
def __init__(self,d):
self.data=d;# data in the node
self.next=None #address of next node
"""add a field called frequency here"""
class LinkedList:
def __init__(self):
self.head=None #linked list at the beginning is empty. head is
None
def print(self):#print every node's data
temp=self.head#let temp points to head
while temp:#As long as temp is not None (the end)
"""modify print, so frequency is also printed out frequency
"""
print(temp.data,end="")#print data
temp=temp.next # let temp points to the next Node
print()
"""complete the folloing function """
def insert(self,d):
temp=self.head
"""
travel the list like print, if d is in there break the loop
if yes, increase its freq
if not add it the front of the list like "push"
"""
"""
def push(self,new_d):#will add new node at the beginning
newNode=Node(new_d) #create a Node
newNode.next=self.head #Let new Node's next to be the original
head
self.head=newNode #update head as the New Node
def insertAfter(self,prev_data, new_data):
temp=self.head#let temp be the head
while temp and temp.data!=prev_data:#as long temp is not None and
data is not prev_data
temp=temp.next
#if you can get here. One of the condition must be false
if temp==None:#There is no prev_data because you have reached the
end
print("The given previous node does not exist")
return
#if you can reach here, temp.data=prev.data
newNode=Node(new_data)#create a new node after Node temp
newNode.next=temp.next#make newNode's next as temp's next
temp.next=newNode# make temp's(prev) next as NewNode
def append(self,new_data):# add new_data at the end of the
list
newNode=Node(new_data)#create a Node with new_data
if self.head==None:#in case the list is empty
self.head=newNode
return
last=self.head#let last be head
while last.next:#as long last next is not None, continue
last=last.next# let last as its next
#when loop terminates, last.next is None, therefore last points to
the last Node
last.next=newNode
"""
def delete(self,key):#delete a Node with data "key"
temp=self.head #let temp be head
if temp is not None:#if list is not empty
if temp.data==key:#if key is at the first Node
"""reduce temp'frequency
if its frequency becomes 0, execute the next three lines"""
self.head=temp.next #let head to head's next
temp=None
return
while temp is not None:#if list is not empty
if temp.data==key:#loop ends if key is found
break
prev=temp#prev is node before
temp=temp.next
#Loop ends either temp is None or loop ends because of "break"
which means key is found
if temp==None:
return #return because key is not in the list
#when temp.data is same as key
"""reduce temp'frequency
if its frequency becomes 0, execute the next three lines"""
prev.next=temp.next
temp=None
list=LinkedList()
list.insert(5)
list.insert(9)
list.insert(5)
list.insert(6)
list.insert(6)
list.insert(9)
list.print()
list.delete(5)
list.print()
list.delete(5)
list.print()
list.delete(6)
list.print()
list.delete(6)
list.print()
In: Computer Science
Handwritten Digit Recognition using Shallow ANN
The MNIST database of handwritten digits, available from this page, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image of 28-by-28.
Hint: The ANN should have 28*28=784 input nodes.
Data files:
Data input:
The data is stored in a very simple file format designed for storing vectors and multidimensional matrices. All the integers in the files are stored in the MSB first (high endian) format used by most non-Intel processors. You can use the functions loadMNISTImages and loadMNISTLabels to read in the training/testing set and label files respectively.
Data format for ANN:
Function loadMNISTImages will return an array of 784 rows, each column contains pixel values of an image.
Use the following code to convert labels into a 10-row array, each column represents one digit:
labels = loadMNISTLabels('training_label'); % initialize figure
labels = labels';
labels(labels==0)=10;
labels=dummyvar(labels);
Create an ANN:
Use patternnet(hiddenLayerSize, trainFcn)to create an ANN for pattern recognition. You may need to try different hiddenLayerSize and training function to obtain good results.
Testing:
After the ANN is trained, use the testing_set/label files to verify the ANN. You must SYSTEMATICALLY test the performance of your system, i.e. use the 20% of data as testing examples and report the overall accuracy, using different number of hidden nodes and training functions. Plotting will be helpful to visualize your results.
NEED TO WRITE CODE IN MATLAB
In: Computer Science
JAVA programming - please answer all prompts as apart of 1 java assignment.
Part A
Create a java class InventoryItem which has
Provide a copy constructor in addition to other constructors. The copy constructor should copy description and price but not howMany, which defaults to 1 instead. In all inheriting classes, also provide copy constructors which chain to this one.
Write a clone method that uses the copy constructor to create a copy. Create similar clone methods in all classes in this assignment.
Write a toString for this class that returns something like "Footo the Wonder Boot Exploder ($22.99)" (leave out howMany)
Also write an equals method for this class. InventoryItems can only be equal to other InventoryItems, and only if they have the same price and description (even if howMany is different). Note how the equals method agrees with the copy constructor about what it means for two InventoryItems to be the same.
Add a method view(), that prints something like "Viewing: Footo the Wonder Boot Exploder"
In a harness class with a main, create several InventoryItems, clone them, and check that equals works properly.
Part B
Create a class Book which inherits from InventoryItem and also has a String author (Book will use description to hold the book's title). toString for this class will return something like "Book: The Curse of the Flying Wombat by Constance deCoverlet ($12.95)".
For Book, override view() to print something like "Opening Book Exerpt: The Curse of the Flying Wombat"
Also override equals to require author is the same, in addition to the requirements in the superclass (chain the equals methods together).
Create a class MusicCD which inherits from InventoryItem and also has a String performer (it will use description to hold the CD's title). toString for this class will return something like "CD: Tommy Gnosis: Greatest Hits ($18.65)"
For MusicCD override view() to print something like "Now Playing Sample: Greatest Hits".
Also override equals to require performer is the same, in addition to the requirements in the superclass.
In your main, create more InventoryItem variables, but point them at a Book and a MusicCD. Use clone to make copies of each type and make sure this works. Check that equals works properly.
In: Computer Science
In shell script what is the reason this statement is not working?
x=7
y=13
while [ $x -le $y ]
do
echo $x
x=x+2
done
why on while statement it has error?
2.x=7
y=13
while [$x \< $y ]
do
echo $x
let x=x+2
done
what does it mean \< ? and give me the reason how this statement works
In: Computer Science
PYTHON PROGRAM!
Exercise 1 - The Collatz Conjecture
The Collatz conjecture was a mathematical proposal set forward by Lothar Collatz in 1937, also known as the 3n + 1 conjecture.
The conjecture is summarized as follows:
For example, if you start with 12, the series would be 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, and takes 9 iterations to get to 1.
The Collatz conjecture says that any starting number will eventually end up at 1. However, it is still unproven (see Mathematician Proves Huge Result on ‘Dangerous’ Problem (Links to an external site.) for some recent progress!).
Collatz visualization |
Write a python program that will determine how many iterations it takes for each starting value from 1 to 100 (experiment with higher values if you want!). Write out the starting value and number of iterations to a comma delimited csv file (i.e. one set of comma separated values per line). Also plot the result (starting value vs. iterations) with a visible marker for the points (you can choose which ever style you like) and no line. Make sure to give your plot a title and label the axes appropriately.
In: Computer Science
Consider an employee using their computer to send and retrieve email at their workplace. Only Ethernet networks are used for physical connectivity, but the mail server is located on a separate network. The employee’s network and the mail server’s network are connected by a single router which also has a connection to the Internet via the workplace’s ISP.
Explain how the employees email client sends and receives emails using the email server, indicating any protocols involved and where any encapsulation/decapsulation occurs as data travels between the client, local mail server, and remote mail servers.
In: Computer Science
As an IT professional who may face differing and competing priorities from business units, suggest one (1) strategy for negotiating an achievable project scope without damaging the relationship with business units. Support your answer with the steps that you would take in order to implement your strategy.
In: Computer Science
Can you provide source code in Java that
1. accepts a two-way acceptor via file;
2. and validate if the input string is part of the language
In: Computer Science