Questions
The source code I have is what i'm trying to fix for the assignment at the...

The source code I have is what i'm trying to fix for the assignment at the bottom.

Source Code:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

const int NUM_ROWS = 10;
const int NUM_COLS = 10;

// Setting values in a 10 by 10 array of random integers (1 - 100)
// Pre: twoDArray has been declared with row and column size of NUM_COLS
// Must have constant integer NUM_COLS declared
// rowSize must be less than or equal to NUM_COLS
// Post: All twoDArray values set to integers 1 - 100
void InitArray(/* OUT */ int twoDArray[][NUM_COLS], /* IN */ int rowSize);

// Display the array
// Pre: twoDArray contains integers with row and column size of NUM_COLS
// Must have constant integer NUM_COLS declared
// rowSize must be less than or equal to NUM_COLS
// Post: Display all values in array in pretty format
void PrintArray(/* IN */ const int twoDArray[][NUM_COLS], /* IN */ int rowSize);

// Accepts an integer as a parameter and returns its first location in the array
// Pre: twoDArray contains integers with row and column size of NUM_COLS
// Must have constant integer NUM_COLS declared
// rowSize must be less than or equal to NUM_COLS
// numGuessed contains valid integer
// Post: Return true if numGuessed is in array as well as set rowLoc and colLoc coordinates
// Return false if numGuessed not found and set rowLoc and colLoc to -1
bool FindNumber(/* IN */ const int twoDArray[][NUM_COLS], /* IN */ int rowSize,
/* IN */ int numGuessed, /* OUT */ int &rowLoc, /* OUT */ int &colLoc);

//Setting values in a 10 by 10 array of random integers (1 - 100)
// Pre: twoDArray has been declared with row and column size of NUM_COLS
// Must have constant integer NUM_COLS declared
// rowSize must be less than or equal to NUM_COLS
// Post: All twoDArray values set to integers 1 - 100
void InitArray(/* OUT */ int twoDArray[][NUM_COLS], /* IN */ int rowSize)
{
cout << "init\n";
// Loop through each row
for (int row = 0; row < rowSize; row++)
{
// Loop through each column
for (int col = 0; col < rowSize; col++)
{
// printing values from array
twoDArray[row][col] = rand() % 100 + 1;
cout << twoDArray[row][col] << ' ';
}
cout<<endl;
}
}

void PrintArray(/* OUT */ const int twoDArray[][NUM_COLS], /* IN */ int rowSize)
{
cout << "print\n";
// Loop through each row
for (int row = 0; row < rowSize; row++)
{
// Loop through each column
for (int col = 0; col < rowSize; col++)
{
// Printing values from array
cout << setw(4) << twoDArray[row][col] << ' ';
}
cout << endl;
}
}

// Accepts an integer as a parameter and returns its first location in the array
// Pre: twoDArray contains integers with row and column size of NUM_COLS
// Must have constant integer NUM_COLS declared
// rowSize must be less than or equal to NUM_COLS
// numGuessed contains valid integer
// Post: Return true if numGuessed is in array as well as set rowLoc and colLoc coordinates
// Return false if numGuessed not found and set rowLoc and colLoc to -1
bool FindNumber(/* IN */ const int twoDArray[][NUM_COLS], /* IN */ int rowSize,
/* IN */ int numGuessed, /* OUT */ int &rowLoc, /* OUT */ int &colLoc)
{
// Loop to iterate over rows
for(int i=0;i<rowSize;i++)
{
// Loop to iterate over rows
for(int j=0;j<rowSize;j++)
{
// If element at row i and column j is equal to numGuessed
if(twoDArray[i][j]==numGuessed)
{
// Assigning the row and column values of the numGuessed to rowLoc and colLoc
rowLoc = i;
colLoc = j;
// Returning true
return true;
}
}
}
// If the whole array is traversed and numGuessed is not found, false is returned
return false;
}

int main()
{
// Defining an 2D Array of size NUM_ROWS x NUM_COLS
int twoDArray[NUM_ROWS][NUM_COLS];
// Initialising the array
InitArray(twoDArray, NUM_ROWS);
// This variable is used to keep track of whether the number is found or not
bool found;
// Start of do while loop
do
{
// Defining the variable to store the number entered by the user
int guessNum;
// Prompting the user to enter the guessed number
cout << "Guess a number:";
// Reading the number
cin >> guessNum;
// Creating two variables to store the row and column indexes of guessNum in twoDArray
int rolLoc = -1;
int colLoc = -1;
// Calling the function FindNumber and storing the result in the variable found
found = FindNumber(twoDArray, NUM_COLS, guessNum, rolLoc, colLoc);
// If guessNum is found in twoDarray
if(found)
{
// Print the row and column indexes
cout <<rolLoc << " " << colLoc << endl;
}
// Else
else
{
// Print a message to user stating that the guessNum is not found in the twoDArray
cout << guessNum << " is not one of the numbers!" << endl;
}
// End of do while loop
} while(!found);
// Printing the array
PrintArray(twoDArray, NUM_COLS);
return 0;
}

Assignment details:

  • Change the logic so that after user has chosen a number, and the program has verified that it's in the array, the program goes into a loop and lets the user guess the number's coordinates, returning a message stating higher or lower for the x and y coordinates, until they guess the number's location. A program run might look something like
Pick a number between 1 and 100: 75
Number not found!
Pick a number between 1 and 100: 45
Guess location (x y): 5 5
x is correct! and y too high!
Guess location (x y): 5 4
x is correct! and y too high!
Guess location (x y): 5 3
x is correct! and y too high!
Guess location (x y): 5 2
x is correct! and y too high!
Guess location (x y): 5 1
Found!

Submit: Documented source code in a zip file

In: Computer Science

Java Implementation It uses adjacency list representation, and already has the loadAdjList() function implemented for reading...

Java Implementation

It uses adjacency list representation, and already has the loadAdjList() function implemented for reading adjacency lists from standard input (make sure you understand the input format and how loadAdjList() works). You need to complete the function printAdjMatrix().

import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;
class Graph {
private int totalVertex;
private LinkedList<LinkedList<Integer>> adjList;
//adjacency list of edges
public Graph() { totalVertex = 0; }
public void loadAdjList() {
Scanner in = new Scanner(System.in);
totalVertex = in.nextInt();
adjList = new LinkedList<LinkedList<Integer>>();
for(int i = 0; i < totalVertex; i ++) {
LinkedList<Integer> tmp = new LinkedList<Integer>();
int idx1 = in.nextInt() - 1;
int degree = in.nextInt();
//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
for(int j = 0; j < degree; j ++) {
int idx2 = in.nextInt() - 1;
tmp.add(idx2);
}
adjList.add(tmp);
}
in.close();
}
public void printAdjMatrix() {
Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
//complete the following
}
}
//change class name GraphRepresentation to Main() for submission to AIZU
public class GraphRepresentation {
public static void main(String argv[]) {
Graph g = new Graph();
g.loadAdjList();
g.printAdjMatrix();
}
}

In: Computer Science

Discuss the potential advantages and disadvantages of “Fair-Share Scheduling”.

Discuss the potential advantages and disadvantages of “Fair-Share Scheduling”.

In: Computer Science

Write a program that processes numbers, corresponding to student records read in from a file, and...

Write a program that processes numbers, corresponding to student records read in from a file, and writes the required results to an output file (see main ( )). Your program should define the following functions:

double read_double (FILE *infile) — Reads one double precision number from the input file. Note: You may assume that the file only contains real numbers.

int read_integer (FILE *infile) - Reads one integer number from the input file.

double calculate_sum (double number1, double number2, double number3, double number4, double number5) - Finds the sum of number1, number2, number3, number4, and number5 and returns the result.

double calculate_mean (double sum, int number) - Determines the mean through the calculation sum / number and returns the result. You need to check to make sure that number is not 0. If it is 0 the function returns -1.0 (we will assume that we are calculating the mean of positive numbers), otherwise it returns the mean.

double calculate_deviation (double number, double mean) - Determines the deviation of number from the mean and returns the result. The deviation may be calculated as number - mean.

double calculate_variance (double deviation1, double deviation2, double deviation3, double deviation4, double deviation5, int number) - Determines the variance through the calculation:

             ((deviation1)^2 + (deviation2)^2 + (deviation3)^2 + (deviation4)^2 + (deviation5)^2) / number

and returns the result. Hint: you may call your calculate_mean ( ) function to determine the result!

double calculate_standard_deviation (double variance) - Calculates the standard deviation as sqrt (variance) and returns the result. Recall that you may use the sqrt ( ) function that is found in math.h.

double find_max (double number1, double number2, double number3, double number4, double number5) — Determines the maximum number out of the five input parameters passed into the function, returning the max.

double find_min (double number1, double number2, double number3, double number4, double number5) — Determines the minimum number out of the five input parameters passed into the function, returning the min.

void print_double (FILE *outfile, double number) — Prints a double precision number (to the hundredths place) to an output file.

A main ( ) function that does the following (this is what the program does!!!):

Opens an input file "input.dat" for reading;

Opens an output file "output.dat" for writing;

Reads five records from the input file (input.dat); You will need to use a combination of read_double ( ) and read_integer ( ) function calls here!

Calculates the sum of the GPAs;

Calculates the sum of the class standings;

Calculates the sum of the ages;

Calculates the mean of the GPAs, writing the result to the output file (output.dat);

Calculates the mean of the class standings, writing the result to the output file (output.dat);

Calculates the mean of the ages, writing the result to the output file (output.dat);

Calculates the deviation of each GPA from the mean (Hint: need to call calculate_deviation ( ) 5 times)

Calculates the variance of the GPAs

Calculates the standard deviation of the GPAs, writing the result to the output file (output.dat);

Determines the min of the GPAs, writing the result to the output file (output.dat);

Determines the max of the GPAs, writing the result to the output file (output.dat);

Closes the input and output files (i.e. input.dat and output.dat)

Expected Input File Format (real numbers only):

For this assignment you will be required to read five records from the "input.dat" file. Each record will have the following form:

    Student ID# (an 8 digit integer number)

    GPA (a floating-point value to the hundredths place)

    Class Standing (1 - 4, where 1 is a freshmen, 2 is a sophomore, 3 is a junior, and 4 is a senior --> all integers)

    Age (a floating-point value)

Example data for 1 student record in the file could be as follows:

    12345678

    3.78

    3

    20.5

IV. Expected Results:

The following sample session demonstrates how your program should work.

Assuming input.dat stores the following records:

    12345678

    3.78

    3

    20.5

  

87654321

    2.65

    2

    19.25

   

08651234

    3.10

    1

    18.0

   

   

11112222

    3.95

    4

    22.5

   

22223234

    2.45

    3

    19.3333

Your program should write the following to output.dat: NOTE: you only need to output the numbers, the text is for demonstration purposes only.

        3.19     -- GPA Mean

        2.60     -- Class Standing Mean

        19.92   -- Age Mean

        0.60     -- GPA Standard Deviation

        2.45     -- GPA Min

        3.95     -- GPA Max

In: Computer Science

this is a test program foo that has a bug. Assume your machine has 4KB pages....

this is a test program foo that has a bug. Assume your machine has 4KB pages. Note that this code is runnable on a Linux machine.

#include <stdlib.h>

#include <stdio.h>

#include <sys/mman.h>

struct foo {

    int a; // 4-byte int

    int b; // 4-byte int

};

int main (int argc, char * argv[]) {

    int num = atoi(argv[1]); // convert program arg to integer

    struct foo * a = mmap(NULL,

                          sizeof(struct foo) * num,

                          PROT_READ | PROT_WRITE,

                          MAP_ANONYMOUS | MAP_PRIVATE,

                          -1,

                          0);

    a[num].a = 100;

    printf("Succeed\n");

}

  1. What is the bug?
  2. Explain (in detail) why when I run foo with different arguments as below I get different results:

[me@machine] ./foo 512

bash: “./test 512” terminated by signal SIGSEGV

[me@machine] ./foo 256

Succeed

In: Computer Science

1. Explain the common security threat concept in the cloud. [Hint : chapter 9] Cloud Computing,...

1. Explain the common security threat concept in the cloud.

[Hint : chapter 9] Cloud Computing, Kris Jamsa, 2013, Johns & Bartlett Learning, ISBN: 978-1- 4496-4739-1

In: Computer Science

how to find all the neighbors in a n-dimensional array in python? thank you in advance...

how to find all the neighbors in a n-dimensional array in python?
thank you in advance

all the neighboors of a coordinate*

In: Computer Science

array • First, create a function called addNumber, which has a formal parameter for an array...

array
• First, create a function called addNumber, which has a formal parameter for an array of integers and increase the value of each array element by a random integer number between 1 to 10.
o Add any other formal parameters that are needed.
• Second, create another function called printReverse that prints this array in reverse order.
• Then, you need to write a C++ program to test the use of these two functions.

In: Computer Science

Please based on my python code. do the following steps: thank you Develop a method build_bst...

Please based on my python code. do the following steps:

thank you

  1. Develop a method build_bst which takes a list of data (example: [6, 2, 4, 22, 34, 9, 6, 67, 42, 55, 70, 120, 99, 200]) and builds a binary search tree full of Node objects appropriately arranged.
  2. Test your build_bst with different sets of inputs similar to the example provided above. Show 3 different examples.
  3. Choose 1 example data.  Develop a function to remove a node from a bst data structure.  This function should consider all the three cases:  case-1: remove a leaf node, case-2: remove a node with one child and case-3: remove a node with two children. Show an example.

Perform tree balancing after node deletion if necessary.You can choose AVL tree or Red Black tree implementation.

Perform the time complexity for this function.Briefly explain?

  1. Write a function which takes two bst and merges the two trees.  The function should return the merged tree.  Show an example.

Perform tree balancing after merge a tree if necessary.You can choose AVL tree or Red Black tree implementation.

Perform the time complexity for this function.

Here is my python code:

from queue import Queue

class Node:

def __init__(self, data):

self.parent = None

self.left = None

self.right = None

if isinstance(data, list):

self.build_tree(data)

return

self.value = data

def build_tree(self, L):

q = Queue()

q.put(self)

self.value = L[0]

for i in range(1, len(L), 2):

node = q.get()

node.left = Node(L[i])

node.left.parent = node

q.put(node.left)

if i+1 == len(L):

return

node.right = Node(L[i+1])

node.right.parent = node

q.put(node.right)

def min(self):

if self.left is None or self.right is None:

if self.left is not None:

return min(self.value, self.left.min())

if self.right is not None:

return min(self.value, self.right.min())

return self.value

return min(self.value, self.left.min(), self.right.min())

def max(self):

if self.left is None or self.right is None:

if self.left is not None:

return max(self.value, self.left.max())

if self.right is not None:

return max(self.value, self.right.max())

return self.value

return max(self.value, self.left.max(), self.right.max())

def preorder(self):

if self.value is None:

return

print(self.value, end=' ')

if self.left is not None:

self.left.preorder()

if self.right is not None:

self.right.preorder()

if __name__ == "__main__":

#L = [6, 2, 4, 22, 34, 9, 6, 67, 42, 55, 70, 120, 99, 200]

L = [int(x) for x in input().split()]

root = Node(L)

root.preorder()

print()

print(f"Minimum node in tree: {root.min()}")

print(f"Maximum node in tree: {root.max()}")

In: Computer Science

IN JAVA PLEASE, USE COMMENTS Following the example of Circle class, design a class named Rectangle...

IN JAVA PLEASE, USE COMMENTS

Following the example of Circle class, design a class named Rectangle to represent a rectangle. The class contains:

• Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height.

• A no-arg constructor that creates a default rectangle.

• A constructor that creates a rectangle with specified width and height

• A method name getWidth() return the value of width

• A method named getHeight() returns value of height

• A method named setWidth(double) set the width with given value

• A method named setHeight(double) set the height with given value

• A method named getArea() that returns the area of this rectangle

• A method getPerimeter() that returns the perimeter

Write a test program that creates two rectangle objects – one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area and perimeter of each rectangle in this order.

In: Computer Science

C++ program, FOR THE MAIN WHEN YOU DECLARE FUNCTION PLEASE PUT CORNER SIZES IN A TABLE...

C++ program, FOR THE MAIN WHEN YOU DECLARE FUNCTION PLEASE PUT CORNER SIZES IN A TABLE AND A LOOP SO YOU DON'T HAVE TO DECLARE FUNCTION MULTIPLE TIME

You may work in groups of two.

Your job is to write a function makeSpiral() that takes a two-dimensional array and the number of rows and columns to fill. The function will fill the rows-by-columns corner of the array with the integers from 1 to (rows * columns) in a counter-clockwise spiral pattern. The pattern starts at a[0][0] in the upper left, and goes down, then right, then up, then left filling the elements with values; and then moves in one row and column on each side, continuing until you run out of rows and columns. For example, with a 5 by 6 array and filling a 4 by 4 corner, the result will be something like this:

row/column 0 1 2 3 4 5 0 1 12 11 10 1 2 13 16 9 2 3 14 15 8 3 4 5 6 7 4 The top and left sides of this table just show the column and row numbers. The rest of the array (outside the corner passed into the makeSpiral() function) will be left unchanged by the function.

Next, write a function printSpiral() that takes an output file handle, a 2-d array and the number of rows and columns to print, and prints the spiral in the array in a reasonable format. Use setw() with the size (number of digits) of the value of ( rows * columns ) + 1 to set the size of each value to print. Do not skip lines, and do not print the row or column numbers, just the spiral. Print output directly to a text file.

Then write a program that declares a 15 by 20 array and opens a text file for output. The program will then loop, filling the array completely with zeroes (use a function for this task), calling makeSpiral() with the various values for the size of the corner to fill, and then calling printSpiral() to print the spiral. Run this loop to test all of the spiral corner sizes you need.

How can you pass in multiple corner sizes to the various functions without prompting for the values, reading them from a file, or using multiple separate function calls (e.g., outside a loop)? Solve this problem in this lab, too. It is not hard.

In a reduced size fixed-width font, this is what a 15x20 spiral looks like:

1 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
2 67 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 47
3 68 125 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 107 46
4 69 126 175 216 215 214 213 212 211 210 209 208 207 206 205 204 159 106 45
5 70 127 176 217 250 249 248 247 246 245 244 243 242 241 240 203 158 105 44
6 71 128 177 218 251 276 275 274 273 272 271 270 269 268 239 202 157 104 43
7 72 129 178 219 252 277 294 293 292 291 290 289 288 267 238 201 156 103 42
8 73 130 179 220 253 278 295 305 304 303 302 301 287 266 237 200 155 102 41
9 74 131 180 221 254 279 280 281 282 283 284 285 286 265 236 199 154 101 40
10 75 132 181 222 255 256 257 258 259 260 261 262 263 264 235 198 153 100 39
11 76 133 182 223 224 225 226 227 228 229 230 231 232 233 234 197 152 99 38
12 77 134 183 184 185 186 187 188 189 190 191 192 193 194 195 196 151 98 37
13 78 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 97 36
14 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 35
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

Send me tests with at least the following corner sizes, plus several more of your own choice: 1 by 1, 1 by 2, 2 by 1, 2 by 2, 3 by 3, 4 by 4, 5 by 5, 4 by 7, 7 by 4, 4 by 8, 6 by 4, 15 by 20 Designing this completely before trying to code any of it will save you several hours of effort. You may write little test programs (stubs) to test specific ideas before you complete the design.

In: Computer Science

Write a 5 to 7 page paper in which you create a disaster recovery plan for...

Write a 5 to 7 page paper in which you create a disaster recovery plan for a fictitious business with the following characteristics: is an urgent care clinic, contains 4 doctors 10 nurses and 2 nurse practitioners, are open 7 days a week 18 hours per day, and the primary service is to treat patients.

In: Computer Science

using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers....

using c++

10. Sorting Orders
Write a program that uses two identical arrays of eight integers. It should display the contents
of the first array, then call a function to sort it using an ascending order bubble sort, modified
to print out the array contents after each pass of the sort. Next the program should display the
contents of the second array, then call a function to sort it using an ascending order selection
sort, modified to print out the array contents after each pass of the sort.

test case:

Bubble Sort
The unsorted values are: 7 2 3 8 4 5 6 1 
 sort pass #1 : 2 7 3 8 4 5 6 1 
 sort pass #2 : 2 3 7 8 4 5 6 1 
 sort pass #3 : 2 3 7 4 8 5 6 1 
 sort pass #4 : 2 3 7 4 5 8 6 1 
 sort pass #5 : 2 3 7 4 5 6 8 1 
 sort pass #6 : 2 3 7 4 5 6 1 8 
 sort pass #7 : 2 3 4 7 5 6 1 8 
 sort pass #8 : 2 3 4 5 7 6 1 8 
 sort pass #9 : 2 3 4 5 6 7 1 8 
 sort pass #10 : 2 3 4 5 6 1 7 8 
 sort pass #11 : 2 3 4 5 1 6 7 8 
 sort pass #12 : 2 3 4 1 5 6 7 8 
 sort pass #13 : 2 3 1 4 5 6 7 8 
 sort pass #14 : 2 1 3 4 5 6 7 8 
 sort pass #15 : 1 2 3 4 5 6 7 8 

The sorted values are: 1 2 3 4 5 6 7 8 

Selection Sort
The unsorted values are: 7 2 3 8 4 5 6 1 
 sort pass #1 : 1 2 3 8 4 5 6 7 
 sort pass #2 : 1 2 3 8 4 5 6 7 
 sort pass #3 : 1 2 3 8 4 5 6 7 
 sort pass #4 : 1 2 3 4 8 5 6 7 
 sort pass #5 : 1 2 3 4 5 8 6 7 
 sort pass #6 : 1 2 3 4 5 6 8 7 
 sort pass #7 : 1 2 3 4 5 6 7 8 

The sorted values are: 1 2 3 4 5 6 7 8 

In: Computer Science

Explain the disaster recovery plan for AWS cloud. [Hint : chapter 10] Cloud Computing, Kris Jamsa,...

Explain the disaster recovery plan for AWS cloud.

[Hint : chapter 10] Cloud Computing, Kris Jamsa, 2013, Johns & Bartlett Learning, ISBN: 978-1- 4496-4739-1

In: Computer Science

USING JAVA: complete the method below in the BasicBioinformatics class. /** * Class BasicBioinformatics contains static...

USING JAVA: complete the method below in the BasicBioinformatics class.

/**
* Class BasicBioinformatics contains static methods for performing common DNA-based operations in
* bioinformatics.
*
*
*/
public class BasicBioinformatics {

/**
* Calculates and returns the number of times each type of nucleotide occurs in a DNA sequence.
*
* @param dna a char array representing a DNA sequence of arbitrary length, containing only the
* characters A, C, G and T
*
* @return an int array of length 4, where subscripts 0, 1, 2 and 3 contain the number of 'A',
* 'C', 'G' and 'T' characters (respectively) in the given sequence
*/
public static int[] nucleotideCounts(char[] dna) {
// INPUT CODE HERE
}

/**
* Calculates and returns the number of times each type of nucleotide occurs in a DNA sequence.
*
* @param dna a String representing a DNA sequence of arbitrary length, containing only the
* characters A, C, G and T
*
* @return an int array of length 4, where subscripts 0, 1, 2 and 3 contain the number of 'A',
* 'C', 'G' and 'T' characters (respectively) in the given sequence
*/
public static int[] nucleotideCounts(String dna) {
return nucleotideCounts(dna.toCharArray());
}

In: Computer Science