Questions
In math class, a student has written down a sequence of 16 numbers on the blackboard....

In math class, a student has written down a sequence of 16 numbers on the blackboard. Below each number, a second student writes down how many times that number occurs in the sequence. This results in a second sequence of 16 numbers. Below each number of the second sequence, a third student writes down how many times that number occurs in the second sequence. This results in a third sequence of numbers. In the same way, a fourth, fifth, sixth, and seventh student each construct a sequence from the previous one. Afterward, it turns out that the first six sequences are all different. The seventh sequence, however, turns out to be equal to the sixth sequence. Give one sequence that could have been the sequence written down by the first student. Explain which solution strategy or algorithm you have used.

In: Computer Science

create a code in JAVA that takes arguments to do a bfs(breadth first search) or a...

create a code in JAVA that takes arguments to do a bfs(breadth first search) or a dfs( depth first search) using a txt file as the graph input.

I have made most of the main function as well as a nose function I just need the bfs and dfs functions to work here's what I have so far, the comments that start with TODO are the parts that I need to finish

Main.java

import java.io.*;
import java.util;
ArrayList; import java.util.Iterator;
import java.util.List;

public class Main {
//class variables
private static boolean extendedOn;
public static String [] arr;
public static List<Node> nodeList;
public static Node firstNode;
public static int vertices;
//main method
public static void main(String[]args){
//the int for the arguments
int argument = 0;
int destination;
extendedOn = false;
boolean isDfs = false;
//checks to make sure that the user specified the destination
if(args[argument].equals("-dest")){
argument++;
try { destination = Integer.parseInt(args[argument]); argument++; }catch (Exception e{
System.out.println("Wrong Argument, needs an integer");
System.exit(0); } }
else{ System.out.println("Please specify the destination using -dest");
System.exit(0); }
//if the first arg is -e if(args[argument].equals("-e")){ argument++; extendedOn = true; }
//if args is dfs if(args[argument].equals("-dfs")){ argument++; isDfs = true; }
//if the args is -bfs else if(args[argument].equals("-bfs")){ argument++; isDfs = false; }
else{
System.out.println("Requires a Search Argument"); System.exit(0); }
//the argument that gets the file
File file = new File( args[argument] ); instantiateList(file); //gets the initial time Long timeStart = System.currentTimeMillis();
//figures out whether to do dfs or bfs
if(isDfs){ DFS(firstNode); }
else{ BFS(); }
//gets the endingTime Long timeEnd = System.currentTimeMillis(); System.out.println("\nTime Taken: " + (timeEnd - timeStart)); }

//method that populates the node list with how many vertices there are
private static void instantiateNodes(){
for(int y = 1; y <= vertices; y++){
nodeList.add(new Node(y)); }
firstNode = nodeList.get(0); }
//method to instantiate the List
public static void instantiateList(File file){
vertices = 0;
//String [] arr; //= new String[0];
//reads the file
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
//gets the vertices then creates the array which the buffered reader will put the values into
vertices = Integer.parseInt(br.readLine());
arr = new String[vertices];
int counter = 0;
//puts the values in String line = null;
while ((line = br.readLine()) != null)
{ arr[counter++] = line; } }
catch (FileNotFoundException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
//prints out the vertices and initializes the nodeList
System.out.println("\nVertices: " + vertices);
nodeList = new ArrayList<>(); instantiateNodes();
//for loop
for(int x = 0; x < vertices; x++){
//populates a list with the vertexes
String line = arr[x];
List adjacentVertexes = new ArrayList();
//while the line is not empty put it in the list
while(!line.isEmpty())
{ String vertex;
//if there are multiple vertexes
if(line.contains(" "))
{ vertex = line.substring(0, line.indexOf(" "));
//gets the node from the node list and adds it to the Node's adjacency List adjacentVertexes.add(nodeList.get( (Integer.parseInt(vertex)) - 1 )); }
//if there is only one vertex left else{ adjacentVertexes.add(nodeList.get( (Integer.parseInt(line)) - 1 ));
line = ""; break; } //changes the line to the next vertex line = line.substring(line.indexOf(" ")+1); }
//creates the node and initializes it
Node newNode = nodeList.get( ((Node)adjacentVertexes.get(0)).getVertex() - 1 );
//removes the name of the vertex and sets it's list adjacentVertexes.remove(0); newNode.setList(adjacentVertexes);
//adds the newNode to the list of Nodes nodeList.add(newNode); } }
//TODO method for the BFS
public static void BFS(){ System.out.println("BFS:"); }
//TODO method for the DFS
public static void DFS(){ System.out.println("DFS:"); } } }

Node.java

import java.util.List;
public class Node {    
//variable for if the node has been visited before     private boolean hasBeenSearched;   
 private List<Node> adjacency;    
private int vertex;    
public int searched;    
public Node(int v){      
 vertex = v;        
hasBeenSearched = false;     }    
//gets the vertex of the node    
public int getVertex(){        
return vertex;     }    
//sets the variables for if the node has already been searched    
public void setSearch(boolean search){         hasBeenSearched = search;     }    
//gets the varaible for the search of the node     public boolean getSearch(){     
   return hasBeenSearched;     }    
//method used to set the list full of nodes    
public void setList(List<Node> nodeList){         adjacency = nodeList;     }    
//method used to get the Node from the list     public Node getNode(int index){       
  return adjacency.get(index);     }    
//method used to get the size of the adjacency list     public int getSize(){         return adjacency.size();     } }

In: Computer Science

Please post code in format that can be copied. If possible please explain code but not...

Please post code in format that can be copied.

If possible please explain code but not necessary.

Directions:

1. Create a new project for the lab and copy stat.h, stat.cpp, and teststat.cpp into your workspace.

2. Now review the header file. Make sure you understand the design. Can you explain the difference between what the class represents versus how it plans to accomplish it?

3. Now edit the stat.cpp file. Notice that many of the member functions are missing. For all of the missing functions you will need to copy the function prototypes from the header file into the .cpp file. Remember to add Statistician:: before the name of each member function. (Not the friend functions or helper functions.)

4. Add the logic for 3 of the following methods (you may choose): • reset • mean • minimum • maximum • operator+ • operator==

5. You should now test all the functionality of the class (in the client/application code). Run the test code and determine if there are any errors in the code.

Stats.cpp

#include <iostream> // Provides istream classes
#include "stats.h"

using namespace std;

Statistician::Statistician( )
{
reset( );
}

void Statistician::next(double r)
{
total += r;
count++;
if ((count == 1) || (r < tinyest))
tinyest = r;
if ((count == 1) || (r > largest))
largest = r;
}


// implement reset

// implement mean

// implement minimum

// implement maximum

// implement operator +

// implement operator ==

istream& operator >>(istream& ins, Statistician& target)
{
double user_input;

while (ins && (ins.peek( ) != ';'))
{
   if (ins.peek( ) == ' ')
   ins.ignore( );
   else
   {
   ins >> user_input;
   target.next(user_input);
   }
}
ins.ignore( );

return ins;
}

ostream& operator <<(ostream& outs, Statistician& target)
{
outs << "Values for statistician object: " << endl;
outs << "\ttotal: " << target.total << endl;
outs << "\tcount: " << target.count << endl;
outs << "\tsmallest: " << target.tinyest << endl;
outs << "\tlargest: " << target.largest << endl << endl;

return outs;

}

stats.h

#ifndef STATS_H // Prevent duplicate definition
#define STATS_H
#include <iostream>

using namespace std;

class Statistician
{
public:
// CONSTRUCTOR
Statistician( );
// MODIFICATION MEMBER FUNCTIONS
void next(double r);
void reset( );
// CONSTANT MEMBER FUNCTIONS
int length( ) const { return count; }
double sum( ) const { return total; }
double mean( ) const;
double minimum( ) const;
double maximum( ) const;
// FRIEND FUNCTIONS
friend Statistician operator +
(const Statistician& s1, const Statistician& s2);
friend istream& operator >>
           (istream&, Statistician& s1);
       friend ostream& operator <<
       (ostream&, Statistician& s1);
private:
int count; // How many numbers in the sequence
double total; // The sum of all the numbers in the sequence
double tinyest; // The smallest number in the sequence
double largest; // The largest number in the sequence
};

// NON-MEMBER functions for the Statistician class
bool operator ==(const Statistician& s1, const Statistician& s2);

#endif

teststat.cpp


#include <iostream>
#include "stats.h"

using namespace std;

void menu (void)
{ cout<<endl<<endl;
cout<<"1. Add a number"<<endl;
cout<<"2. Reset the statistician"<<endl;
cout<<"3. Length"<<endl;
cout<<"4. Sum"<<endl;
cout<<"5. Mean"<<endl;
cout<<"6. Minimum"<<endl;
cout<<"7. Maximum"<<endl;
cout<<"8. Add"<<endl;
cout<<"9. Equality"<<endl;
cout<<"10. Print" << endl;
cout<<"11. Quit"<<endl<<endl;
cout<<"Enter selection>";
}

void add(Statistician& S)
{Statistician s2, s3;
s2.reset();
s3.reset();

//enter values for second stat
cout<<"Enter values for second stat, enter ; to stop"<<endl;
cin>>s2;

s3 = S + s2;
cout<<"Values for added statistician are:"<<endl;
cout<<"Length: "<<s3.length( )<<endl;
cout<<"Sum: "<<s3.sum( )<<endl;
}


void equal(const Statistician &S)
{ Statistician s2;
s2.reset();

//enter values for second stat
cout<<"Enter values for second stat, enter ; to stop"<<endl;
cin>>s2;

   if (s2==S) cout<<"equal"<<endl;
       else cout<<"unequal"<<endl;
}


//Beginning of main program
int main (void)
{
   int choice;
   double num;

   //declare a Statistician
   Statistician s;
   s.reset();

   do {
   //print menu
   menu();
   cin>>choice;

   switch (choice) {
       case 1 : cout<<endl<<"Enter a number> ";
               cin>>num;
               s.next(num);
               cout<<endl;
               break;

       case 2 : s.reset();
               cout<<endl<<"Statistician reset"<<endl;
               break;

       case 3: cout<<endl<<"Length is "<<s.length()<<endl;
               break;

       case 4: cout<<endl<<"Sum is "<<s.sum()<<endl;
               break;

       case 5: if (s.length() > 0)
                   cout<<endl<<"Mean is "<<s.mean()<<endl;
               else
                   cout<<"Must add a number first."<<endl;
               break;

       case 6: if (s.length() >0)
                   cout<<endl<<"Minimum is "<<s.minimum()<<endl;
               else
                   cout<<"Must add a number first."<<endl;
               break;

       case 7: if (s.length() >0)
                   cout<<endl<<"Maximum is "<<s.maximum()<<endl;
               else
                   cout<<"Must add a number first."<<endl;
               break;

       case 8: add(s);
               break;

       case 9: equal(s);
               break;

       case 10: cout << s;
               break;

       case 11: cout<<endl<<"Thanks and goodbye."<<endl;
               break;

       default : cout<<endl<<"Invalid command. Try again."<<endl;
   }

   } while (choice != 11);
}

In: Computer Science

Python. The array C has multibel peaks (+ , -). write a code that detect the...

Python.

The array C has multibel peaks (+ , -). write a code that detect the vlaues of all those peaks.
C = [0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0.0011
-0.0031
0.0011
0.0034
-0.0039
0.0004
0.0052
-0.0045
-0.0025
0.0067
-0.0038
-0.0034
0.0077
-0.0034
-0.0054
0.0076
-0.0011
-0.0063
0.0068
0.0004
-0.0084
0.0061
0.0037
-0.0086
0.0018
0.0063
-0.0045
-0.0069
0.0078
0.0027
-0.0132
0.0054
0.0133
-0.0131
-0.0060
0.0180
-0.0037
-0.0169
0.0140
0.0128
-0.0210
0.0048
0.0218
-0.0158
-0.0134
0.0216
-0.0004
-0.0205
0.0121
0.0126
-0.0197
-0.0031
0.0186
-0.0130
-0.0115
0.0160
-0.0010
-0.0114
0.0091
0.0026
-0.0087
0.0035
0.0043
-0.0047
0.0002
0.0025
-0.0015
-0.0006
0.0011
0.0002
-0.0006
-0.0004
0.0008
-0.0002
0
0
0
0
0
0
0
0
0
0
0]

In: Computer Science

What is my code missing? // chStr.cpp // Put your name here // Pseudocode #include #include...

What is my code missing?

// chStr.cpp

// Put your name here

// Pseudocode

#include

#include <___>

#include

using namespace std;

const string ANAME = "Katia Kool";

const char AGRADE = 'A';

const double COMMISSION_RATE_A = 0.02625;

const ___; . . . // likewise, constants for Betty

int main()

{

       int numberOfShares = 622;                // number of shares

       double pricePerShareA = 21.77;           // price per share

       double pricePerShareB = 12.44;           // price per share

       double stockA, stockB;                   // cost of stock, calculated

       double commissionA, commissionB;        // commission paid, calculated

       double totalA, totalB;                   // total cost, calculated

       // compute cost of the stock purchases

       stockA = pricePerShareA * numberOfShares;

       ___;

// compute amount of the commissions

       commissionA = stockA * COMMISSION_RATE_A;

       ___;

// compute total amounts

       totalA = stockA + commissionA;

       ___;

       // output results

       cout << fixed << showpoint << setprecision(2); // format output

       // your output should appear as below

       return 0;

}

/* Output:

Name: Katia Kool       Grade: A

Stock: $nnnnn.nn

Commission: $nnn.nn

Total: $nnnnn.nn

Name: Betty Boop       Grade: B

Stock: $nnnnn.nn

Commission: $nnn.nn

Total: $nnnnn.nn                  */

In: Computer Science

Write a C++ program that continuously requests a donation to be entered. If the donation is...

Write a C++ program that continuously requests a donation to be entered. If the donation is less than 0 or greater than 10, your program should print an appropriate message informing the user that an invalid donation has been entered, else the donation should be added to a total. When a donation of -1 is entered, the program should exit the repetition loop and compute and display the average of the valid donations entered.

In: Computer Science

in .java Write a program that reads an integer with 3 digits and prints each digit...

in .java

Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ...

Enter an integer of exactly 3 digits(e.g. 538): 319
9
1
3
Hint: consider what you get from these operations:
319%10
319/10
31%10

In: Computer Science

The advent of Information and Communication Technology has had a huge impact whether one is doing...

The advent of Information and Communication Technology has had a huge impact whether one is doing research, communicating or buying a product online. Write an essay about how ICT has positively impacted the commerce, write an essay and provide references or sources.

In: Computer Science

Define Intellectual Property (IP) Regarding China and IP What additional evidence would convince you that China’s...

Define Intellectual Property (IP)





Regarding China and IP

What additional evidence would convince you that China’s theft of technological secrets represents a national strategy rather than just a series of isolated incidents?




What actions might Western countries take to protect the loss of technological secrets and to reduce the risk of continuing to do business in China?





What is the essential difference between competitive intelligence and industrial espionage, and how is competitive intelligence gathered?





What are the four criteria for fair use?

1

2

3

4

What types of things cannot be patented?  



You be the judge: How would you rule on the 3M vs. Formula 1 copyright?


In: Computer Science

Starting with the following C++ program: #include <iostream> using namespace std; void main () { unsigned...

Starting with the following C++ program:

#include <iostream>

using namespace std;

void main ()

{

unsigned char c1;

unsigned char c2;

unsigned char c3;

unsigned char c4;

unsigned long i1 (0xaabbccee);

_asm

{

}

cout.flags (ios::hex);

cout << "results are " << (unsigned int) c1 << ", "

<< (unsigned int) c2 << ", "

<< (unsigned int) c3 << ", "

<< (unsigned int) c4 << endl;

}

Inside the block denoted by the _asm keyword, add code to move each byte of i1

into the unsigned chars c1 through c4 with the high order byte going into c1 and

the low order into c4.

In: Computer Science

2. Describe in detail i)what information should be added in which DNS servers for your own...

2. Describe in detail i)what information should be added in which DNS servers for your own start-up company (say ‘nwguru.com’) that has a webserver and email service to its employees. ii) What are companies you can contact for domain name registration and how much are the fees?

