Questions
A local biologist needs a program to predict population growth. The inputs would be: The initial...

A local biologist needs a program to predict population growth. The inputs would be:

  1. The initial number of organisms, as an int
  2. The rate of growth (a real number greater than 1), as a float
  3. The number of hours it takes to achieve this rate, as an int
  4. A number of hours during which the population grows, as an int

For example, one might start with a population of 500 organisms, a growth rate of 2, and a growth period to achieve this rate of 6 hours. Assuming that none of the organisms die, this would imply that this population would double in size every 6 hours. Thus, after allowing 6 hours for growth, we would have 1000 organisms, and after 12 hours, we would have 2000 organisms.

Write a program that takes these inputs and displays a prediction of the total population.

An example of the program input and output is shown below:

Enter the initial number of organisms: 10
Enter the rate of growth [a real number > 1]: 2
Enter the number of hours to achieve the rate of growth: 2
Enter the total hours of growth: 6

The total population is 80

In: Computer Science

Discuss the pros and cons of an IDE vs command-line interpreters. Why are command-line interpreters still...

Discuss the pros and cons of an IDE vs command-line interpreters. Why are command-line interpreters still being used? Be sure to argue both sides.

In: Computer Science

(Java) Create a new linked list from two given arrays with the greater element from each...

(Java)

Create a new linked list from two given arrays with the greater element from each corresponding array element placed into the linked list.

Given two arrays of varying size initialized with integers of varying values, the task is to create a new linked list using those arrays. The condition is that the greater element value from each corresponding array element will be added to the new linked list in the list position that maintains the integers in ascending order. When the program has reached the end of the shorter array, the remaining elements of the longer array will be added to the linked list in such a way as to maintain the integers in the linked list in ascending order.

In: Computer Science

Discuss the differences between repetitive and selective statements. Use segment codes to demonstrate your understanding. Explain...

  • Discuss the differences between repetitive and selective statements. Use segment codes to demonstrate your understanding.
  • Explain why you are choosing one of the following three statements in your code:
    • a) for statement,
    • b) while statement,
    • c) do-while statement.
  • Provide examples.

In: Computer Science

Write a program that accepts the lengths of three sides of a triangle as inputs. The...

Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle.

Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides.

  • Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs.

An example of the program input and proper output format is shown below:

Enter the first side: 3
Enter the second side: 4
Enter the third side: 5

The triangle is a right triangle

In: Computer Science

I can't figure out why this won't run. //CryptographyTest.java //package cryptography; import java.util.Scanner; public class CryptographyTest...

I can't figure out why this won't run.

//CryptographyTest.java
//package cryptography;

import java.util.Scanner;

public class CryptographyTest {
  
public static void main(String[] args) {
// create a scanner object to read from user
Scanner s = new Scanner(System.in);
// prompt user for input option
while(true) {
// loop till user say exit
System.out.println("Select Option:");
System.out.println("1. Encrypt");
System.out.println("2. Decrypt");
System.out.println("3. Exit");
String input = s.nextLine(); // get user input
int option = 0;
try {
// check for valid input
option = Integer.parseInt(input);
if(option < 1 || option > 3) {
throw new IllegalArgumentException();
}
} catch (Exception e) {
// print error message
System.out.println("Invalid Input!");
}
      
       // check for user option
if(option == 1) {
// ask user for data to encrypt
System.out.print("Enter 4 digit number to Encrypt: ");
int data = getInput(s); // get user input
// check for valid input
if(data == -1) {
// print error message
System.out.println("Invalid Input!");
}
else {
System.out.print("Encrypted number is: ");
String encrypt_number = "" + Cryptography.encrypt(data);
// add zeroes at start of number if needed
int len = encrypt_number.length();
for(int i=4;i>len;i--) {
encrypt_number = "0" + encrypt_number;
}
System.out.println(encrypt_number);
}
}
else if(option == 2) {
// ask user for data to decrypt
System.out.print("Enter 4 digit number to Decrypt: ");
int data = getInput(s); // get user input
// check for valid input
if(data == -1) {
// print error message
System.out.println("Invalid Input!");
}
else {
System.out.print("Decrypted number is: ");
String decrypt_number = "" + Cryptography.decrypt(data);
// add zeroes at start of number if needed
int len = decrypt_number.length();
for(int i=4;i>len;i--) {
decrypt_number = "0" + decrypt_number;
}
System.out.println(decrypt_number);
}
}
else if(option == 3) {
// break the loop and exit program
System.out.println("Bye!");
break;
}
}
  
}

private static int getInput(Scanner s) {
String input;
// get user input
input = s.nextLine();
// check for input length
if(input.length() != 4) {
// return as input is not valid
return -1;
}
else {
// check for integer input
try {
int data = Integer.parseInt(input);
// return the input in integer form
return data;
} catch (Exception e) {
// return as input is not integer type
return -1;
}
}
}

}

