Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(temp_data.txt) 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 LivingTemp1,20.0 LivingTemp2,20.1 LivingTemp1,20.6 LivingTemp2,20.6 LivingTemp1,19.8 LivingTemp2,19.8 LivingTemp1,19.4 LivingTemp2,19.5 LivingTemp1,19.0 LivingTemp2,19.1 LivingTemp1,18.5 LivingTemp2,18.6 LivingTemp1,18.0 LivingTemp2,18.1
(temp_data.txt)
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 LivingTemp1,20.0 LivingTemp2,20.1 LivingTemp1,20.6 LivingTemp2,20.6 LivingTemp1,19.8 LivingTemp2,19.8 LivingTemp1,19.4 LivingTemp2,19.5 LivingTemp1,19.0 LivingTemp2,19.1 LivingTemp1,18.5 LivingTemp2,18.6 LivingTemp1,18.0 LivingTemp2,18.1
Task 1.1 3 Marks Write a C++ program called avg-proc.cpp that calculates the average temperature in your living roo over a period of time based on the data from two IoT sensors Your program should first request the name of a temperature text file. A text file 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 while a child process shoulkd 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 specified text file is located in the same directory as your program. The average temperature value should be formatted to two decimal places process Implementation The following steps show how your program should work: 1. Your program should first request the name of a temperature text file 2. It then reads the input file line by line and stores the temperatures in a suitable global data structure 3. When the reading of the input file 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 variablie 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 fileStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started