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.
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
This is a popular solution!
Step by step
Solved in 2 steps with 1 images