(goes with this:)

//Cryptography.java

//package cryptography;

public class Cryptography {
  
public static int encrypt(int input) {
// input is a 4 digit integer
// convert integer to string
String str = "" + input;
// add zeroes at start of number if needed
int len = str.length();
for(int i=4;i>len;i--) {
str = "0" + str;
}
// get individual digits
int first_digit = str.charAt(0) - '0'; // remove '0' to convert char to digit
int second_digit = str.charAt(1) - '0';
int third_digit = str.charAt(2) - '0';
int fourth_digit = str.charAt(3) - '0';
// add 7 to each digit and take reminder by dividing 10
first_digit = (first_digit + 7) % 10;
second_digit = (second_digit + 7) % 10;
third_digit = (third_digit + 7) % 10;
fourth_digit = (fourth_digit + 7) % 10;
// replace first digit with third and second with fourth
String encrypt_number = "" + third_digit + fourth_digit + first_digit + second_digit;
// convert string to integer and return it
return Integer.parseInt(encrypt_number);
}
  
public static int decrypt(int input) {
// input is 4 digit integer
// convert integer to string
String str = "" + input;
// add zeroes at start of number if needed
int len = str.length();
for(int i=4;i>len;i--) {
str = "0" + str;
}
// get individual digits
int first_digit = str.charAt(0) - '0'; // remove '0' to convert char to digit
int second_digit = str.charAt(1) - '0';
int third_digit = str.charAt(2) - '0';
int fourth_digit = str.charAt(3) - '0';
// add 3 to each digit and take reminder by dividing 10
first_digit = (first_digit + 3) % 10;
second_digit = (second_digit + 3) % 10;
third_digit = (third_digit + 3) % 10;
fourth_digit = (fourth_digit + 3) % 10;
// replace first digit with third and second with fourth
String encrypt_number = "" + third_digit + fourth_digit + first_digit + second_digit;
// convert string to integer and return it
return Integer.parseInt(encrypt_number);
}

}

In: Computer Science

(a) Implement the following algorithm, which is given a duplicate-free array array as input, in C++....

(a) Implement the following algorithm, which is given a duplicate-free array array as input, in C++. whatDoIDo (array):

1) Build a heap from array (using buildHeap as explained in class), where the heap starts at position array[0].

2) Starting from j = size of array - 1, as long as j>0:

i. Swap the entries array[0] and array[j].

ii. Percolate down array[0], but only within the subarray array[0..j-1].

iii. Decrement j by 1. Provide three input/output examples for duplicate-free arrays of size about 10.

(b) What does whatDoIDo do? Explain your answer.

(c) What is the worst-case running time of whatDoIDo, in dependence of the size N of the given array? Explain your answer.

In: Computer Science

In arduino: 1.Given two Arrays A= {2,4,7,8,3) and B={11,3,2,8,13). Write a program that find the numbers...

In arduino:

1.Given two Arrays A= {2,4,7,8,3) and B={11,3,2,8,13). Write a program that find the numbers into A but not in B. For the example C=A-B= {4,7} Print the values (Use for loops)

2.Create a vector of five integers each in the range from -10 to 100 (Prompt the user for the five integer x). Perform each of the following using loops:

a) Find the maximum and minimum value

b)Find the number of negatives numbers

Print all results

In: Computer Science

Please use assembly language x86 Visual Studio Write a program to add the following word size...

Please use assembly language x86 Visual Studio

Write a program to add the following word size numbers:15F2, 9E89, 8342, 99FF, 7130 using adc instruction and a loop. The result must be in DX, AX. Show the result in debug window.

In: Computer Science

In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files...

In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files from the Internet. This program is very similar to wget utility in Unix/Linux environment.The synopsis of SimpleWebGet is: java SimpleWebGet URL. The URL could be either a valid link on the Internet, e.g., www.asu.edu/index.html, or gaia.cs.umass.edu/wireshark-labs/alice.txt or an invalid link, e.g., www.asu.edu/inde.html. ww.asu.edu/inde.html. The output of SimpleWebGet for valid links should be the same as wget utility in Linux, except the progress line highlighted within the red rectangle: 100% [============================>] 152,138 248.78K/s.The outputs of SimpleWebGet for not-found hosts or non-found files should be the same as wget utility in Linux. Dynamics progress bar and percentages are shown.The program could successfully download a HTML file or other Web objects.The program could report the Resolving line.The program could report the Connecting line.The program could report the HTTP request and response line.The program could report the Length line.The program could report the accurate data transfer rate.The program could handle the host/servname not known error. The program could handle the file not found error.

In: Computer Science

Question 13 We define the letters 'a', 'e', 'i', 'o' and 'u' as vowels. We do...

Question 13

We define the letters 'a', 'e', 'i', 'o' and 'u' as vowels. We do not consider any other letter as a vowel.

Write a function named initialVowels() that returns a list of words in a body of text that begin with a vowel.

Include both capitalized and lower case instances of the vowels.

A word should appear in the return list at most once, no matter how many times is occurs in the input string.

Input: a string that consists of words, separated by spaces

Return: an list of words in the input string that begin with an upper or lower case vowel

For example, the following would be correct output:

>>> mlk = 'Our lives begin to end the day we become silent about things that matter'

>>> print(initialVowels(mlk))

['Our','about']

Question 14

The three words 'a', 'an' and 'the' are the only articles in the English language.

Write a function named countArticles(). Hint: Count both capitalized and lower case instances of articles.

Input: a string, named sentence

Return: the number of words in sentence that are articles

For example, the following would be correct output:

>>> theFlea = ['The flea is a mighty insect']

>>> print(articleCount(theFlea))

>>> 2

Question 15

Write a function named pluralCount() that takes two string parameters.

The first parameter is the name of an input file that exists before pluralCount() is called.

The second parameter is the name of an output file that pluralCount() creates and writes to.

You may assume that the input file is in the current working directory and you should write the output file to that directory as well.

For each line in the input file, the function pluralCount() should write to the output file the number of words in the line that end in the letter 's'.

For example, if the following is the content of the file foxInSocks.txt:

Look, sir. Look, sir. Mr. Knox, sir.

Let's do tricks with bricks and blocks, sir.

Let's do tricks with chicks and clocks, sir.

The following function call:

inF = 'foxInSocks.txt'

outF = 'foxRepLines.txt'

pluralCount(inF, outF)

should create the file ‘foxRepLines.txt’ with the content:

0

4

4

In: Computer Science

Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks:...

Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this year’s competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The expected revenue is calculated and displayed. The revenue is $25 per contestant. For example if there were 3 contestants, the expected revenue would be displayed as: Revenue expected this year is $75.00 The program prompts the user for names and talent codes for each contestant entered. Along with the prompt for a talent code, display a list of the valid categories. The categories should be displayed in the following format: The types of talent are: S Singing D Dancing M Musical instrument O Other After data entry is complete, the program displays the valid talent categories and then continuously prompts the user for talent codes and displays the names of all contestants in the category. Appropriate messages are displayed if the entered code is not a character or a valid code.

beginning of c# code:

using System;

using static System.Console;

using System.Globalization;

class GreenvilleRevenue

