In: Computer Science
In C++
============================================================EXERCISE 2 PROBLEM SET============================================================
1) Declare a structure named TempScale , with the following members:fahrenheit: a doublecentigrade: a doubleNext, declare a structure named Reading , with the following members:windSpeed: an inthumidity: a doubletemperature: a TempScale str ucture variableNext define a Reading structure variable.
------------------------------------------------------------
2) Write statements that will store the following data inthe variable you defined in Problem 1:Wind Speed: 37 mphHumidity: 32%Fahrenheit temperature: 32 degreesCentigrade temperature: 0 degrees
------------------------------------------------------------
3) Write a function called showReading. It should accept a Reading structure variable (Prob #1) as its argument.The function should display the contents of thevariable on the screen.------------------------------------------------------------
4) Write a function called findReading. It should use aReading structure reference variable (Prob # 1) as itsparameter. The function should ask the user to entervalues for each member of the structure.
------------------------------------------------------------
5) Write a function called getReading , which returns aReading structure (Prob #1). The function should askthe user to enter values for each member of a Readingstructure, then return the structure.
------------------------------------------------------------
6) Write a function called recordReading . It should use aReading structure pointervariable (Prob #1) as itsparameter. The function should ask the user to entervalues for each member of the structure pointed toby the parameter.
------------------------------------------------------------
7) Rewrite the following statement using the structurepointer operator:(*rptr).windSpeed = 50;
------------------------------------------------------------
8) Rewrite the following statement using the structurepointer(arrow)operator: *(*strPtr).num = 10;
------------------------------------------------------------
Code 1 to 6;
#include<iostream>
using namespace std;
void showReading(struct Reading);
void findReading(struct Reading &);
void recordReading (struct Reading *);
struct Reading getReading ();
struct TempScale
{
double fahrenheit;
double centigrade;
};
struct Reading
{
int windSpeed;
double inthumidity;
TempScale temperature;
};
int main()
{
Reading readData;
readData.inthumidity=32;
readData.windSpeed=37;
readData.temperature.fahrenheit=32;
readData.temperature.centigrade=0;
showReading(readData);
cout<<"\n\nfindReading function
call"<<endl;
findReading(readData);
showReading(readData);
cout<<"\n\ngetReading function
call"<<endl;
readData=getReading();
showReading(readData);
cout<<"\n\nrecordReading function call"<<endl;
recordReading(&readData);
showReading(readData);
return 1;
}
void showReading(struct Reading reading)
{
cout<<"Wind speed:
"<<reading.windSpeed<<" mph"<<endl;
cout<<"Humidity:
"<<reading.inthumidity<<"%"<<endl;
cout<<"Fahrenheit temperature:
"<<reading.temperature.fahrenheit<<"
degree"<<endl;;
cout<<"Centigrade temperature:
"<<reading.temperature.centigrade<<"
degree"<<endl;
}
void findReading(struct Reading & reading)
{
cout<<"Enter the wind speed: ";
cin>>reading.windSpeed;
cout<<"Enter the humidity in percentage:
";
cin>>reading.inthumidity;
cout<<"Entre fahrenheit remperature: ";
cin>>reading.temperature.fahrenheit;
cout<<"Entre Centigrade remperature: ";
cin>>reading.temperature.centigrade;
}
struct Reading getReading ()
{
Reading reading;
cout<<"Enter the wind speed: ";
cin>>reading.windSpeed;
cout<<"Enter the humidity in percentage:
";
cin>>reading.inthumidity;
cout<<"Entre fahrenheit remperature: ";
cin>>reading.temperature.fahrenheit;
cout<<"Entre Centigrade remperature: ";
cin>>reading.temperature.centigrade;
return reading;
}
void recordReading (struct Reading *ptr)
{
cout<<"Enter the wind speed: ";
cin>>ptr->windSpeed;
cout<<"Enter the humidity in percentage:
";
cin>>ptr->inthumidity;
cout<<"Entre fahrenheit remperature: ";
cin>>ptr->temperature.fahrenheit;
cout<<"Entre Centigrade remperature: ";
cin>>ptr->temperature.centigrade;
}
ouput
7)
(*rptr).windSpeed=50 is same as rptr->windSpeed=50;
8)
ans
*strPtr->num = 10;
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.