We are going to write a calculator program to compute math equations using pipes
ID: 3570486 • Letter: W
Question
We are going to write a calculator program to compute math equations using pipes - program needs to fork() as many times as needed and use pipes to communicate to children. Equation specified in the first line of the data file will determine this setup. Once the setup is done, parent task reads the data from the data file and pumps into various pipes in parallel and results come back to main task using another pipe.
All tasks use standard input stream 0 to read the first argument, use stream 3 to read 2nd argument and use standard output stream 1 for output. Main task uses the pipe stream numbers directly since it needs standard I/O streams to communicate with the user.
Here is an example: configuration diagram for computing "a - b * c" looks like the following. Note that the whole equation is processed left to right. No need to worry about operator precedence since that is not our focus here.
Sample data file content: a - b * c; 30 20 2; 500 10 20; 90 1 10
Usage: calculator < data.txt. Expected output: 20, 9800, 890
Parent task can close the pipes when eof is reached for input file. When eof is detected in the pipe that brings the results in, parent task can quit.
}
Explanation / Answer
~veerasam was here
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.