Questions
** in C language please Write a function that remove a substring of str beginning at...

** in C language please

Write a function that remove a substring of str beginning at index idx and length len.
// param str: the string being altered
// param idx: the starting index of the removed chunk
// param len: the number of characters to remove (length of sub>
// removed) assumptions:
// 0 <= idx
// str is a valid string that terminates properly
//


// TODO: complete the function
void remove_substr(char str[], int idx, int len) {

In: Computer Science

(C++) Behavior: Returns true is there exists a sequence of 3 *consecutive* values in the array...

(C++)
Behavior: Returns true is there exists a sequence of 3 *consecutive* values in the array such that the sum of the first two elements is equal to the third element in that sequence, false otherwise. The third element has to be within a distance of dist from the second element. False otherwise.

Example: For the array {3,4,1,3,17,3,96,21,5,20}, if dist is 7 the function returns true because 4+1=5 and the element 5 is within 7 spots from element 1.

bool exists_trio_within_distance(int*, int, int);
int main()
{
   const int asize=10;
   int a[asize]={3,4,1,3,17,3,20,21,5,20};

   const int bsize=6;
   int b[bsize]={3,4,1,3,3,7};
   //////////////////////////////////////////

//test exists_trio function
  

   //should print "A trio exists."


   if (exists_trio(a,asize))
       cout << "A trio exists.\n";
   else
       cout << "A trio does not exist.\n";

   //should print "A trio does not exist."
   if (exists_trio(b,bsize))
       cout << "A trio exists.\n";
   else
       cout << "A trio does not exist.\n";

   cout << "=========================\n";

   //////////////////////////////////////////////

//test exists_trio_within_distance function

   //if you only want to test exists_trio, comment
   //out the below code

   //change the array a to help test Function 2
   a[6]=209; //change a[6] from 20 to 209
   int dist=7;
   //should print "A trio exists within distance 7."
   if (exists_trio_within_distance(a,asize,dist))
       cout << "A trio exists within distance " << dist << "." << endl;
   else
       cout << "A trio does not exist within distance " << dist << "." << endl;

   dist=2;
   //should print "A trio does not exist within distance 2."
   if (exists_trio_within_distance(b,bsize,dist))
       cout << "A trio exists within distance " << dist << "." << endl;
   else
       cout << "A trio does not exist within distance " << dist << "." << endl;
}

In: Computer Science

Java (a) Create a class Router which stores the information of a router. It includes the...

Java

(a) Create a class Router which stores the information of a router. It includes the brand, the model number (String) and the price (double, in dollars). Write a constructor of the class to so that the information mentioned is initialized when a Router object is created. Also write the getter methods for those variables. Finally add a method toString() to return the router information in the following string form.

 "brand: Linksys, model number: RVS4000, price: 1080.0"

Copy the content of the class as the answers to this part.

  1. (b) Create a class ComputerShop which stores the router information in a map routerMap, whose key is the concatenation of the brand and model number, separated by ": " (a colon and a space). Write a method addRouter(Router oneRouter) which adds oneRouter to routerMap. Copy the content of the class, which any include import statement(s) required, as the answers to this part.

  2. (c) Create a class TestComputerShop with a main() method which creates a ComputerShop object aShop and add the first router with brand "Linksys", model number "RVS4000" and price 1080. Add the second router with brand "Planet", model number "VRT-311S" and price 510. Copy the content of the class as the answers to this part.

  3. (d) Write a method showRouter() of ComputerShop which loops through the keys of routerMap using the enhanced for-loop and directly prints each router object stored using System.out.println(). (Loop through the values is simpler but using the keys is required in this part.) This should show suitable information since the method toString() has been written in (a). Add a statement in TestComputerShop to display all the router information of aShop. Copy the content of the method, line(s) added and execution output as the answers to this part.

  4. (e) Write a method modelNumberSet() of ComputerShop which returns model numbers of the routers in a set. You should loop through the values of routerMap using the enhanced for-loop and collect the model numbers. Add a statement in TestComputerShop to display the set using System.out.println(). Copy the content of the method, line(s) added and new execution output as the answers to this part.

  5. (f) Write a method priceList() of ComputerShop which returns the prices of the routers in a list. You should loop through the values of routerMap using the enhanced for-loop and collect the prices of the routers. Add a statement in TestComputerShop to display the list using System.out.println(). Copy the content of the method, line(s) added and new execution output as the answers to this part.

In: Computer Science

Please make a C program named: rotate.c This code will contain a single function (and the...

Please make a C program named:

rotate.c

This code will contain a single function (and the include directive to your header file) to perform the rotation operation using the two integer operands passed to this function. The first integer operand is the number to be rotated. The second integer operand is the number of bit positions that the first operand must be rotated by.

EXAMPLE:

Enter a 32-bit number (>= 1 and <= 4294967295, inclusively): 1

Enter the number of positions to rotate-right the input (between 0 and 31, inclusively): 1

1 rotated by 1 position gives: 2147483648

In: Computer Science

Write a class named TestScores. The class constructor should accept an array of test scores as...

Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program.

Use TestScoresDemo.java to test your code

public class TestScoresDemo

{

public static void main(String[] args)

{

// An array with test scores.

// Notice that element 3 contains an invalid score.

double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0 };

// Another array with test scores.

// All of these scores are good.

double[] goodScores = {97.5, 66.7, 88.0, 100.0, 99.0 };

// Create a TestScores object initialized with badScores.

try

{

TestScores tBad = new TestScores(badScores);

// The following statement should not execute.

System.out.println("The average of the bad scores is " +

tBad.getAverage());

}

catch (IllegalArgumentException e)

{

System.out.println("Invalid score found.\n" + e.getMessage());

}

// Create a TestScores object initialized with goodScores.

try

{

TestScores tGood = new TestScores(goodScores);

System.out.println("The average of the good scores is " +

tGood.getAverage());

}

catch (IllegalArgumentException e)

{

System.out.println("Invalid score found.\n" + e.getMessage());

}

}

}

In: Computer Science

Using Matlab Write a program that print the following matrix. (hint: use nested for-loop and if-statement)...

Using Matlab

Write a program that print the following matrix. (hint: use nested for-loop and if-statement)

mat =

[2 -1 0 0 0

-1 2 -1 0 0

0 0 -1 2 -1

0 0 0 -1 2];

In: Computer Science

Implement the following method take takes the name of an ASCII text file and displays the...

Implement the following method take takes the name of an ASCII text file and displays the frequency of each character in the file. (6 pts)

public static void CountCharacters(String filename)

{

...

}

// Main provided for testing

public static void main(String args[])

{

CountCharacters("testfile.dat");

}

Output should be in the following format:

ASCII CODE - COUNTS

10 - 1

66 - 2

104 - 1

In: Computer Science

class Counter{   private int count = 0;   public void inc(){    count++;     }   public int get(){     return...

class Counter{

  private int count = 0;

  public void inc(){

   count++;  

  }

  public int get(){

    return count;

  }

}

class Worker extends Thread{

Counter count;

  Worker(Counter count){

    this.count = count;

  }

  public void run(){

    for (int i = 0; i < 1000;i++){

      synchronized(this){

        count.inc();

      }}

  }

}

public class Test

{  

  public static void main(String args[]) throws InterruptedException

  {

    Counter c = new Counter();

    Worker w1 = new Worker(c);

    Worker w2 = new Worker(c);

    w1.start();

    w2.start();

    w1.join();

    w2.join();

    System.out.println(c.get());

     

  }

}

The above code should print 2000 because inc() method is synchronized. However, it is printing a different number ranging from 1000 to 2000 everytime it runs. Can you explain why? How would you fix it?

In: Computer Science

2. Resourcing profiling is the first step of the risk management life cycle. Describe what is...

2. Resourcing profiling is the first step of the risk management life cycle. Describe what is involved with this step, what challenges are involved with resource profiling. Use examples from the real world for your analysis. Your answer must be two pages in length.

In: Computer Science

Q1. Formulate the logical constraints for the following statements (where A, B, C, and D are...

Q1. Formulate the logical constraints for the following statements (where A, B, C, and D are all binary variables):

a. If A happens then B or C happens.

b. If A and B happen then C and D must happen.

c. If A happens or B does not happen then C or D must happen.

d. If A happens or B happens then C and D happen.

This has previously been posted before on Chegg but there are conflicting answers and comments to the questions/responses.

In: Computer Science

PYTHON: Implement the following algorithm to construct magic n × n squares; it works only if...

PYTHON: Implement the following algorithm to construct magic n × n squares; it works only if n is odd.

row ← n - 1

column ← n/2

for k = 1 . . . n2 do

Place k at [row][column]

Increment row and column

if the row or column is n then

replace it with 0

end if

if the element at [row][column] has already been filled then

Set row and column to their previous values

Decrement row end if end for

Here is the 5 × 5 square that you get if you follow this algorithm:

11 18 25 2 9

10 12 19 21 3

4 6 13 20 22

23 5 7 14 16

17 24 1 8 15

Write a program whose input is the number n and whose output is the magic square of order n if n is odd.

Please solve in Python

In: Computer Science

In Python, write a function called user_name that takes two arguments, first_name and last_name and creates...

In Python, write a function called user_name that takes two arguments, first_name and last_name and creates a “user name” consisting of the first three letters of the first name concatenated with the first three letters of the last name.   You can assume ach name is at least three letters long.

Return the new user name.   

your results should yield something like these test cases.

>>> print(user_name("bob", "taft"))

bobtaf

>>>

>>> print(user_name("Ralph", "Waldo"))

RalWal

>>>

In: Computer Science

Write a c++ program that randomly generates 100 dates, store them into four vectors of date...

Write a c++ program that randomly generates 100 dates, store them into four vectors of date objects according to their seasons.. The dates generated must be within 1000 days after 1/1/2000.

In: Computer Science

What would the code look like if you weren't using hash maps and array lists (only...

What would the code look like if you weren't using hash maps and array lists (only using scanner import) and solving using a partition algorithm?

In: Computer Science

a file named maintence08-01.txt is included with your downloadable student files. Assume that this program is...

a file named maintence08-01.txt is included with your downloadable student files. Assume that this program is a working program in your organization and that it needs modifications that are described in the comments(lines that begin with two slashes) at the beginning of the file. Your job is to alter the program to meet the new specifications.


Here is the file Maintence08-01.txt

// This application reads sales data for a real estate broker.
// The user enters a record for each of 10 salespeople
// containing the salesperson's name,
// the number of properties sold by that person during the month,
// and the total value of those properties.
// The data records are sorted by value so the data for
// the top three salespeople can be displayed.
// Modify the program to
// (1) enter data for any number of salespeople up to 60
// (2) allow the user to choose whether to see
// (a) the data for the top three salespeople
// (or fewer if 3 are not entered) by value
// (b) the data for the top three salespeople
// (or fewer if 3 are not entered) by
// number of properties sold

start
Declarations
num SIZE = 10
string names[SIZE]
num properties[SIZE]
num values[SIZE]
num count
num NUM_TO_DISPLAY = 3
num comps
num x
num y
num tempProp
num tempVal
string tempName
getReady()
display()
finish()
stop

getReady()
count = 0
while count < SIZE
output "Enter salesperson name "
input names[count]
output "Enter number of properties sold "
input properties[count]
output "Enter total value of those properties "
input values[count]
count = count + 1
endwhile
return

display()
sort()
count = 0
while count < NUM_TO_DISPLAY
output names[count], properties[count], values[count]
count = count + 1
endwhile
return


finish()
output "End of display"
return

sort()
comps = SIZE - 1
while y < comps
x = 0
while x < comps
if values[x] < values[x + 1] then
swap()
endif
x = x + 1
endwhile
y = y + 1
endwhile
return

void swap()
tempName = names[x + 1]
names[x + 1] = names[x]
names[x] = tempName
tempProp = properties[x + 1]
properties[x + 1] = properties[x]
properties[x] = tempProp
tempVal = values[x + 1]
values[x + 1] = values[x]
values[x] = tempVal
return

In: Computer Science