Declare a structure named TempScale, with the following members:
fahrenheit: a double
centigrade: a double
Next define a Reading structure variable.
Write statements that will store the following data in the variable you defined above.
Wind Speed: 37 mph
Humidity: 32%
Fahrenheit temperature: 32 degrees
Centigrade temperature: 0 degrees 25.
showReading. It should accept a all member variable as its argument. The function should display the contents of the variables on the screen.
getFahrenheitReading, The function should return the value of Fahrenheit temperature.
getCelsiusReading, The function should return the value of Fahrenheit temperature.
recordReading. It should ask the user to enter values for each member of the structure and save the values.
findReading (int temp). It should use formulas to convert temperature into Fahrenheit and Celsius (according to user choice).
Input Validation: Add proper validation checks do not accept negative numbers for data member.
#include <iostream>
using namespace std;
struct TempScale{
double fahrenheit;
double centigrade;
double windspeed;
double humidity;
};
void showReading(TempScale r){
cout<<"\nWind Speed: "<<r.windspeed<<" mph";
cout<<"\nHumidity: "<<r.humidity<<"%";
cout<<"\nFahrenheit temperature: : "<<r.fahrenheit<<" degrees";
cout<<"\nCentigrade temperature: "<<r.centigrade<<" degrees";
}
double getFahrenheitReading(TempScale r){
return r.fahrenheit;
}
double getCelsiusReading(TempScale r){
return (5 * (r.fahrenheit - 32) / 9);
}
void recordReading(TempScale r){
cout<<"\nEnter wind speed: ";
cin>>r.windspeed;
cout<<"\nEnter humidity: ";
cin>>r.humidity;
cout<<"\nEnter fahrenheit: ";
cin>>r.fahrenheit;
cout<<"\nEnter centigrade: ";
cin>>r.centigrade;
}
double findReading (int temp){
return (5 * (temp - 32) / 9);
}
int main()
{
struct TempScale Reading;
Reading.windspeed=37;
Reading.humidity=32;
Reading.fahrenheit=32;
Reading.centigrade=25;
showReading(Reading);
return 0;
}
Comments
Leave a comment