Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I am struggeling with this task, I keep getting the wrong output. How should one go and write this program?? Write a C++ program

Hi I am struggeling with this task, I keep getting the wrong output. How should one go and write this program??

Write a C++ program called avg proc.cpp that calculates the average temperature in your living room over a period of time based on the data from two IoT sensors. Your program should rst request the name of a temperature text le. A text le called temp data.txt is provided that contains a number of sensor messages sent, with each line representing a distinct message. Each message contains a sensor name and a temperature value which are separated by commas. The program should read the temperature data into a suitable data structure. The temperatures for sensor 1 should then be added to a global sum total by the parent process, while a child process should be spawned to add the temperatures for sensor 2 to the same global sum total. After all the temperature samples have been processed, the average temperature should be calculated and printed by dividing the sum total by the number of samples. Assume that the specied text le is located in the same directory as your program. The average temperature value should be formatted to two decimal places. Implementation

The following steps show how your program should work: 1. Your program should rst request the name of a temperature text le. 2. It then reads the input le line by line and stores the temperatures in a suitable global data structure. 3. When the reading of the input le is complete, the program creates a new child process with the fork() function. 4. The parent process then sums up the temperature data from sensor 1 in a global variable. 5. At the same time, the child process sums up the temperature data from sensor 2 in the same global variable. 6. When the processing of the temperature data is complete, the program calculates and prints the average temperature by dividing the global sum variable by the total number of samples in the input le.

this is the example output (T :

image text in transcribed

and this is the text file :

LivingTemp1,17.8 LivingTemp2,17.9 LivingTemp1,18.1 LivingTemp2,18.2 LivingTemp1,18.5 LivingTemp2,18.6 LivingTemp1,19.0 LivingTemp2,19.0 LivingTemp1,19.5 LivingTemp2,19.6

user make run ./avg_proc Enter file name: temp_data.txt Average Temperature: 9.29

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago