1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
GalinKa [24]
4 years ago
14

Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). D

o this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same array. Celsius=(F-32)*5/9 From main, print the modified temperature array in a single column format similar to one shown below: Temperatures(Celsius) 37.78 65.56 100.00 0.00 21.11 Test your program with the following values: 100 150 212 32 70
Computers and Technology
1 answer:
dalvyx [7]4 years ago
8 0

Answer:

The solution code is written in Java.

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        double myArray [] = new double[5];
  5.        Scanner reader = new Scanner(System.in);
  6.        for(int i=0; i < myArray.length; i++){
  7.            System.out.print("Enter temperature (Fahrenheit): ");
  8.            myArray[i] = reader.nextDouble();
  9.        }
  10.        convert2Cels(myArray, 5);
  11.        for(int j = 0; j < myArray.length; j++){
  12.            System.out.format("%.2f \n", myArray[j]);
  13.        }
  14.    }
  15.    public static void convert2Cels(double [] tempArray, int n){
  16.        for(int i = 0; i < n; i++){
  17.            tempArray[i] = (tempArray[i] - 32) * 5 / 9;
  18.        }
  19.    }
  20. }

Explanation:

Firstly, let's create a double-type array with 5 elements, <em>myArray </em>(Line 6).

Next, we create a Java Scanner object to read user input for the temperature (8).

Using a for-loop that repeats iteration for 5 times, prompt user to input temperature in Fahrenheit unit and assign it as the value of current element of the array. (Line 11 - 12). Please note the nextDouble() method is used to read user input as the data type of input temperature is expect in decimal format.

At this stage, we are ready to create the required function convert2Cels() that takes two input arguments, the temperature array,  <em>tempArray</em> and number of array elements, <em>n </em>(Line 23).  Using a for-loop to traverse each element of the tempArray and apply the formula to convert the fahrenheit to celcius.  

Next, we call the function <em>convert2Cels() i</em>n the main program (Line 15) and print out the temperature (in celsius) in one single column (Line 17-19). The <em>%.2f</em> in the print statement is to display the temperature value with 2 decimal places.

You might be interested in
Which of the following is true? You are a project manager for Laredo Pioneer's Traveling Rodeo Show. You're heading up a project
nika2105 [10]

Answer: C. You are a project manager for Laredo Pioneer's Traveling Rodeo Show. You're heading up a project to promote a new line of souvenirs to be sold at the shows. You're ready to document the processes you'll use to perform the project as well as define how the project will be executed and controlled and how changes will be monitored and controlled. You are working on the project management plan.

Explanation:

4 0
3 years ago
The report Jamie created has a dark background and the page number is not displaying correctly. Which formatting option would he
Readme [11.4K]
The Font Color <span>formatting option would be needed to apply to the page number to add contrast between the background and the page number</span>
8 0
3 years ago
1.A tachometer measures:
Art [367]
1. D


2. D


I hope I helped :)
3 0
3 years ago
Why is peer-to-peer architecture the simplest form of network? because computers form P2P networks all by themselves because ser
Ket [755]
Bc nothing but 2 computer is required 
6 0
3 years ago
Read 2 more answers
A program asks the user to enter the unit price of a chair and the quantity he is buying. It calculates and displays the total p
Shtirlitz [24]

Answer:

The c++ program for the given scenario is shown below.

#include <iostream>

using namespace std;

int main() {

   // variables declared for unit price, quantity, total price

// price is taken as double

// quantity is taken as integer

   double chair_price, total_price;

   int chair_qty;

   cout << " Enter the unit price of the chair : " << endl;

   cin >> chair_price;

   cout << " Enter the number of the chairs to be bought : " << endl;

   cin >> chair_qty;

   total_price = chair_price * chair_qty;

   cout << " The total price for " << chair_qty << " chairs is " << total_price << endl;

   return 0;

}

OUTPUT

Enter the unit price of the chair  

23.4

Enter the number of the chairs to be bought  

10

The total price for 10 chairs is 234

Explanation:

 

1. The variables for unit price, quantity of chairs and total price of chairs are declared. The reason for data type is explained below.

double chair_price, total_price;

   int chair_qty;

2. The variables are not initialized since their values is to be entered by the user.

3. First, the user is prompted to enter the unit price of the chair. This is stored in a double variable since price can be in decimals.

cin >> chair_price;

4. Next, the user enters the number of chairs to be bought. This value is stored in an integer variable since quantity can not be a decimal number.

cin >> chair_qty;

5. The total price is computed as the product of the unit price and the quantity of chairs. The total cost is also stored in a double variable since unit price can be in decimals.

total_price = chair_price * chair_qty;

6. Lastly, this total price is displayed to the standard output.

7. The keyword endl is used to insert new line.

4 0
3 years ago
Other questions:
  • Assume the existence of a class named window with functions named close and freeresources, both of which accept no parameters an
    13·1 answer
  • Jessica is working on a report for her art history class. She is using Microsoft Word for her report so that she can incorporate
    6·2 answers
  • What is the key function of a Scrum Master?
    13·1 answer
  • what is the goal of technology A. to understand how the natural world functions B. to study the natural world C. to improve the
    9·1 answer
  • When making an on-site service call, what should you do before making any changes to software or before taking the case cover of
    6·1 answer
  • Setting up network encryption involves
    5·1 answer
  • Remember partially filled arrays where the number of elements stored in the array can be less than its capacity (the maximum num
    14·1 answer
  • Convert the following numbers to binary numbers: 5 , 6 , 7 , 8 , 9 .​
    13·2 answers
  • It is a type of web page that allows you to share your ideas experiences and beliefs
    9·1 answer
  • True or false?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!