Find the Bug - Looking for at least 3 bugs! USE SOME METHOD TO SHOW ME YOUR "FIXED CODE" ( type it in Red or highlight in yellow or use // at the end of the line) Your downloadable files for Chapter 1 include DEBUG02-01 Each file starts with some comments ( lines that begin with two slashes ) that describe the program. Examine the pseudocode that follows the introductory comment, then find and correct all the bugs. Click here for Debug0201.docxPreview the document Complete your answer in Word, Save it, and upload it into the assignment.
Debug0201
// This pseudocode segment is intended to compute and display
// the average grade of three tests
start
Declarations
num test1
num test2
num test2
num average
output "Enter score for test 1 "
input test1
output "Enter score for test 2 "
input test2
output "Enter score for test 3 "
input test3
average = test1 + test2 + test3 / 3
output "Average is ", answer
end
In: Computer Science
In: Computer Science
Use the recursion tree method to determine the asymptoticupper bound of T(n).T(n) satisfies the recurrence T(n)=2T(n-1)+ c, where c is a positive constant, andT(0)=0.
In: Computer Science
Briefly summarize one additional article on Green IT in one to two paragraphs. (Make sure this is from a scholarly source, and not a website). Be sure to cite in APA.
In: Computer Science
Model a book Draw a class diagram representing a book defined by the following statement: “A book is composed of a number of parts, which in turn are composed of a number of chapters. Chapters are composed of sections.” First, focus only on classes and associations.
Add multiplicity to the class diagram you produced.
Refine the class diagram to include the following attributes:
• Book includes a publisher, publication date, and an ISBN
• Part includes a title and a number
• Chapter includes a title, a number, and an abstract
• Section includes a title and a number
Consider the refined class diagram. Note that the Part, Chapter, and Section classes all include a title and a number attribute. Use inheritance to factor out these two attributes .
In: Computer Science
We showed that since the problem concerning a machine halting on its own index is unsolvable, the general halting problem for Turing machines is unsolvable. Does this imply that any superset of an unsolvable problem is unsolvable? Provide a proof or a counterexample.
In: Computer Science
PLEASE PROVIDE COMMENTS TO BE ABLE TO UNDERSTAND CODE
C++
Inventory Class
Create an inventory class. The class will have the following data members,
const int size = 100;
int no_of_products; // the total number of products in the
inventory. char name_array[size][15] ; // stores name of
products
double array [size][2]; // In the first column quantity of the
product and in the second column the price per item of the product
is stored.
name_array stores the name of products, it is assumed that the length of the product name is at most 14 characters and each name is null terminated ( See Table 1. for an example )
For each product, the two-dimensional array will store two pieces of information, the current stock in number of pieces and the per unit price. We note that the information for a given product will be stored in the same row in the one-dimensional and two-dimensional arrays ( See Table 2. for an example).
The class should provide the following functions.
Constructor function: The function receives no parameters but initializes the elements of the double array to zero and the first element of each row of the char array to a null character.
int row_no( char *product name): Function receives the name of the product and returns the number of the row that contains the information for this product in the two-dimensional arrays. This function may be used by other functions when needed.
int get_stock ( char *product_name): Function receives the name of the product and returns the current amount of the product in the stock.
double order( char *product_name, int quantity): The function will check if the requested quantity of the stock is available. If the requested quantity is available drop from the stock and return the total cost of the order, otherwise order cannot be met and return zero.
bool new_product( char *product_name, int quantity, double price): If there is an empty entry available in the arrays, then, a new product is added to the inventory. The new product should be added to the first available entries in the two-dimensional arrays. After that the function increases the number of different products in the inventory by one and returns true. If no space is available in the arrays, then, product can not be added to the inventory and the function returns false.
void discontinued_product( char *product_name); // If a product is discontinued, the function should set the entry of this item in the two- dimensional array zero and the first element of the row for this product in the two-dimensional name_array to a null character. This entry becomes available for adding new product to the inventory. Reduce the number of different products in the inventory by one.
Write the implementation of this class as well as test it with a driver program.
Note : In this problem you are not allowed to use string class or any of the string library functions.
c |
a |
m |
e |
r |
a |
\0 |
||||||||
t |
e |
l |
e |
v |
i |
s |
i |
o |
n |
\0 |
||||
\0 |
||||||||||||||
c |
o |
m |
p |
u |
t |
e |
r |
\0 |
||||||
\0 |
||||||||||||||
r |
e |
f |
r |
i |
g |
e |
r |
a |
t |
o |
r |
\0 |
||
o |
v |
e |
n |
\0 |
||||||||||
\0 |
||||||||||||||
\0 |
||||||||||||||
\0 |
Table 1. Stores the product names
12 |
625.00 |
17 |
410.00 |
0 |
0 |
8 |
750.00 |
0 |
0 |
6 |
975.00 |
9 |
550.00 |
0 |
0 |
0 |
0 |
0 |
0 |
Table 2. First column stores the stock in the inventory and second
In: Computer Science
Group Project
Step 1: Select any four sorting algorithm and two searching algorithms
Step 2: Understand the logic of all the algorithms
Step 3: Create java program and use your sorting/searching source codes and integrate it into your main java project.
Step 4: Create a separate java class for each algorithm
Step 5: Create a random function that generates at least 100000 random integer numbers from 1 to 1 million(No need to print out or store the numbers)
Step 6: Insert start transaction and end transaction for each sorting and searching methods
Step 7: Calculate the time in milliseconds for each sorting and searching class
Step 8: Compare the performance of each algorithm
Project Deliverables
In: Computer Science
I need to, Modify my mapper to count the number of occurrences of each character (including punctuation marks) in the file.
Code below:
#!/usr/bin/env python
#the above just indicates to use python to intepret this file
#This mapper code will input a line of text and output <word, 1> #
import sys
sys.path.append('.')
for line in sys.stdin:
line = line.strip() #trim spaces from beginning and end
keys = line.split() #split line by space
for key in keys:
value = 1
print ("%s\t%d" % (key,value)) #for each word generate 'word TAB 1' line
In: Computer Science
Choose a successful company and discuss how they use information technology to achieve their competitive advantage in their market.
In: Computer Science
Create a swap method without a temporary variable.
Implement an algorithm to figure out if someone has won a game of tic-tac-toe.
import java.util.Arrays; public class ArrayReview { private int data[]; public ArrayReview(int n) { data = new int[n]; for (int i = 0; i < n; i++) { data[i] = (int) (Math.random() * 100); } } public int[] getData() { return data; } public void setData(int[] data) { this.data = data; } @Override public String toString() { return Arrays.toString(data); } public void setKthItem(int k, int item) { if (k < 0 || k >= data.length) { return; } data[k] = item; } public int pickMaxIndex(int arr[], int start, int end) { int max = start; for (int i = start + 1; i <= end; i++) { if (arr[i] > arr[max]) { max = i; } } return max; } public void swap(int arr[], int i, int j) { if (arr[i] == arr[j]) { return; } arr[i] = arr[i] + arr[j]; arr[j] = arr[i] - arr[j]; arr[i] = arr[i] - arr[j]; } public void selectionSort() { int i, j, max_index; int n = data.length; for (i = 0; i < n - 1; i++) { max_index = i; for (j = i + 1; j < n; j++) if (data[j] > data[max_index]) max_index = j; swap(data, max_index, i); } } public static void main(String[] args) { ArrayReview array = new ArrayReview(10); System.out.println(array); System.out.println("After sorting: "); array.selectionSort(); for (int i : array.getData()) { System.out.printf("%-4d", i); } System.out.println(); } }
In: Computer Science
Hello, I am using IntelliJ IDEA with JavaFX to build a travel expensive calculator, but I dont konw how to conver user input to doulbe. Pleasse teach me how to add all textfield and display it after I click submit.
public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Label label1 = new Label ("(1) Number of days on the trip"); Label label2 = new Label ("(2) Transportation cost (choose one only)"); Label label3 = new Label ("Airfare Cost "); Label label4 = new Label ("Miles driven "); Label label5 = new Label ("(3) Conference registration cost "); Label label6 = new Label ("(4) Lodging Cost (per night) "); Label label7 = new Label ("(5) Food cost (total) "); Label label8 = new Label ("(6) Lodging Cost (per night) "); Label TotalExpensive = new Label("Total expenses: "); Label TotalExpensiveResult = new Label(" "); TextField field1 = new TextField(); TextField field2 = new TextField(); TextField field3 = new TextField(); TextField field4 = new TextField(); TextField field5 = new TextField(); TextField field6 = new TextField(); TextField field7 = new TextField(); Button button1 = new Button ("Submit"); //Create submit button Button button2 = new Button ("Cancel"); //Create Cancel button HBox hBox = new HBox(20, label1, field1); HBox hBox1 = new HBox(10, label2); HBox hBox2 = new HBox(15, label3, field2); HBox hBox3 = new HBox(10, label4, field3); HBox hBox4 = new HBox(12, label5, field4); HBox hBox5 = new HBox(32, label6, field5); HBox hBox6 = new HBox(75, label7, field6); HBox hBox7 = new HBox(32, label8, field7); HBox hBox8 = new HBox(20, button1, button2); HBox hBox9 = new HBox(20, TotalExpensive, TotalExpensiveResult); hBox.setAlignment(Pos.BASELINE_RIGHT); hBox1.setAlignment(Pos.BASELINE_LEFT); hBox2.setAlignment(Pos.BASELINE_RIGHT); hBox3.setAlignment(Pos.BASELINE_RIGHT); hBox4.setAlignment(Pos.BASELINE_RIGHT); hBox5.setAlignment(Pos.BASELINE_RIGHT); hBox6.setAlignment(Pos.BASELINE_RIGHT); hBox7.setAlignment(Pos.BASELINE_RIGHT); hBox8.setAlignment(Pos.CENTER); hBox9.setAlignment(Pos.CENTER); hBox.setPadding(new Insets(0,0,15,0)); hBox3.setPadding(new Insets(0,0,15,0)); hBox8.setPadding(new Insets(25,0,15,0)); GridPane gridPane = new GridPane (); gridPane.add(hBox, 0, 0); gridPane.add(hBox1, 0, 1); gridPane.add(hBox2, 0, 2); gridPane.add(hBox3, 0, 3); gridPane.add(hBox4, 0, 4); gridPane.add(hBox5, 0, 5); gridPane.add(hBox6, 0, 6); gridPane.add(hBox7, 0, 7); gridPane.add(hBox8, 0, 8); gridPane.add(hBox9, 0, 9); //*******Here********* button1.setOnAction(event -> { double cost = field1; TotalExpensiveResult.setText("Total Cost: $" + cost); }); gridPane.setAlignment(Pos.CENTER); gridPane.setPadding( new Insets(20, 20, 20, 20)); gridPane.setVgap( 10); gridPane.setHgap( 10); primaryStage.setTitle("Travel Expenses Calculator"); primaryStage.setScene(new Scene (gridPane)); primaryStage.show(); }
In: Computer Science
This problem is about query flooding in P2P networks. Here, we explore the reverse-path routing of the QueryHit messages in Gnutella. Suppose that Alice issues a Query message. Furthermore, suppose that Bob receives the Query message (which may have been forwarded by several intermediate peers) and has a file that matches the query.
5.1. As we know when a peer has a matching file, it sends a QueryHit message along the reverse path of the corresponding Query message. An alternative design would be for Bob to establish a direct TCP connection with Alice and send the QueryHit message over this connection. What are the advantages and disadvantages of such an alternative design?
5.2 In the Gnutella protocol, when the peer Alice generates a Query message, it inserts a unique ID in the message’s MessageID field. When the peer Bob has a match, it generates a QueryHit message using the same MessageID as the Query message. Describe how peers can use the MessageID field and local routing tables to accomplish reverse-path routing.
5.3. An alternative approach, which does not use message identifiers, is as follows. When a query message reaches a peer, before forwarding the message, the peer augments the query message with its IP address. Describe how peers can use this mechanism to accomplish reverse-path routing.
In: Computer Science
c programing language
This assignment, which introduces the use of loops, solves the following problem: given a starting location in a city, how long does it take a “drunken sailor” who randomly chooses his direction at each intersection to reach the city’s border? You will read input values to set up the problem parameters, run several trials to determine an average number of steps for the sailor to reach the border, and output the results.
This problem is an example of a “random walk,” a succession of random steps that can model real world problems like stock price fluctuation or molecules traveling through liquid. The approach is a simple approximation of a Monte Carlo experiment, in which repeated random samples are run to find a numerical result.
This assignment has been split into three parts to help teach you how to build a large program in smaller pieces. Doing so makes the program easier to develop and test--you can make sure each smaller piece works and then integrate the pieces together. In this lab, Part 1, you will handle the input processing--prompting the user for inputs, reading those values, and testing for all possible input errors.
Remember, in addition to submitting your code, you MUST complete the Blackboard assignment "Program 4 style assessment" to get all of the points for this program. You can complete this "assignment" by typing a short message indicating you submitted your code through the textbook IDE.
In your Blackboard submission, please indicate which of the three parts of the program you have completed. If you plan to complete all three parts, do not submit to Blackboard until all parts are done.
2. Specification
Problem Description
The city is organized as a set of M x N blocks. The sailor’s position, which must always be an intersection or a point on the border, can be represented as a pair of coordinates (X, Y), where 0 ≤ X ≤ M, and 0 ≤ Y ≤ N. See Figure 1 in the figures document for an example of a 4 x 3 city with the sailor at position (3, 2).
Input Specification
Your input must be entered in the order listed below. All inputs are integers. Note that your program should prompt the user to enter each value and check that each input fits within the bounds described below, as well as ensure there are no formatting errors:
M and N, the number of blocks in the X (2 ≤ M ≤ 10) and Y planes (2 ≤ N ≤ 10), respectively. This pair of values will be entered on the same line.
A starting position for the sailor, input as a pair of integers (X,Y).
T, The number of trials to execute (1 ≤ T ≤ 10). As we'll see in later parts of the assignment, each trial consists of placing the sailor at the starting point and randomly choosing movements until he reaches the border.
A sample set of input prompts and valid inputs to those prompts are shown below:
Output Specification
For this part of the program, after reading all inputs, your program should simply reprint the input values that were entered. So, given the sample inputs shown above, your program should print:
As noted above, detailed test cases showing appropriate input prompts can be found starting on page 3 of the figures document.
Error Checking
Your program should print a descriptive error message under any of the conditions below. For examples of valid error messages, see the built-in program test cases.
Any of the inputs are incorrectly formatted and therefore cannot be read correctly using scanf()
Your error message should simply read Could not read input in all cases.
Don't forget to clear the line if there is a formatting error, as described in Lecture 11!
The values of M and/or N (the number of X and Y blocks) do not fit in the ranges 2 ≤ M ≤ 10 and 2 ≤ N ≤ 10.
Your error message(s) should print # X blocks must be >= 2 and <= 10 or # Y blocks must be >= 2 and <= 10, depending on which input(s) caused the error.
It's possible for both values to be out of bounds, so your program may print two error messages for this pair of inputs.
The values of X and/or Y (the sailor's starting position) do not fit in the ranges 1 ≤ X ≤ (M-1) and 1 ≤ Y ≤ (N-1).
Your error message(s) should print Starting X position must satisfy (1 <= X <= M-1) or Starting X position must satisfy (1 <= Y <= N-1), depending on which input(s) caused the error.
The number of trials does not fit in the range 1 ≤ T ≤ 10.
3. Hints
Bounds checking and error messages
See Lecture 12 (M 9/30) for one example of how to handle input validation—repeatedly prompting your user to enter input values until the inputs are error-free.
Program development
Although the program has already been broken into smaller pieces, you can test your solution to this part piece by piece as well. I suggest starting with a single input validation loop--prompt for and read the number of X and Y blocks and test them for errors. If your program does all of those things successfully, it will pass the test case "Output test 2a". Then, move on to your input validation loop for the sailor's starting position, which, if it works correctly, will pass "Output test 2b." Adding a successful input validation loop for the number of trials will enable your program to pass the remaining test cases.
In: Computer Science
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