Questions
Write a recursive program in C++ to compute the determinant of an NxN matrix, A. Your...

  1. Write a recursive program in C++ to compute the determinant of an NxN matrix, A. Your program should ask the user to enter the value of N, followed by the path of a file where the entries of the matrix could be found. It should then read the file, compute the determinant and return its value. Compile and run your program.

In: Computer Science

What factors should be considered in selecting a design strategy?

  1. What factors should be considered in selecting a design strategy?

In: Computer Science

MergeSort has a rather high memory space requirement, because every recursive call maintains a copy of...

MergeSort has a rather high memory space requirement, because every recursive call maintains a copy of the sorted subarrays that will be merged in the merge step. What is the memory space requirement in terms of O(.)? Describe how you would implement MergeSort in such a way that merge is done in-place and less memory space is needed? In-place means MergeSort does not take extra memory for the merge operation as in the default implementation.

In: Computer Science

PLEASE NO USE OF LINKED LIST OR ARRAYS(USE CHARACTER POINTERS INSTEAD) TO HOLD DATA STRUCTURES This...

PLEASE NO USE OF LINKED LIST OR ARRAYS(USE CHARACTER POINTERS INSTEAD) TO HOLD DATA STRUCTURES

This lab, for which you may work in groups of two, will require you to use a C structure to hold a record of any kind of data, i.e., address book, library of books as with chapter 14, etc. These records will be held in dynamic memory using memory allocation (malloc) to create new memory and the function (free) to release memory created via (malloc). Do not use linked lists for this assignment, we are using dynamic memory allocation to hold records, not using linked lists. The structures will act as an in memory database for your records (structures), and you will need to create enough memory to hold all of your records, but also when you remove records, you will need to allocate new memory, move the data over to that memory space, and free the old memory (instead of using a static size array). No use of arrays is allowed to hold your structures, but you can use arrays in other places in your program. Your program will prompt for information that will be added to a new structure that will be added when you call the add function. Delete is as simple as just taking the last record out of your database (i.e. no need to search for a “record” to delete - this assignment is about pointers and memory allocation / free, so no need to make the algorithm more complicated). In addition to your memory to hold your data / structures, your program will also need to hold a static duration memory type that will serve as the counter for how many times the database has changed. Along with the amount of times the database has changed, you will also need to have a variable to hold the number of records in your database, functions to calculate size (records multiplied by sizeof struct), and functions to add, print, and delete records. You will not be required to use lookup functions, print is just the entire database. To manage your in-memory database, you will need to use some pointers to hold locations of your data. Please take some time to write down examples of where you will need to have pointers. You will need to have at least a pointer to the beginning of your database memory, another to show which record you are on, but think about the need for other pointers when you think about functions that will delete a record, add a record, etc. One of the major points of this assignment is not just the ability to manage records in memory, it is also about how to manage the memory itself. There is a huge inherent danger in how memory is allocated and subsequently not released properly which will create a “memory leak” in your program which will consume memory over time and crash your system (due to all the memory being used, or your process hitting a max limit of memory). This will mean that you will need to manage how pointers are pointing at data very carefully as it is very easy to create a memory leak and your program will not crash, it will just not release memory properly. You will need a menu to prompt users for the above requirements that may look like: MENU ======= 1. Print all records 2. Print number of records 3. Print size of database 4. Add record 5. Delete record 6. Print number of accesses to database 7. Exit Once you have gathered the appropriate information you will need to manipulate the data to hold the data correctly, but we are not using File I/O to maintain state on the data (would require too much time). Your database is a memory only database, so once your program ends, your database is gone. Being this is the case, it will be important to create a header file that has some data in it (5-7 records), so you will not need to enter all the records every time.

In: Computer Science

You are given a singly linked list. Write a function to find if the linked list...

You are given a singly linked list. Write a function to find if the linked list contains a cycle or not. A linked list may contain a cycle anywhere. A cycle means that some nodes are connected in the linked list. It doesn't necessarily mean that all nodes in the linked list have to be connected in a cycle starting and ending at the head. You may want to examine Floyd's Cycle Detection algorithm.

/*This function returns true if given linked 
list has a cycle, else returns false. */
static boolean hasCycle( Node head) 

In: Computer Science

The below_freezing function takes a string as its parameter and return True if the temperature specified...

The below_freezing function takes a string as its parameter and return True if the temperature specified by the string is below freezing point for water. It returns False if the temperature is at or above the freezing point. The string takes the format of a decimal number followed by a letter where F stands for Fahrenheit, C for Celsius, and K for Kelvin. For example, below_freezing("45.5F") and below_freezing("300K") both return False. below_freezing("-1.2C") and below_freezing("272K") both return True It's critical that you include test case code to show proper testing. PLEASE DO IN PYTHON

In: Computer Science

read in firstNum. 2) read in secondNum. 3)  run the loop,  If secondNum is 0 then...

read in firstNum.

2) read in secondNum.

3)  run the loop,  If secondNum is 0 then print out firstNum, otherwise, temp =firstNum % secondNum, firstNum = secondNum, secondNum = temp.

Your code MUST have your name, and date, and description of the algorithms as comments.

Submit GCD.java file and the screen shoot of compile and run result (image file or PDF file) from JGRASP.

 

//This program demonstrates parts of greatest common divisor
// It shows how to calculate the remainder of two integers and also
// how a while loop works with a place holder (temp) variable

// Algorithm
// Read in two positive integer
// Using a while loop, print the remainder value, and then decrement the value
// Finally, print out the final value of gcd

import java.util.Scanner;

public class GCD {
 
    public static void main(String[] args) {
      
       int firstNum;
       int secondNum;
       int gcd =0;
      
      
       Scanner input = new Scanner( System.in );
       //user input the first number

       ……………………………………

       ……………………………………

       ……………………………………
      

      //user input the second number

        ………………………………………

        ………………………………………..

         ………………………………………..
      
       //if the second number is 0

      
        //while loop   
       while ( secondNum != 0){ 
          int temp = firstNum%secondNum;

           ……….............................................

          ........................................................


           System.out.println(temp);        
       }
             
      System.out.println("And finally gcd has the value of  " + gcd);

     }// of main
} // of class GCD

In: Computer Science

Doing recursion to match digits of two inputted integers. Found this online and it works but...

Doing recursion to match digits of two inputted integers. Found this online and it works but I wanna understand how each line works. Like why x %10 == y%10 and calling DigitMatch(x/10,y/10)?

public int digitMatch(int x, int y){

    if(x < 0 || y < 0){

      throw new IllegalArgumentException();

    }

      else if(x < 10 || y < 10){

         if(x % 10 == y % 10)

            return 1;

         else

             return 0;

      } else if( x % 10 == y % 10){

         return 1 + digitMatch(x/10, y/10);

      }

    else{

         return digitMatch(x/10,y/10);

    }

In: Computer Science

[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter...

[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter five floating point values from the keyboard (warning: you are not allowed to use arrays or sorting methods in this assignment - will result in zero credit if done!). Have the program display the five floating point values along with the minimum and maximum values, and average of the five values that were entered. Your program should be similar to (have outputted values be displayed with 4 digits of precision after decimal point, in bold underline is what your user types in when they run the program): Enter Value 1: 2.34567 Enter Value 2: 3.45678 Enter Value 3: 1.23456 Enter Value 4: 5.67891 Enter Value 5: 4.56789 The values entered are: 2.3457, 3.4568, 1.2346, 5.6789, 4.5679 The minimum value is 1.2346 and maximum value is 5.6789 The average of these five values are: 3.4568

In: Computer Science

Write a brief explanation of why these commands function as described. 8. Why does `find ....

Write a brief explanation of why these commands function as described.

8. Why does `find . -name '*.pdf'` not find "BOOK.PDF" even if that file is in the current working directory?

9. Why does `find . -name 'pdf*'` not find "book.pdf" even if that file is in the current working directory?

10. Why does `find /etc -iname '*conf*'` return both directories and files?

In: Computer Science

My question is on this program I have difficulty i marked by ??? public class SortedSet...

My question is on this program I have difficulty i marked by ???

public class SortedSet { private Player[] players; private int count;

public SortedSet() { this.players = new Player[10]; }

/** * Adds the given player to the set in sorted order. Does not add

* the player if the case-insensitive name already exists in the set.

* Calls growArray() if the addition of the player will exceed the size

* of the current array. Uses an insertion sort algorithm to place the

* new player in the correct position in the set, taking advantage of

* the private swapPlayers method in this class.

* * @param player the player to add

* @return the index where the player was added, or -1 if not added

*/

public int add(Player player) {

My question is how to add sorted order with the player in the case-insensitive

????????????????????????????????????????????????????? and

return -1;

}

/**

* @param name the name of the player to remove

* @return true if removed, false if not found

*/

public boolean remove(String name) {

??????????????????????????????????????????????????????????????????????

How to removes the player with the given case-insensitive name from the set. return true;

}

/**

* @param name the player's name

* @return the index where the player is stored, or -1 if not found

*/

public int find(String name) {

?????????????????????????????????????????????????????????

How to Locates the player with the given case-insensitive name in the set. return 0;

}

/**

* @param index the index from which to retrieve the player

* @return the player object, or null if index is out of bounds.

*/

public Player get(int index) {

?????????????????????????????????????????????????????????

How to returns the player object stored at the given index. return null;

}

/**

* Provides access to the number of players currently in the set.

* @return the number of players */ public int size() { return count;

}

/**

* Provides access to the current capacity of the underlying array.

* @return the capacity of the array

*/

public int capacity() { return players.length;

}

/** Provides a default string representation of th sorted set. Takes

* advantage of Player's toString method to provide a single line String.

* Example: [ (Player: joe, Score: 100) (Player: fred, Score: 98) ]

* @return the string representing the entire set

*/ @Override

public String toString() {

??????????????????????????????????????

How to provides a default string ?????????

return null;

}

/**

* @param i the first index

* @param j the second index

*/

private void swapPlayers(int i, int j) {

??????????????????????????????????????????????????????

How to private method used during sorting to swap players in the underlying array.

}

private void growArray() {

???????????????????????????????????????????????????????????

How to private method used to double the array if adding a new player will exceed the size of the current array.

}

}

//----------------------------------------------------------------------------------------------------------------------------// //

players Classes public class Player implements Comparable {

//

fields private String name; private int score;

/**

* Full constructor.

* @param name the player's name

* @param score the player's highest score

*/

public Player(String name, int score) {

this.name = name; this.score = score;

}

/**

* Provides access to the player's name.

* @return the player's name

*/

public String getName() {

return name;

}

/**

* Allows the player's name to be set.

* @param name the player's name

*/

public void setName(String name) {

this.name = name;

}

/**

* Provides access to the player's highest score.

* @return the player's highest score

*/

public int getScore() {

return score;

}

/**

* Allows the player's highest score to be set.

* @param score the player's highest score

*/

public void setScore(int score) {

this.score = score;

}

/**

* Provides a default string representation of an object of this class.

* @return */ @Override public String toString() {

return "Player: " + name + ", Score: " + score;

}

/** * Provides a unique hash code for this object,

* based on the case-insensitive player name.

* @return the hash code

*/

@Override public int hashCode() {

int hash = 3;

hash = 83 * hash + Objects.hashCode(this.name.toLowerCase());

return hash;

}

/** * Reports if the given object is equal to this object,

* based on the case-insensitive player name.

* * @param obj the object to compare to this one

* @return true if the names are the same, false if not.

*/ @Override

public boolean equals(Object obj) {

if (this == obj) {

return true;

}

if (obj == null) {

return false;

}

if (getClass() != obj.getClass()) {

return false;

}

final Player other = (Player) obj;

return this.name.equalsIgnoreCase(other.name);

}

/** * Compares the given object with this one to determine sort order.

* * @param other the other object to compare to this one

* @return a negative value if this object should come before the other one,

* a positive value if it should come after, or zero if they are the same

*/ @Override public int compareTo(Player other) { return other.score - this.score; } }

//----------------------------------------------------------------------------------------------------------------------------//

// Main class

public class Lab1 {

/** * All tests performed here in main method.

* * @param args the command line arguments

*/

public static void main(String[] args) {

SortedSet set = new SortedSet();

//test insertion for (int i = 0; i < 10; i++) {

if (set.add(new Player(String.valueOf((char) (i + 97)), i + 10)) != 0) {

System.out.println("INSERTION FAIL"); return; }

}

System.out.println("INSERTION PASS");

//test growing array

if (set.add(new Player("k", 9)) != 10) {

System.out.println("GROW FAIL"); return;

}

System.out.println("GROW PASS");

//test duplicate

if (set.add(new Player("D", 5)) != -1) {

System.out.println("DUPLICATE FAIL");

return;

}

System.out.println("DUPLICATE PASS");

//test valid remove

if (!set.remove("c")) {

System.out.println("VALID REMOVE FAIL");

return;

}

System.out.println("VALID REMOVE PASS");

//test invalid remove if (set.remove("z")) {

System.out.println("INVALID REMOVE FAIL");

return;

}

System.out.println("INVALID REMOVE PASS");

//test valid find

if (set.find("g") != 3) {

System.out.println("VALID FIND FAIL");

return;

}

System.out.println("VALID FIND PASS");

//test invalid find

if (set.find("z") != -1) {

System.out.println("INVALID FIND FAIL");

return;

}

System.out.println("INVALID FIND PASS");

//test valid get

if (set.get(0).getScore() != 19) {

System.out.println("VALID GET FAIL");

return;

}

System.out.println("VALID GET PASS");

//test invalid

get if (set.get(100) != null) {

System.out.println("INVALID GET FAIL");

return;

}

System.out.println("INVALID GET PASS");

//test toString method try { String str = set.toString();

if (str.equals("[ (Player: j, Score: 19) (Player: i, Score: 18) " + "(Player: h, Score: 17) (Player: g, Score: 16) " + "(Player: f, Score: 15) (Player: e, Score: 14) " + "(Player: d, Score: 13) (Player: b, Score: 11) " + "(Player: a, Score: 10) (Player: k, Score: 9) ]")) { System.out.println("TOSTRING PASS"); } else { System.out.println("TOSTRING FAIL"); } } catch (Exception e) { System.out.println("TOSTRING FAIL"); } //test proper capacity of array if (set.capacity() != 20) { System.out.println("SIMPLE CAPACITY FAIL"); return; } System.out.println("SIMPLE CAPACITY PASS"); for (int i = 0; i < 100; i++) { set.add(new Player((String.valueOf((char) (i + 97))) + i, i)); } if (set.capacity() != 160) { System.out.println("COMPLEX CAPACITY FAIL"); return; } System.out.println("COMPLEX CAPACITY PASS"); } }

In: Computer Science

Design and implement the class Day that implements the day of the week in a program....

Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:

  1. Set the day.
  2. Print the day.
  3. Return the day.
  4. Return the next day.
  5. Return the previous day.
  6. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
  7. Add the appropriate constructors.
  8. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G.
  9. Write a program to test various operations on the class Day.

In: Computer Science

Background: introduction to "Wrapper" classes, this is a tool or concept provided in the Java Programming...

Background: introduction to "Wrapper" classes, this is a tool or concept provided in the Java Programming Language that gives us a way to utilize native datatypes as Objects with attributes and methods. A Wrapper class in Java is the type of class which contains or the primitive data types. When a wrapper class is created a new field is created and in that field, we store the primitive data types. It also provides the mechanism to covert primitive into object and object into primitive.Working with collections, we use generally generic ArrayList<Integer> instead of this ArrayList<int>. An integer is wrapper class of int primitive type. We use a Java wrapper class because for generics we need objects, not the primitives."

Problem: Create a Word Counter application, submit WordCounter.java.

Word Counter takes input of a text file name (have a sample file in the same directory as your Word Counter application to we don't have to fully path the file). The output of our Word Counter application is to echo the file name and the number of words contained within the file.

Sample File: Hello.txt:

hello

hello

hello

hello

hello

hello

hello

hello

hello

hello

In: Computer Science

Using this code snippet: Answer the following questions <div id=”mainContent”>      <p>I’m a cool paragraph <span>...

Using this code snippet: Answer the following questions

<div id=”mainContent”>

     <p>I’m a cool paragraph

<span>

    that has some

                  <span class=”coolClass”>yellow</span>

                  text

            </span>

     </p>

     <p class=”blue”>

            I’m just some blue text

      </p>

      <p class=”coolClass”> I should be un-touched text </p>

</div>

<div id=”footer”>

     <p class=”tagLine”>Copyright &copy; 2014</p>

</div>

1. Write the CSS rule (selector/declaration) to change all elements with a class of ‘blue’ to have blue foreground text. Hint: color

2. Write the CSS rule to change just the span with a class of “coolClass” to have a text color of yellow.

3. Write the CSS rule to change the element with and id of ‘footer’ to have a font size of 12px. Hint: font-size

4. Write the CSS needed to make all paragraphs in the document have a font weight of bold. Hint: font-weight

In: Computer Science

Below are the parallel arrays that track a different attribute of the apples (note that the...

Below are the parallel arrays that track a different attribute of the apples (note that the above chart (Sweet-Tart Chart) doesn't align with the data from the previous lesson):

 
 

names = ["McIntosh", "Red Delicious", "Fuji", "Gala", "Ambrosia", "Honeycrisp", "Granny Smith"]

 

sweetness = [3, 5, 8, 6, 7, 7.5, 1]

 

tartness = [7, 1, 3, 1, 1, 8, 10]

Step 1: Data Model (parallel arrays to dictionary)

Build a dictionary named apples. The apple dictionary keys will be the names of the apples. The values will be another dictionary. This value dictionary will have two keys: "sweetness" and "tartness". The values for those keys will be the respective values from the sweetness and tartness lists given above. You will build this by defining a variable named apples (see the complex_map example).

This is why dicitionarries are also calleed associative arrays. The arrays need to be kept in order so they can associate the same index with the same corrresoponding value that make holding this kind of data easier.

Step 2: Apple Aid

Now that we have our model, create a function named by_sweetness whose parameter will be a tuple (from apples.items()) The function by_sweetness will return the sweetness value of the incoming tuple. This helper function cannot reference the global variable apples (from step 1).

Create another function by_tartness that is essentially the same as by_sweetness but returns the tartness value of the incoming tuple.

Step 3: Apple Sorting

Write a function called apple_sorting that has two parameters: data (the data model dictionary) and sort_helper (the function used to sort the model). The apple_sorting should use the sorted function to sort the data (e.g. data.items()) with sort_helper. The function returns a list of tuples in order of their sweetness (sweetest apples listed first).

Once done, this should work:

 
 

print(apple_sorting(apples, by_sweetness))

In: Computer Science