Question: Task 1 : Lets Do Some Calculation ! ! ! ! Client - Server Calculator [ 3 0 Points ] In this task, you need

Task 1: Lets Do Some Calculation !!!! Client-Server Calculator [30 Points]
In this task, you need to implement a client-server based calculator. The client can submit any number
of queries (i.e. mathematical expressions) to the server. The server will evaluate the client's queries
one by one and send back the answer as a response.
In this task, the main process will call fork to create a child process where child process acts as the
server and the parent (main process) acts as client. The server will respond to all queries submitted by
the client until it receives a specific terminating word (mentioned below) as a query from the client.
After receiving the specific terminating word, the server will close the communication channel and
exits. You need to use pipe to establish a communication channel between client and server.
Figure 1: Workflow of client-server based calculator.Figure 1 shows the workflow of this client-server based calculator using pipes. The client (parent)
should read expression (or may be terminating word) from standard input device, and will display
result received from the server on standard output device as shown in the figure.
Requirement specifications for this task are as follows:
Input expression is always space separated, i.e. blank space between operand and operator.
Input expression always starts with an operand.
Input expression can have at most 20 operands (i.e., it can have at most 19 operators).
Operands in input expression may be an integer or float/double number.
Input expression can contain any combination of these five operators viz. (i) Addition (+),(ii)
Subtraction (-),(iii) Multiplication (*),(iv) Division (/), and modulo (%).
When server performs calculation, it needs to follow BODMAS rule where division, multiplication
and modulo operators are at same precedence (say precedence-1) and addition and subtraction
are at precedence-2. According to BODMAS, server should first perform precedence-1 operations
followed by precedence-2 operations. Among same precedence operations, server should perform
operation from left to right.
When client receives END word from STDIN, it should send a termination signal to the server to
terminate it properly.
On receiving the result of mathematical expressions from the server, client should print "RESULT:
"followed by result. As an example, if client receive 5 from the server, then it should display
"RESULT: 5" on STDOUT.
Example of Input & Output:
[INPUT]1+5**2-1+10
[OUTPUT] RESULT: 20
[INPUT]5+1-2**5+10
[OUTPUT'] RESULT: 6
[INPUT] END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!