{

   static void Main()

   {

      // Your code here

   }

}

In: Computer Science

We saw in class different sorting algorithms, and we generally assumed the input to be sorted...

We saw in class different sorting algorithms, and we generally assumed the input to be sorted wasj an array. Here, the provided input is an unordered linked list of n elements with integer values. We are interested in sorting this list in increasing order (smallest first), in O(n log n) worst case time, while using constant space (also called in-place sorting). Note that recursion requires additional space on the stack, so should EC330 Applied Algorithms and Data Structures for Engineers, Fall 2020 be avoided in this case.

You are provided with the following files: LNode.h, LNode.cpp, LSorter.h, LSorter.cpp, and main.cpp.

A linked list node, LNode, is implemented in LNode.h and LNode.cpp. The LSorter class with the sortList method are declared in LSorter.h. The sortList method, which you need to implement, is declared as follows:

class LSorter { public: LNode* sortList(LNode* head); };

This method accepts as input the head node of the list to be sorted, and returns the head node of the sorted linked list. Your implementation should be included in the LSorter.cpp file. You may add additional classes and/or methods as you see fit, but everything should be included in this file, and none of the other files may be modified.

Finally, the provided main.cpp file may be used to test your implementation. You may assume that your input consists of non-negative integers with a maximal value of 1,000,000. Modify and submit LSorter.cpp only. The submitted file should compile and run with the rest of the files. We will run it against large linked list and measure the run time.

Partial credit will be given for an in-place solution with a runtime that is worse than O(n log n).

LNode.h:

#ifndef LNode_h
#define LNode_h

#include <stdio.h>

class LNode {
public:
    int val;
    LNode* next;
    LNode(int x=0);
};

#endif /* LNode_h */

LNode.cpp:

#include "LNode.h"

LNode::LNode(int x) {
        val = x;
        next = nullptr;
    }

Lsorter.h:

#ifndef LSorter_h
#define LSorter_h

#include <stdio.h>
#include "LNode.h"

class LSorter {
public:
    LNode* sortList(LNode* head);
};

#endif /* LSorter_h */

Lsorter.cpp:

#include <algorithm>
#include "LSorter.h"
using namespace std;

LNode* LSorter::sortList(LNode* head){
        // Your code goes in here...
    
}

main.cpp:

#include <iostream>
#include "LNode.h"
#include "LSorter.h"

using namespace std;

int main(int argc, const char * argv[]) {
    
    LNode LNode1(5);
    LNode LNode2(1);
    LNode LNode3(7);
    LNode LNode4(13);
    LNode LNode5(2);
    LNode LNode6(9);
    
    LNode1.next = &LNode2;
    LNode2.next = &LNode3;
    LNode3.next = &LNode4;
    LNode4.next = &LNode5;
    LNode5.next = &LNode6;
    
    LSorter solution;
    LNode* head = solution.sortList(&LNode1);
    
    LNode* currnode = head;
    while (currnode != nullptr){
        cout << currnode->val << endl;
        currnode = currnode->next;
    }           

    return 0;
}

In: Computer Science

we saw a C program called GuessNumber.c that generates a random integer between 1 and 1000...

we saw a C program called GuessNumber.c that generates a random integer between 1 and 1000 and asks the user to guess that number. Modify the program so that at the end of each round, it also prints the number of guesses made by the user to reach the answer as well as the best score so far, i.e., the minimum number of guesses used in any round since the program was started. The source code of the original version of GuessNumber.c can be found in: https://github.com/pdeitel/CHowToProgram8e/archive/master.zip under examples/ch01/GuessNumber/GNU/randomized_version/

In: Computer Science

write c++ program. 1. Time converter 2. Length Converter 3. weight Converter 4.Currency Converter 5. Temprature...

write c++ program.
1. Time converter
2. Length Converter
3. weight Converter
4.Currency Converter
5. Temprature Converter (C to F and F to C)

time converter (minutes to second, second to minutes, hours to seconds, seconds to hours, minutes to hours, hours to minutes)

In: Computer Science