Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribedimage text in transcribed

(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 file

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

Step: 3

blur-text-image

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

The Nature of Language

Answered: 1 week ago

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago