Question

In: Computer Science

struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale...

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

Solutions

Expert Solution

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.


Related Solutions

System.out.println("Enter a temperature in Fahrenheit: ");          double fahrenheit = input.nextDouble();       double...
System.out.println("Enter a temperature in Fahrenheit: ");          double fahrenheit = input.nextDouble();       double celsius = (5.0 / 9) * (fahrenheit - 32);    System.out.println("Fahrenheit " + fahrenheit + " is " + celsius + " in Celsius"); the above code i would like to print to 2 decimal places for celsius please   this is in JAVA
The task is to sort structs in array. The struct is struct coor{ int x; int...
The task is to sort structs in array. The struct is struct coor{ int x; int y; int z; }; Create an array with 100 coordinates, which are randomly initiated with x between 0 and 30 and y between 5 and 60, and z between 10 and 90. Then modify the Quick Sort algorithm (QuickSort.cpp) to sort coordinated. Comparison of the coordinates should be carried on first x, then y, and z last. It means that if two points has...
Implement stack in C Struct: struct patients{ int id; int severity; char *firstName; char *lastName; char...
Implement stack in C Struct: struct patients{ int id; int severity; char *firstName; char *lastName; char *state; int time_spent; }; Given Array: struct patients* patientsArray[4] = {&p1, &p2, &p3, &p4}; Create two functions one for pushing this array to the stack and one for popping the variables such as p1 p2 p3 p4 by its ID
Develop a form to display centigrade temperature and corresponding Fahrenheit temperature ranging from 30 to 90...
Develop a form to display centigrade temperature and corresponding Fahrenheit temperature ranging from 30 to 90 at increments of 10. Use a do while loop. Please use the below formula to convert Celsius to Fahrenheit in advance C# I need the form not a table. Thank you!
Write in java Q 4.Centigrade and Fahrenheit are two scales to measure temperature. Write a program...
Write in java Q 4.Centigrade and Fahrenheit are two scales to measure temperature. Write a program that that prompts the user to enter Centigrate and then print the Fahrenheit. Use following formula for conversion. Fahrenheit = Centigrade*1.8 +   32 ; Q. 7 Write a program to calculate the bill of a customer. The program will -           Prompt the employee to enter the monthly plan fees. -           Prompt the employee to enter the rate per additional minute. -          Print the bill...
Consider the following struct that represents a node within a binary tree: struct Node { int...
Consider the following struct that represents a node within a binary tree: struct Node { int data; // Data of interest Node *left // Link to left subtree (nullptr if none) Node *right ; // Link to right subtree (nullptr if none) }; Complete the following function that computes the number of elements in a binary tree: // Counts the number of elements in the binary tree to which t points. // Returns the number of elements. int size(Node *t)...
Please do this code with python. Thank you! struct Node {     int data;     struct...
Please do this code with python. Thank you! struct Node {     int data;     struct Node* left;     struct Node* right; }; // Node creation struct Node* newNode(int data) {     struct Node* nn         = new Node;     nn->data = data;     nn->left = NULL;     nn->right = NULL;     return nn; } // Function to insert data in BST struct Node* insert(struct Node* root, int data) {   if (root == NULL)         return newNode(data);     else {...
1)What is the output of the following code? struct someType { int a; int b; };...
1)What is the output of the following code? struct someType { int a; int b; }; void f1(someType &s) { s.a = 1; s.b = 2; } someType f2(someType s) { someType t; t = s; s.a = 3; return t; } int main() { someType s1, s2; f1(s1); s2 = f2(s1); cout << s1.a << '-' << s1.b << '-' << s2.a << '-' << s2.b << '-' << endl; return 0; } ------------------------------------------------------------------------------------------------------------------ 2) struct dateType { int...
FINISH print and freelist #include<stdio.h> #include <stdlib.h> struct node {      int data;      struct node  *next; }; struct...
FINISH print and freelist #include<stdio.h> #include <stdlib.h> struct node {      int data;      struct node  *next; }; struct node* insert(struct node* list,int d ); struct node* del(struct node* list,int d ); void print( struct node *list); void freeList(struct node* list); void copy ( struct node *q, struct node **s ); int main( ) {     int number = 0, choice = 0;     struct node *pList=NULL;     struct node *nList = NULL;         while(choice!= 4)     {                 printf("Do you want to (1)insert, (2)delete, (3)Copy (4)quit.\n");...
Using the following definitions for a binary tree, typedef struct bintreenode {     int data;     struct bintreenode*...
Using the following definitions for a binary tree, typedef struct bintreenode {     int data;     struct bintreenode* left;     struct bintreenode* right; } btreenode; // Used for a node in the queue. typedef struct node {     btreenode* nodePtr;     struct node* next; } node; // Used to represent the queue efficiently. typedef struct queue {     node* front;     node* back; } queue; Implement the following functions: void bfs(btreenode* root) // Prints a breadth first search traversal of the binary search tree rooted at root....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT