Assignment
Write each of the following functions. The function header must be implemented exactly as specified. Write a main function that tests each of your functions.
Specifics
In the main function ask for a filename and fill a list with the values from the file. Each file should have one numeric value per line. This has been done numerous times in class. You can create the data file using a text editor or the example given in class – do not create this file in this program. Then call each of the required functions and then display the results returned from the functions. Remember that the functions themselves will not display any output, they will return values that can then be written to the screen.
If there are built in functions in Python that will accomplish the tasks lists below YOU CANNOT USE THEM. The purpose of this lab is to get practice working with lists, not to get practice searching for methods. DO NOT sort the list, that changes the order of the items. The order of the values in the list should be the same as the order of the values in the file.
Required Functions
def findMaxValue (theList) – Return the largest integer value found in the list.
def findMinValue (theList) – Return the smallest integer value found in the list.
def findFirstOccurance (theList, valueToFind) – Return the index of the first occurrence of valueToFind. If valueToFind does not exist in the list return -1.
def findLastOccurance (theList, valueToFind) – Return the index of the last occurrence of valueToFind. If valueToFind does not exist in the list return -1.
def calcAverage (theList) – Return the average of all the values found in the list.
def findNumberAboveAverage (theList) - Return the number of values greater than OR equal to the average. This requires you to call the calcAverage function from this function – DO NOT repeat the code for calculating the average.
def findNumberBelowAverage (theList) - Return the number of values less than the average. This requires you to call the calcAverage function from this function – DO NOT repeat the code for calculating the average.
def standardDeviation (theList) – Return the standard deviation of the values. To find the standard deviation start with the average of the list. Then for each value in the list subtract the average from that value and square the result. Find the average of the squared differences and then take the square root of that average.
For example, if the list contains the values 4, 5, 6, and 3 the average of those values would be 4.5. Subtract 4.5 from each value and square that results. The differences would be -0.5, 0.5, 1.5 and -1.5 respectively. The square of each of those differences would be 0.25, 0.25, 2.25, and 2.25 respectively. The average of these values is 1.25 ((0.25 + 0.25 + 2.25 + 2.25) / 4).
In: Computer Science
C++ Code
You will write a program to process the lines in a text file using a linked list and shared pointers.
You will create a class “Node” with the following private data attributes:
• Line – line from a file (string)
• Next (shared pointer to a Node)
Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the style they use in the book of having a "#include" for the implementation file at the bottom of the header file, then you do not include your implementation file in the project.
You will have the following public methods:
• Accessors and mutators for each attribute
• Constructor that initializes the attributes to nulls (empty string)
You will make the linked list a class and make the processes class methods.
Your program will open a text file , read each line and store it in a Node. Make sure the file opened correctly before you start processing it. You do not know how many lines are in the file so your program should read until it gets to the end of the file. It will display the contents of the list (the lines that were read from the file) with all the duplicates.
Then your program will edit the list, removing any duplicate entries and display the list again once the duplicates have been removed.
Your linked list class should include the following methods, possibly more:
1. addNode – adds a node to the list given the value of the line
2. removeDuplicates – go through the entire list and remove any duplicate lines
3. displayList – displays each entry in the list
. You will write all of the code for processing the linked list - do not use any predefined objects in C++. You do not need to offer a user interface – simply display the list before and after removing duplicate lines.
To test the program, use the Stuff1.txt below:
Stuff1.txt
The sky is blue.
Clovis Bagwell
Shake rattle and roll.
The quick brown fox jumped over the lazy dog.
One red bean stuck in the bottom of a tin bowl.
Rats live on no evil star.
The sky is blue.
Mark Knopfler
The sky is blue.
Archibald Beechcroft
Oliver Crangle
Workers of the world unite.
Oliver Crangle
A squid eating dough in a polyethylene bag is fast and bulbous.
Somerset Frisby
Mark Knopfler
Oliver Crangle
Data structures is really hard.
It's raining and boring outside.
It's raining and boring outside.
It's raining and boring outside.
Somerset Frisby
Henry Bemis
Mark Knopfler
In: Computer Science
JAVA:
You're given 3 files. Demo.java, SampleInterace.java, and OverflowException.java. Use your Demo class to implement SampleInterface, and the OverflowException class should handle any errors that may come from the addNum method.
Demo.java:
public class Demo implements SampleInterface {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated constructor stub
}
@Override
public void addNum(int value) throws OverflowException {
// TODO Auto-generated method stub
}
@Override
public void removeNum(int value) {
// TODO Auto-generated method stub
}
@Override
public int sumOfNumbers() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
@Override
public boolean isFull() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
}
SampleInterface.java :
public interface SampleInterface {
/**
* Method adds a value to the list if the list doesn't have the value already
* If your list is full then the
* is full this method throws a OverflowException.
*
* @throws OverflowException
*/
public void addNum(int value) throws OverflowException;
/**
* This method will remove a value in your list if it's present
* If the value does not exist in this list then the list should remain unchanged
*
*/
public void removeNum(int value);
/**
* Method should add all numbers currently stored in the list and return it
* @return the sum of all the numbers stored in this object.
*/
public int sumOfNumbers();
/**
* removes all numbers from this object.
*/
public void clear();
/**
* Checks if the current list is full or not.
* @return true if the list in this object is full. false otherwise.
*/
public boolean isFull();
/**
* Checks if the current list is empty or not.
* @return true if the list in this object is empty. false otherwise.
*/
public boolean isEmpty();
}
OverflowException.java :
public class OverflowException extends Exception {
/**
*
*/
public OverflowException() {
// TODO Auto-generated constructor stub
}
/**
* @param arg0
*/
public OverflowException(String arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
/**
* @param arg0
*/
public OverflowException(Throwable arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
/**
* @param arg0
* @param arg1
*/
public OverflowException(String arg0, Throwable arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}
/**
* @param arg0
* @param arg1
* @param arg2
* @param arg3
*/
public OverflowException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
super(arg0, arg1, arg2, arg3);
// TODO Auto-generated constructor stub
}
}
In: Computer Science
In: Math
please run it and show a sample. please dont change the methods.
public interface PositionalList extends Iterable {
/**
* Returns the number of elements in the list.
* @return number of elements in the list
*/
int size();
/**
* Tests whether the list is empty.
* @return true if the list is empty, false otherwise
*/
boolean isEmpty();
/**
* Returns the first Position in the list.
*
* @return the first Position in the list (or null, if empty)
*/
Position first();
/**
* Returns the last Position in the list.
*
* @return the last Position in the list (or null, if empty)
*/
Position last();
/**
* Returns the Position immediately before Position p.
* @param p a Position of the list
* @return the Position of the preceding element (or null, if p is
first)
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position before(Position p) throws IllegalArgumentException;
/**
* Returns the Position immediately after Position p.
* @param p a Position of the list
* @return the Position of the following element (or null, if p is
last)
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position after(Position p) throws IllegalArgumentException;
/**
* Inserts an element at the front of the list.
*
* @param e the new element
* @return the Position representing the location of the new
element
*/
Position addFirst(E e);
/**
* Inserts an element at the back of the list.
*
* @param e the new element
* @return the Position representing the location of the new
element
*/
Position addLast(E e);
/**
* Inserts an element immediately before the given Position.
*
* @param p the Position before which the insertion takes
place
* @param e the new element
* @return the Position representing the location of the new
element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position addBefore(Position p, E e)
throws IllegalArgumentException;
/**
* Inserts an element immediately after the given Position.
*
* @param p the Position after which the insertion takes place
* @param e the new element
* @return the Position representing the location of the new
element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position addAfter(Position p, E e)
throws IllegalArgumentException;
/**
* Replaces the element stored at the given Position and returns the
replaced element.
*
* @param p the Position of the element to be replaced
* @param e the new element
* @return the replaced element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
E set(Position p, E e) throws IllegalArgumentException;
/**
* Removes the element stored at the given Position and returns
it.
* The given position is invalidated as a result.
*
* @param p the Position of the element to be removed
* @return the removed element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
E remove(Position p) throws IllegalArgumentException;
/**
* Returns an iterator of the elements stored in the list.
* @return iterator of the list's elements
*/
Iterator iterator();
/**
* Returns the positions of the list in iterable form from first to
last.
* @return iterable collection of the list's positions
*/
Iterable> positions();
}
import java.util.Iterator;
import Position; (interface)
import PositionalList;(interface)
public class DoublyLinkedList implements PositionalList
{
private int NumberofNode;
private Node head;
private Node tail;
public DoublyLinkedList()
{
head = new Node();
tail = new Node();
head.next =tail;
tail.prev = head;
}
@Override
public int size()
{
return NumberofNode;
return size;
}
@Override
public boolean isEmpty()
{
if(NumberofNode < 1 )
return
true;
else
return
false;
//return size ==0;
}
@Override
public Position first()
{
if(NumberofNode >=1)
return
head;
return null;
}
@Override
public Position last()
{
if(NumberofNode >= 1)
return
tail;
return null;
}
@Override
public Position before(Position p) throws
IllegalArgumentException
{
return null;
}
@Override
public Position after(Position p) throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addFirst(E e) {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addLast(E e) {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addBefore(Position p, E e)
throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addAfter(Position p, E e)
throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public E set(Position p, E e) throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public E remove(Position p) throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public Iterator iterator() {
// TODO Auto-generated method
stub
return null;
}
@Override
public Iterable> positions() {
// TODO Auto-generated method
stub
return null;
}
public E removeFirst() throws IllegalArgumentException
{
// TODO Auto-generated method
stub
return null;
}
public E removeLast() throws IllegalArgumentException
{
// TODO Auto-generated method
stub
return null;
}
}
In: Computer Science
****PLEASE ANSWER ALL QUESTIONS****
Question 1 (1 point)
164 employees of your firm were asked about their job satisfaction. Out of the 164, 47 said they were unsatisfied. What is the estimate of the population proportion? What is the standard error of this estimate?
Question 1 options:
|
|||
|
|||
|
|||
|
|||
|
Question 2 (1 point)
Suppose the nationwide high school dropout rate for 2014 was around 14.62%. If you checked the records of 472 students in high school in 2014, what is the probability that greater than 14.97% of them ended up dropping out?
Question 2 options:
|
|||
|
|||
|
|||
|
|||
|
Question 3 (1 point)
An airline records flight delays in and out of Chicago O'Hare airport for a year. The average delay for these flights is 9.64 minutes with a standard deviation of 3.51 minutes. For a sample of 49 flights, 94% of flights will have an average delay less than how many minutes?
Question 3 options:
|
|||
|
|||
|
|||
|
|||
|
Question 4 (1 point)
A U.S. census bureau pollster noted that in 411 random households surveyed, 252 occupants owned their own home. For a 95% confidence interval for the proportion of home owners, what is the margin of error?
Question 4 options:
|
|||
|
|||
|
|||
|
|||
|
Question 5 (1 point)
The Student Recreation Center wanted to determine what sort of physical activity was preferred by students. In a survey of 64 students, 39 indicated that they preferred outdoor exercise over exercising in a gym. They estimated the proportion of students at the university who prefer outdoor exercise as ( 0.452 , 0.7667 ), with 99% confidence. Which of the following is an appropriate interpretation of this confidence interval?
Question 5 options:
|
|||
|
|||
|
|||
|
|||
|
Question 6 (1 point)
The owner of a local phone store wanted to determine how much customers are willing to spend on the purchase of a new phone. In a random sample of 13 phones purchased that day, the sample mean was $493.254 and the standard deviation was $21.6007. Calculate a 90% confidence interval to estimate the average price customers are willing to pay per phone.
Question 6 options:
|
|||
|
|||
|
|||
|
|||
|
In: Statistics and Probability
Question 6
A high school math teacher believes that male and female students who graduated from the school perform equally well on SAT math test. She randomly chooses 10 male students and 10 female students who graduated from this school. The following are the SAT math scores of the 20 students:
Male: 23, 30, 27, 29, 22, 34, 36, 28, 28, 31
Female: 22, 33, 30, 28, 28, 31, 34, 25, 29, 21
Give a 95% confidence interval for the difference in the mean SAT math score between male and female students who graduated from this school.
Question 6 options:
|
-3.37 to 4.77 |
|
|
-2.18 to 6.01 |
|
|
-2,45 to 3.85 |
|
|
-0.34 to 7.61 |
Question 7
A survey asks this question "How long did you spend on shopping in the past week?" The responses (in hours) of 15 people are given below:
3, 0, 4, 1, 6, 1, 2, 4, 5, 2, 5, 4, 2, 5, 3
Find a 95% confidence interval for the mean number of hours people spent on shopping in the past week.
Question 7 options:
|
2.18 to 4.14 |
|
|
2.15 to 4.11 |
|
|
2.07 to 4.03 |
|
|
1.94 to 3.90 |
Question 8
A survey asks this question "How long did you spend on shopping in the past week?" The responses (in hours) of 15 people are given below:
3, 0, 4, 1, 6, 1, 2, 4, 5, 2, 5, 4, 2, 5, 3
Test the claim that the mean number of hours people spent on shopping in the past week is greater than 3 hours.
What is the p-value?
Question 8 options:
|
0.6128 |
|
|
0.7744 |
|
|
0.6635 |
|
|
0.3872 |
Question 9
Twelve students who were not satisfied with their ACT scores particiapted in an online 10-hour training program. The ACT scores before and after the training for the 12 students are given below:
| Student | Before | After |
|---|---|---|
| 1 | 23 | 27 |
| 2 | 25 | 26 |
| 3 | 27 | 31 |
| 4 | 30 | 32 |
| 5 | 24 | 26 |
| 6 | 25 | 24 |
| 7 | 27 | 31 |
| 8 | 26 | 28 |
| 9 | 28 | 30 |
| 10 | 22 | 25 |
| 11 | 20 | 24 |
| 12 | 29 | 32 |
Test a claim that the program is effective in improving a student’ ACT score.
What is the p-value?
Question 9 options:
|
Essentially 0 |
|
|
0.0325 |
|
|
0.0478 |
|
|
1.000 |
Question 10
A county environmental agency suspects that the fish in a particular polluted lake have elevated mercury level. To confirm that suspicion, five striped bass in that lake were caught and their tissues were tested for mercury. For the purpose of comparison, four striped bass in an unpolluted lake were also caught and tested. The fish tissue mercury levels in mg/kg are given below.
polluted: 0.580, 0.711, 0.571, 0.666, 0.598
unpolluted: 0.382, 0.276, 0.570, 0.366
Construct the 90% confidence interval for the difference in the population means based on these data.
Question 10 options:
|
0.05 to 0.40 |
|
|
0.08 to 0.37 |
|
|
0.10 to 0.35 |
|
|
0.04 to 0.41 |
In: Statistics and Probability
Question 6 (1 point)
A high school math teacher believes that male and female students
who graduated from the school perform equally well on SAT math
test. She randomly chooses 10 male students and 10 female students
who graduated from this school. The following are the SAT math
scores of the 20 students:
Male: 23, 30, 27, 29, 22, 34, 36, 28, 28, 31
Female: 22, 33, 30, 28, 28, 31, 34, 25, 29, 21
Give a 95% confidence interval for the difference in the mean SAT math score between male and female students who graduated from this school.
Question 6 options:
-3.37 to 4.77
-2.18 to 6.01
-2,45 to 3.85
-0.34 to 7.61
Question 7 (1 point)
A survey asks this question "How long did you spend on shopping in
the past week?" The responses (in hours) of 15 people are given
below:
3, 0, 4, 1, 6, 1, 2, 4, 5, 2, 5, 4, 2, 5, 3
Find a 95% confidence interval for the mean number of hours people spent on shopping in the past week.
Question 7 options:
2.18 to 4.14
2.15 to 4.11
2.07 to 4.03
1.94 to 3.90
Question 8 (1 point)
A survey asks this question "How long did you spend on shopping in
the past week?" The responses (in hours) of 15 people are given
below:
3, 0, 4, 1, 6, 1, 2, 4, 5, 2, 5, 4, 2, 5, 3
Test the claim that the mean number of hours people spent on shopping in the past week is greater than 3 hours.
What is the p-value?
Question 8 options:
0.6128
0.7744
0.6635
0.3872
Question 9 (1 point)
Twelve students who were not satisfied with their ACT scores
particiapted in an online 10-hour training program. The ACT scores
before and after the training for the 12 students are given
below:
Student Before After
1 23 27
2 25 26
3 27 31
4 30 32
5 24 26
6 25 24
7 27 31
8 26 28
9 28 30
10 22 25
11 20 24
12 29 32
Test a claim that the program is effective in improving a student’
ACT score.
What is the p-value?
Question 9 options:
Essentially 0
0.0325
0.0478
1.000
Question 10 (1 point)
A county environmental agency suspects that the fish in a
particular polluted lake have elevated mercury level. To confirm
that suspicion, five striped bass in that lake were caught and
their tissues were tested for mercury. For the purpose of
comparison, four striped bass in an unpolluted lake were also
caught and tested. The fish tissue mercury levels in mg/kg are
given below.
polluted: 0.580, 0.711, 0.571, 0.666, 0.598
unpolluted: 0.382, 0.276, 0.570, 0.366
Construct the 90% confidence interval for the difference in the population means based on these data.
Question 10 options:
0.05 to 0.40
0.08 to 0.37
0.10 to 0.35
0.04 to 0.41
In: Statistics and Probability
Although painful experiences are induced in social rituals in many parts of the world, little is known about the social effects of pain. Will sharing painful experiences in a small group lead to greater bonding of group members than sharing a similar non‑painful experience? Fifty‑four university students in South Wales were divided at random into a pain group containing 2727 students, with the remaining students in the no‑pain group.
Pain was induced by two tasks. In the first task, students submerged their hands in freezing water for as long as possible, moving metal balls at the bottom of the vessel into a submerged container; in the second task, students performed a standing wall squat with back straight and knees at 9090 degrees for as long as possible. The no‑pain group completed the first task using room temperature water for 9090 seconds and the second task by balancing on one foot for 6060 seconds, changing feet if necessary.
In both the pain and no‑pain settings, the students completed the tasks in small groups, which typically consisted of four students and contained similar levels of group interaction. Afterward, each student completed a questionnaire to create a bonding score based on answers to questions such as “I feel the participants in this study have a lot in common” or “I feel I can trust the other participants.” The table contains the bonding scores of the two groups.
| No‑pain group | 3.43 | 4.86 | 1.71 | 1.71 | 3.86 | 3.14 | 4.14 | 3.14 | 4.43 | 3.71 |
|---|---|---|---|---|---|---|---|---|---|---|
| 3.00 | 3.14 | 4.14 | 4.29 | 2.43 | 2.71 | 4.43 | 3.43 | 1.29 | 1.29 | |
| 3.00 | 3.00 | 2.86 | 2.14 | 4.71 | 1.00 | 3.71 | ||||
| Pain group | 4.71 | 4.86 | 4.14 | 1.29 | 2.29 | 4.43 | 3.57 | 4.43 | 3.57 | 3.43 |
| 4.14 | 3.86 | 4.57 | 4.57 | 4.29 | 1.43 | 4.29 | 3.57 | 3.57 | 3.43 | |
| 2.29 | 4.00 | 4.43 | 4.71 | 4.71 | 2.14 | 3.57 |
(a) Find the five‑number summaries for the pain and no‑pain groups. (Enter your answers rounded to two decimal places.)
No‑pain group Min =
No‑pain group ?1=
No‑pain group Median =
No‑pain group ?3=
No‑pain group Max =
pain group Min =
pain group ?1=
pain group Median =
pain group ?3=
pain group Max =
(b) Construct a comparative boxplot for the two groups and choose the correct image from the choices.
(c) Which group tends to have higher bonding scores?
no‑pain group
pain group
Compare the variability in the two groups.
The no‑pain group tends to have less variable bonding scores.
The variability in the two groups is similar.
The pain group tends to have less variable bonding scores.
Choose the correct statement about outliers.
Neither group contains one or more clear outliers.
Only the no‑pain group contains one or more clear outliers.
Only the pain group contains one or more clear outliers.
Both groups contain one or more clear outliers.
A scale is tested by repeatedly weighing a standard 9.0 kg weight. The weights for 8 measurements are
8.9,8.6,8.0,8.2,8.3,8.5,8.2,9.3
Mean: ________ kg
In: Statistics and Probability
Question 5 (1 point)
A student at a university wants to determine if the proportion of students that use iPhones is less than 0.46. The hypotheses for this scenario are as follows. Null Hypothesis: p ≥ 0.46, Alternative Hypothesis: p < 0.46. If the student takes a random sample of students and calculates a p-value of 0.8906 based on the data, what is the appropriate conclusion? Conclude at the 5% level of significance.
Question 5 options:
|
|||
|
|||
|
|||
|
|||
|
Question 6 (1 point)
You hear on the local news that for the city of Kalamazoo, the proportion of people who support President Trump is 0.37. However, you think it is greater than 0.37. The hypotheses you want to test are Null Hypothesis: p ≤ 0.37, Alternative Hypothesis: p > 0.37. You take a random sample around town and calculate a p-value for your hypothesis test of 0.9793. What is the appropriate conclusion? Conclude at the 5% level of significance.
Question 6 options:
|
|||
|
|||
|
|||
|
|||
|
Question 7 (1 point)
A medical researcher wants to determine if the average number of days spent in the hospital after a certain procedure is different from 9.8 days. If the researcher conducts a hypothesis test, what will the null and alternative hypotheses be?
Question 7 options:
|
|||
|
|||
|
|||
|
|||
|
Question 8 (1 point)
Consumers Energy states that the average electric bill across the state is $39.09. You want to test the claim that the average bill amount is actually different from $39.09. What are the appropriate hypotheses for this test?
Question 8 options:
|
|||
|
|||
|
|||
|
|||
|
In: Statistics and Probability