In: Computer Science

Write a C++ program to allow a user to enter in any positive number greater than...

Write a C++ program to allow a user to enter in any positive number greater than or equal to zero. The program should not continue until the user has entered valid input. Once valid input has been entered the application will determine if the number is an abundant number or not and display whether or not the number is an abundant number. If the user enters in a 0 the program should quit.

An abundant number is a number n for which the sum of divisors is greater than two times itself (i.e., >2n).

Consider 12: the divisors = ( 1,2 ,3,4,6,12)

1+2+3+4+6+12 = 25 > 2(12) = 25 > 24 (Yes 12 is abundant)

Consider 6: the divisors = ( 1,2 ,3, 6)

1+2+3+6 = 12 > 2(6) = 12 > 12 (No 6 is NOT abundant)

Make sure your program conforms to the following requirements:
1. Keep running until the user enters a 0. (5 points)
2. Make sure the number is positive (at least 0). (5 points).
3. Determine if the number is abundant or not and print a message to the user. (35 points)
4. Add comments wherever necessary. (5 points)

Sample Runs:

NOTE: not all possible runs are shown below.

Sample Run 1

Welcome to the abundant numbers program
Please enter in an number (>=0)...6
6 is NOT an abundant number
Please enter in an number (>=0)...12
12 is an abundant number
Please enter in an number (>=0)...-8
Please enter in an number (>=0)...24
24 is an abundant number
Please enter in an number (>=0)...45
45 is NOT an abundant number
Please enter in an number (>=0)...0

Process finished with exit code 0

Sample Run 2

Welcome to the abundant numbers program
Please enter in an number (>=0)...-8
Please enter in an number (>=0)...-12
Please enter in an number (>=0)...9
9 is NOT an abundant number
Please enter in an number (>=0)...0

Process finished with exit code 0

General Requirements:
1. No global variables (variables outside of main() )

2.Please make sure you;re only using the concepts already discussed in class. That is, please try and restrict yourself to input/output statements, variables, selection statements and loops. Using any other concept (like functions or arrays) will result in loss of points.

3. All input and output must be done with streams, using the library iostream

4. You may only use the iostream and iomanip libraries (you do not need any others for these tasks)

5. NO C style printing is permitted. (Aka, don’t use printf). Use cout if you need to print to the screen.

6. When you write source code, it should be readable and well-documented (comments).

In: Computer Science

Use Workbench/Command Line to create the commands that will run the following queries/problem scenarios. Use MySQL...

Use Workbench/Command Line to create the commands that will run the following queries/problem scenarios.

Use MySQL and the Colonial Adventure Tours database to complete the following exercises.

1. List the last name of each guide that does not live in Massachusetts (MA).

2. List the trip name of each trip that has the type Biking.

3. List the trip name of each trip that has the season Summer.

4. List the trip name of each trip that has the type Hiking and that has a distance longer than 10 miles.

5. List the customer number, customer last name, and customer first name of each customer that lives in New Jersey (NJ), New York (NY) or Pennsylvania (PA). Use the IN operator in your command.

6. Repeat Exercise 5 and sort the records by state in descending order and then by customer last name in ascending order.

7. How many trips are in the states of Maine (ME) or Massachusetts (MA)?

8. How many trips originate in each state?

9. How many reservations include a trip price that is greater than $20 but less than $75?

10. How many trips of each type are there?

11. Colonial Adventure Tours calculates the total price of a trip by adding the trip price plus other fees and multiplying the result by the number of persons included in the reservation. List the reservation ID, trip ID, customer number, and total price for all reservations where the number of persons is greater than four. Use the column name TOTAL_PRICE for the calculated field.

12. Find the name of each trip containing the word “Pond.”

13. List the guide’s last name and guide’s first name for all guides that were hired before June 10, 2013.

14. What is the average distance and the average maximum group size for each type of trip?

15. Display the different seasons in which trips are offered. List each season only once.

16. List the reservation IDs for reservations that are for a paddling trip. (Hint: Use a subquery.)

17. What is the longest distance for a biking trip?

18. For each trip in the RESERVATION table that has more than one reservation, group by trip ID and sum the trip price. (Hint: Use the COUNT function and a HAVING clause.)

19. How many current reservations does Colonial Adventure Tours have and what is the total number of persons for all reservations?

In: Computer Science

In c++ language, write a void function GetYear that prompts for and inputs the year the...

In c++ language, write a void function GetYear that prompts for and inputs the year the operator was born (type int) from standard input. The function returns the user’s birth year through the parameter list (use pass by reference) unless the user enters an invalid year, in which case a BadYear exception is thrown. To test for a bad year, think about the range of acceptable years. It must be 4 digits (i.e. 1982) and it cannot be greater than the current year (the user obviously cannot be born in a calendar year that has yet to happen!).

Then write a try-catch statement that calls the GetYear function defined above. If a BadYear exception is thrown, print an error message and rethrow the exception to a caller; otherwise, execution should just continue as normal.

Consider the Fraction class that we just wrote. Implement an exception handling design in the parameterized constructor to catch zeros in the denominator. Show the new exception class you will need to put in the header (specification) file. Show the definition for your parameterized constructor that throws the exception if the denominator is zero. Finally, show how to use the try-catch statement in the driver program when instantiating a new parameterized Fraction object. (For this part you do not need to show entire programs, only the requested lines of source code.)

In: Computer Science

Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of...

Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of the class.

I have added the Javadoc comments but please feel free to format them if they are done incorrectly.

public class Nickel implements Comparable {

private int year;

/**

* The monetary value of a nickel in cents.

*/

public final int CENTS = 5;

/**

* Initializes this nickel to have the specified issue year.

*

* @param year

*

* @pre. year must be greater than or equal to 1858

*/

Nickel (int year){

}

/**

* Returns the issue year of this coin.

* @return

*/

public int issueYear() {

}

/**

* Compares this nickel to the specified object for equality. The result is true if obj

* is a nickel. The issue year is not considered when comparing two nickels for equality.

*

* @param obj

*

* @return

*/

public boolean equals​(Object obj) {

}

/**

* Returns a hash code for this nickel. Specifically, this method returns the issue year of this nickel.

*/

public int hashCode() {

}

/**

* Compares this nickel to another nickel by their issue year.

* The result is a negative integer if this nickel has an earlier issue year than

* the other nickel, a positive integer if this nickel has a later issue year than

* the the other nickel, and zero otherwise. Specifically, this method returns the

* difference of the issue year of this nickel and the issue year of the other nickel.

*

* @param other

*

* @return

*/

@Override

public int compareTo(Nickel o) {

}

}

In: Computer Science