The density of freshwater as a function of temperature (in Celsius) can be modeled: p= 5.53 x 10-8T - 8.50 x 10-672 + 6.56 x 10-5T. + 1.00 Write a function with structure function rho = density(T) that takes an array of temperatures T in Fahrenheit as an input and returns an array of corresponding densities as an output. An anonymous function that converts Fehrenheit to Celsius is provided.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question
The density of freshwater as a function of temperature (in Celsius) can be modeled:
p = 5.53 x 10-873 – 8.50 x 10-67? + 6.56 x 10-5T. + 1.00
%3D
Write a function with structure
function rho density(T)
that takes an array of temperatures T in Fahrenheit as an input and returns an array of corresponding
densities as an output. An anonymous function that converts Fehrenheit to Celsius is provided.
Transcribed Image Text:The density of freshwater as a function of temperature (in Celsius) can be modeled: p = 5.53 x 10-873 – 8.50 x 10-67? + 6.56 x 10-5T. + 1.00 %3D Write a function with structure function rho density(T) that takes an array of temperatures T in Fahrenheit as an input and returns an array of corresponding densities as an output. An anonymous function that converts Fehrenheit to Celsius is provided.
Expert Solution
Step 1

As no programming language is mentioned, I have written the code in C++. A function to convert Fahrenheit to Celsius is written.

The program is 

#include <iostream>
#include<math.h>
using namespace std;
struct fahrenheit{
    float f[50];
};
struct rho{
    float r[50];
};
float celsius(float m)
{
    return ((float)5/(float)9)*(m-32);
}
rho density(fahrenheit a,int n)
{
   rho b;
    for(int i=0;i<n;i++)
    {
        a.f[i]=celsius(a.f[i]);
        b.r[i]=(5.53*pow(10,-8)*pow(a.f[i],3))-(8.50*pow(10,-6)*pow(a.f[i],2))+(6.56*pow(10,-5)*a.f[i])+1.00;
    }
    return b;
}
int main()
{
    int n,i;
    cout<<"Enter number of values: "<<endl;
    cin>>n;
    fahrenheit a;
    rho s;
    cout<<"Enter temperature values in fahrenheit "<<endl;
    for(i=0;i<n;i++)
    {
        cin>>a.f[i];
    }
    s=density(a,n);
    cout<<"The density values are: \nTemperature\tDensity\n";
    for(i=0;i<n;i++)
    {
        cout<<a.f[i]<<"\t\t"<<s.r[i]<<endl;;
    }
    return 0;
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning