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

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...
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.
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
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.
1 Commenting in C There are two mechanisms in C to declare comments: 1. Commenting in...
1 Commenting in C There are two mechanisms in C to declare comments: 1. Commenting in a single line using // at the beginning, and 2. Commenting in potentially multiple lines using /* to mark the beginning and */ to mark the ending. For each of the following criteria, argue which commenting mechanism is more preferred. readability, writability, and reliability
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...
There are A, B, and C types of problem set, and each type of problem set...
There are A, B, and C types of problem set, and each type of problem set contains 3000, 2000, 5000 problems, respectively. Suppose you can solve A-type problem with 90% probability, B-type problem with 20% probability, and C-type problem with 60% probability. To pass graduation exam, you must solve both of two questions randomly chosen from the total problem set (out of 10,000 problems). Answer the following questions: 1) What is the probability that you pass the graduation exam? 2)...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without specifying the size 2. use push_back to add random integers between 100 and 999 to the vector 3. write a function that returns the smallest, largest, and average of the numbers in the vector display the smallest, largest, and average of the numbers in the vector
Topics 1. Introduction 2. MIPS instruction set architecture (ISA) Exercise 1 Answer the following questions. (a)...
Topics 1. Introduction 2. MIPS instruction set architecture (ISA) Exercise 1 Answer the following questions. (a) List the five classic components of a computer. (b) Describe the steps that transform a program written in a high-level language such as Java into a representation that is directly executed by a computer processor.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT