In: Computer Science
struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale temperature; }; Reading reading; // reading structure variable
Write statements that will store the following data below, in the variable written above in C++ please
Wind Speed: 37 mph
Humidity: 32%
Fahrenheit temperature: 32 degrees
Centigrade temperature: 0 degrees
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new C++ program with name "main.cpp" is created, which contains following code.
main.cpp :
#include <iostream>
using namespace std;
#include <stdio.h>
struct TempScale {
double fahrenheit;
double centigrade;
};
struct Reading {
int windSpeed;
double humidity;
TempScale temperature;
};
int main()
{
Reading reading; // reading structure variable
//accessing variable windSpeed using structure variable
reading
//and assigning value 37 mph
reading.windSpeed=37;
//accessing variable humidity using structure variable
reading
//and assigning value 32%
reading.humidity=32;
//accessing structure variable temperature using structure variable
reading
//with fahrenheit and assigning value 32 degrees
reading.temperature.fahrenheit=32;
//accessing structure variable temperature using structure variable
reading
//with centigrade and assigning value 0 degrees
reading.temperature.centigrade=0;
//displaying values
cout<<"Wind Speed: "<<reading.windSpeed<<"
mph"<<endl;
cout<<"Humidity:
"<<reading.humidity<<"%"<<endl;
cout<<"Fahrenheit temperature:
"<<reading.temperature.fahrenheit<<"
degrees"<<endl;
cout<<"Centigrade temperature:
"<<reading.temperature.centigrade <<"
degrees"<<endl;
return 0;
}
======================================================
Output : Compile and Run above program to get the output as below
Screen 1 :main.cpp
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.