Questions
Create a Matlab program to load in the attached file File_Q5_Use.csv. You will first need to...

Create a Matlab program to load in the attached file File_Q5_Use.csv. You will first need to click on the link to open it, then save it as a .csv file in the directory you are using in your Matlab programs before you can load it in to Matlab.

It has 2 columns, the first column is the x values, the second column is the y values. Set Figure (1). Plot the points using red stars and a blue line with a title of 'Original Points' and get a general idea of what the degree of the polynomial is. It might be easier to split the matrix into 2 vectors x_vec and y_vec.

From the graph - where approximately are the real zeros of this polynomial? Does this polynomial appear to be ODD or EVEN. ? Answer the questions in the %RESULTS.  

After this plot, set Figure (2) to get a different Figure window open but so that the old figure window does not close.

Next, use POLYFIT to find the polynomial that fits the data [Hint: it is less than degree 8 and more than degree 1]. Use a FOR loop to cycle through the from n = 2:1:7 and do the following on each loop:

a. Find using POLYFIT, the polynomial for each degree of n. Do NOT suppress the values of the coefficients returned by each pass through the FOR loop.  

b. Using SUBPLOT where n is the location, plot on the same graph, the original points using red stars and the polynomial created by POLYFIT using a range of [-3:0.1:3] using a blue line. Make a title for each subgraph showing the degree of the polynomial fitted.  

Based upon the 6 graphs, which do you think is the correct degree of the polynomial? Answer in %RESULTS.

The basis for this polynomial was: 2x^5 - 3x^4 + 2x^3 -3x^2 - 144x + 216 = 0. Create a Figure 3 which plots the original points in red stars and points from this polynomial in a blue line for a range of [-3 : 0.1 : 3 ].  

Looking at the graphs, how many data points appear to be outliers, i.e. they probably should not be used in the graph? Answer in %RESULTS.

Looking at the graphs, the plots for degree 5, 6, 7 all appear to be almost the same. Switch to full screen to examine Figure 2. Remembering that the line of best fit passes through as many points as possible and minimizes the distances between the line and the points, can you determine by eye which degree of 5, 6, or 7 would be best?

Save as LastName_FirstName_Quiz_5_6_Q5

File to open. Hint: Make sure this file is in the same directory where you are saving LastName_FirstName_Quiz_5_6_Q5.

File_Q5_Use.csv

In: Computer Science

1 What is a pure virtual function? Why would you define a pure virtual function? Give...

1 What is a pure virtual function? Why would you define a pure virtual function? Give an example of a pure virtual function.

2 When a function has an object parameter that it doesn't modify,
what is the best way to declare the parameter (in the function
signature), and why?

3 Show an example using a function with a string object parameter.

a) When a class has objects as data members, why should its
constructors use initialization lists (member and initializer
syntax) vs. assignment to the members in the body of the ctor?
  
b) Name two cases where you *must* use initialization lists in
constructors (as opposed to assignment in the ctor body).

4 When a function has an object parameter that it doesn't modify,
what is the best way to declare the parameter (in the function
signature), and why?
Show an example using a function with a string object parameter.

In: Computer Science

Create a new Java project called 1410_Recursion. Add a package recursion and a class Recursion. Include...

Create a new Java project called 1410_Recursion. Add a package recursion and a class Recursion. Include the following three static methods described below. However, don't implement them right away. Instead, start by returning the default value followed by a // TODO comment.

  1. public static int sumOfDigits(int n)
    This method returns the sum of all the digits.
    sumOfDigits(-34) -> 7
    sumOfDigits(1038) -> 12
  2. public static int countSmiles(char[] letters, int index)
    This method counts the number of colons followed by a closing parenthesis.
    countSmiles([:,), ,L,i,f,e, ,i,s, ,g,o,o,d, ,:,)], 0) -> 2
    countSmiles([H,a,p,p,y, ,D,a,y, ,:,),:,),:,),!], 0) -> 3
    countSmiles([a,:,b,(,c,),:, ,),e], 0) -> 0
  3. public static String toUpper(String str)
    This method separates all characters by a space and changes all lowercase letters to uppercase letters.
    E.g. "Hi there!" returns "H I T H E R E !"
    Hint: Class Character (Links to an external site.) includes a method toUpperCase (Links to an external site.)​

Create a second source folder called test. It should include a class RecursionTest. That's where you will write the JUnit tests for the three methods above.

  • Each of the three methods should have at least eight corresponding JUnit tests.
  • Choose test data deliberately to provide thorough testing that covers as many potential problems as possible.

Once you have written the JUnit tests, implement the methods.

In: Computer Science

Create in Java Create a stack class to store integers and implement following methods: 1- void...

Create in Java

Create a stack class to store integers and implement following methods:

1- void push(int num): This method will push an integer to the top of the stack.

2- int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1.

3- void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value).

4- Boolean isEmpty(): This method will check the stack and if it is empty, this will return true, otherwise false.

Create a queue class to store integers and implement following methods:

1- void enqueue(int num): This method will add an integer to the queue (end of the queue).

2- int dequeue(): This method will return the first item in the queue (First In First Out).

3- void display(): This method will display all items in the queue (First item will be displayed first).

4- Boolean isEmpty(): This method will check the queue and if it is empty, this will return true, otherwise false.

Using the Stack and the Queue classes created on previous questions, implement an algorithm to receive a stack with some items stored in it and using the queue reverse the stack.

You can

Example:

Let's say we have following stack, where last item pushed to stack is 1. (5 is the first number pushed to stack):

1, 2, 3, 4, 5

After running your algorithm the stack must be reversed and first item in the stack (top) must be 5 as follow:

5, 4, 3, 2, 1

In: Computer Science

Question) The following simple shell program/code using gets() function to obtain input from user. Using the...

Question) The following simple shell program/code using gets() function to obtain input from user. Using the gets() function is potentially dangerous and it allows buffer to overflow.

You need to do following modification in the code;

(a) change the provided code so that you now use fgets() function instead of fget() to obtain input from the user,
(b) make any other necessary changes in the code because of using fgets() function, and
(c) fill in the code for the exectute() function so that the whole program works as expected (a simple shell program).



******************************** C O D E **********************************

/* The program asks for UNIX commands to be typed and inputted to a string*/
/* The string is then "parsed" by locating blanks etc. */
/* Each command and corresponding arguments are put in a args array */
/* execvp is called to execute these commands in child process */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

void parse(char *buf, char **args);
void execute(char **args);
char *gets(char *s);

int main(int argc, char *argv[])
{
    char buf[1024];
    char *args[64];

    for (;;) {
        /*
         * Prompt for and read a command.
         */
        printf("Command: ");

        if (gets(buf) == NULL) {
            printf("\n");
            exit(0);
        }

        /*
         * Split the string into arguments.
         */
        parse(buf, args);

        /*
         * Execute the command.
         */
        execute(args);
    }
}

/*
 * parse--split the command in buf into
 *         individual arguments.
 */
void parse(char *buf, char **args)
{
    while (*buf != '\0') {
        /*
         * Strip whitespace.  Use nulls, so
         * that the previous argument is terminated
         * automatically.
         */
        while ((*buf == ' ') || (*buf == '\t'))
            *buf++ = '\0';

        /*
         * Save the argument.
         */
        *args++ = buf;

        /*
         * Skip over the argument.
         */
        while ((*buf != '\0') && (*buf != ' ') && (*buf != '\t'))
            buf++;
    }

    *args = NULL;
}

/*
 * execute--spawn a child process and execute
 *           the program.
 */
void execute(char **args)
{
//fill in your code here

}

In: Computer Science

Assignment: Subnetting In this assignment, you are required to re-organize our Department's wired computer network. The...

Assignment: Subnetting In this assignment, you are required to re-organize our Department's wired computer network. The first part of the assignment familiarizes you with the current network. The second part requires you to divide the current network into two sub-networks: a small one for the staff and a larger one for the students.

Part 1 Our senior academic Prof Dumbledore's Departmental desktop has the IP address 26.221.51.236/21. Based on this, please answer the following questions.

What is the network address of this network? [1 mark]

What is the network mask of this network? [1 mark]

What is the broadcast address in this network? [1 mark]

What is the lowest host IP address in this network? [1 mark]

Assuming that the router is assigned the largest available IP address in the range, what is the IP address of this network's router? [1 mark]

What is the largest host IP address in this network, excluding the router? [1 mark]

What is the maximum number of hosts that can be supported in this network? [1 mark]

Part 2

In this part, you are asked to partition the Departmental network address block to create separate staff and student sub-networks. Your network must be able to support up to 143 machines on the staff network (not counting the router) and up to 654 machines on the student network (also not counting the router). You must choose the largest possible network address for the student network. You must then choose the smallest possible network address for the staff network. You must also choose the smallest possible size for the two sub-networks so that a visitor/guest network can be established in the future with the remaining network capacity.

Part 2A

Based on your partition, please answer the following questions that relate to the student network.

What is the network address of this network? [1 mark]

What is the network mask of this network? [1 mark]

What is the broadcast address in this network? [1 mark]

What is the lowest host IP address in this network? [1 mark]

Assuming that the router is assigned the largest available IP address in the range, what is the IP address of this network's router? [1 mark]

What is the largest host IP address in this network, excluding the router? [1 mark]

What is the maximum number of hosts that can be supported in this network? [1 mark]

Part 2B

Based on your partition, please answer the following questions that relate to the staff network.

What is the network address of this network? [1 mark]

What is the network mask of this network? [1 mark]

What is the broadcast address in this network? [1 mark]

What is the lowest host IP address in this network? [1 mark]

Assuming that the router is assigned the largest available IP address in the range, what is the IP address of this network's router? [1 mark]

What is the largest host IP address in this network, excluding the router? [1 mark]

What is the maximum number of hosts that can be supported in this network? [1 mark]

In: Computer Science

use java recursion find # of times a substring is in a string but it has...

use java recursion

find # of times a substring is in a string but it has to be the exact same, no extra letters attached to it and capitalization matters.

input: school is boring with schooling and School

substring: school

output: 1

In: Computer Science

import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(")...

import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(") " + entry) return int(input(question))

plz explain this code

In: Computer Science

Create a UEmployee class that contains member variables for the university employee name and salary. The...

Create a UEmployee class that contains member variables for the university employee name and salary. The UEmployee class should contain member methods for returning the employee name and salary. Create Faculty and Staff classes that inherit the UEmployee class. The Faculty class should include members for storing and returning the department name. The Staff class should include members for storing and returning the job title. Write a runner program that creates one instance of each class and prints all of the data for each object.

Note: For PreferredCustomer, add a public void method named makePurchase, which has one double value as its parameter. It's function is to add the parameter to the internal amount spent variable for the PreferredCustomer; and it will need to update the discount if this PreferredCustomer has reached a new rewards tier. Make sure your runner makes purchases that changes, and displays, new discounts for PreferredCustomers.

In: Computer Science

write a program including the pseudocode write a progrqm that outputs a grade based on user...

write a program including the pseudocode write a progrqm that outputs a grade based on user input. an example if the user enters an 80 the program will output the grade is B.
grading scale:
90-100=A
80-89=B
70-79=C
65-69=D
0-64=F

In: Computer Science

List two different ways for developing bagging ensembles and describe each method in a few words.

List two different ways for developing bagging ensembles and describe each method in a few words.

In: Computer Science

package homework; // 1 point penalty for not restoring the package before turning this in //...

package homework; // 1 point penalty for not restoring the package before turning this in

// CSC 403 W20 HW6

// Fix the toDo items

/* AINSLEY SOANE */

import java.time.LocalDate;

public class GpsTime {

private double longitude;

private double latitude;

private LocalDate when;

//ToDo 1 implement the required constructor (see other file)

public GpsTime( double longitude, double latitude, LocalDate when) {

//super();

this.longitude = longitude;

this.latitude = latitude;

this.when = when;

}

//ToDo 2 update the hashcode function below

// You can try your answer from hw5, or make up a new one

public int hashCode() {

int hash = 17;

hash = 31* hash + ((Double) longitude).hashCode();

hash = 31* hash + ((Double) latitude).hashCode();

hash = 31* hash + when.hashCode();

return hash;

}

//ToDo 3 use the textbook 'recipe' to implement the equals function for this class

public boolean equals( Object x) {

return false; // fix this

}

public String toString() {

return Double.toString(longitude)+ " "+Double.toString(latitude)+" "+when.toString();

}

}

How do I do toDo 3? I've been trying to do it but can't figure it out.

In: Computer Science

Consider the following snapshot of a system: Allocation                   Max                 Availa

Consider the following snapshot of a system:

Allocation                   Max                 Available

A B C D              A B C D                    A B C D

P0                    0 0 1 2                0 0 1 2                      1 5 2 0

P1                    1 0 0 0                1 7 5 0

P2                    1 3 5 4                2 3 5 6

P3                    0 6 3 2                0 6 5 2

P4                   0 0 1 4               0 6 5 6

Answer the following questions using the banker’s algorithm:

a. What is the content of the matrix Need?

b. Is the system in a safe state? Demonstrate the reason for your answer.

c. If a request from process P1 arrives for (0,4,2,0), can the request be granted immediately? Demonstrate the reason for your answer.

IN TEXT ONLY!!!

In: Computer Science

Tower of Hanoi - Java Code Use three rods labeled A, B, and C Use three...

Tower of Hanoi - Java Code

  • Use three rods labeled A, B, and C
  • Use three discs labels 1 (smallest), 2 (medium size), and 3 (largest disc)
  • The program prompts you to enter the starting rod (A, B, or C)
  • The program prompts you to enter the ending rod (A, B, or C, but cannot be same rod as entered as starting rod)
  • The starting rod has discs 1, 2, 3, where 1 is on top of 2 is on top of 3 (just like we covered in class)
  • Your program should print out each move, showing clearly which disc goes from/to. See trace below.

Example output

Tower of Hanoi
Program by YOUR NAME
Enter Starting Rod  (A, B, or C): A
Enter Ending Rod (A, B, or C): A
Sorry.  starting and ending rod cannot be the same.
Enter Ending Rod ((A, B, or C): C
OK Starting with  discs 1, 2, and 3 on rod A
Moves are as follows:
1. Move disc 1 from rod A to rod C
2. Move disc 2 from rod A to rod B
3. Move disc 1 from rod C to rod B
4. Move disc. 3 from rod A to rod C
5. Move disk 1 from rod B to rod A
6. Move disk 2 from rod B to rod C
7. Move disk 1 from rod A to rod C
All done. Took a total of 7 moves.

In: Computer Science

JAVA the task is to implement the missing methods in the LinkedIntSet class. Each method you...

JAVA

the task is to implement the missing methods in the LinkedIntSet class. Each method you must write has comments describing how it should behave. You may not add any new fields to the LinkedIntSet class and you may only add new code inside the bodies of the 5 methods you are asked to write. You may also write new private helper methods. However, you may not change any method headers, you may not change any code outside of the 5 methods, and you may not add any new data fields to the class.

public class LinkedIntSet {
   private static class Node {
       private int data;
       private Node next;
      
       public Node(int data, Node next) {
           this.data = data;
           this.next = next;
       }
   }
  
   private Node first;

   public LinkedIntSet() {
       first = null;
   }

   public int size() {
       int counter = 0;
       for (Node current = first; current != null; current = current.next)
           counter++;
       return counter;
   }

   public boolean contains(int i) {
       for (Node current = first; current != null; current = current.next) {
           if (current.data == i)
               return true;
       }
       return false;
   }

   // Ignore this equals method. Write the code for the other equals method.
   public boolean equals(Object otherObject) {
       LinkedIntSet other = (LinkedIntSet) otherObject;
       return this.equals(other);
   }

   /***************************** NEW METHODS ************************************/

   /**
   * Adds <code>element</code> to this set if it is not already present and
   * returns <code>true</code>. If <code>element</code> is already present, the
   * set is unchanged and <code>false</code> is returned.
   *
   * @param element the element to be added
   * @return <code>true</code> if the element was added and <code>false</code>
   * otherwise.
   */
   public boolean addElement(int element) {
       // Replace the line below with your answer
       throw new RuntimeException("Not implemented");
   }

/**
   * Removes an element from the set.
   *
   * @param element the element to be removed
   * @return <code>ture</code> if the element was removed and <code>false</code>
   * otherwise.
   */
   public boolean removeElement(int element) {
       // Replace the line below with your answer
       throw new RuntimeException("Not implemented");
   }

In: Computer Science