Question

In: Computer Science

In C++ ============================================================EXERCISE 2 PROBLEM SET============================================================ 1) Declare a structure named TempScale , with the following...

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;

------------------------------------------------------------

Solutions

Expert Solution

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.


Related Solutions

C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t...
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t specify a size and don’t initialize with values. Starting with 2, pushing these into the back of the vector:   2, 4, 6, 8, 10 vector capacity (array size) changes and is dependent on the compiler. The size of the list is now 5. The vector capacity (array size) is 6. The back element is: 10 The front element is: 2 Now deleting the value at...
Write a program in c++ to do the following : (1) Declare an array a of...
Write a program in c++ to do the following : (1) Declare an array a of size 10 and three pointer variables p, q, and v. (2) Write a loop to fill array a with values 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (3) write following statement: p= &a[2]; q = &a[5]; i = *q - *p; cout<<“The value of i is”<< i; i = *p - *q; cout<<“The value of i is %d”<< i; 4) assign...
Translate the following tasks into Hack C-Instructions: 1) Set D to A - 1 2) Set...
Translate the following tasks into Hack C-Instructions: 1) Set D to A - 1 2) Set both A and D to A + 1 3) Set D to 19 4) Set both A and D to A + D 5) Set RAM[5034] to D - 1 6) Set RAM[543] to 171 7) Add 1 to RAM[7], and store result in D 8) Add 3 to RAM[12], and store result in D
Explain the difference between array and structure based on their usage in C++ programming. Declare a...
Explain the difference between array and structure based on their usage in C++ programming. Declare a structure called studentScore which contains name of student, registration number of students, course code and marks. Declare structure variable named studentCS680 based on the structure in (b) to store fifty (50) students’ data. Write a program that prompts a user to enter data for 50 students in a structure variable declared in (b) and calculate the average mark.
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue //...
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue // Assign myValue the value of "Hello, how's it going?" // Print the value of myValue to the console // 2) Use the charAt() method to display the letter t // from the variable myValue in the console // 3) Use the indexOf() method to display the position of "going" // from the variable myValue in the console // 4) Use the slice() method to...
Create a structure In C program named Student with the following components and appropriate data types:...
Create a structure In C program named Student with the following components and appropriate data types: Name, ID, CGPA i. Create an Array of Students of size three and take user input to fill the array. ii. Now find the student with the least CGPA and display his or hers Name, ID and CGPA.
CODE IN C++ PLEASE Create a structure (object) named Person that has the following characteristics: •...
CODE IN C++ PLEASE Create a structure (object) named Person that has the following characteristics: • full name • age • family members full names represent by an array of size 10. Write a program that creates an array of Person of size 5. Populate the array of objects with the information given by user input according to the following specifications: • With input from the user i) Populate only 3 positions of the array of Person object. ii) Populate...
R Studio Coding Exercise Problem-Set Questions 1-6 # 1) Create the following vector in 1 line...
R Studio Coding Exercise Problem-Set Questions 1-6 # 1) Create the following vector in 1 line of code without using the c() function: # [i] 4 12 20 4 12 20 4 12 # 2) Create a vector of 25 random heights between 54 and 78 inches. Cycle through the vector using a For loop and create a new vector that places each height into a category. People less than 5 feet should be categorized as short, those taller than...
Explain the logical structure of the following set of propositions - a theory. 1.The set of...
Explain the logical structure of the following set of propositions - a theory. 1.The set of languages accepted (decided) by deterministic Turing machines = the set of languages accepted (decided) by nondeterministic Turing machines 2. PATH belongs to P 3. TAUTOLOGY is a member of coNP 4. 2 definitions for NP (1 in terms of a polynomial verifier 2 in terms of a nTM) are equivalent 5. PSPACE = NPSPACE 6. NP is a subset of PSPACE 7. SAT belongs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT