Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In an online banking application, the home process creates a shared memory which has a structure of: struct shared { char sel [ 1 0

In an online banking application, the home process creates a shared memory which has a structure of:
struct shared{
char sel[100];
int b;
};
The process then creates a pipe. Then it prompts input space for users and provides them to select options of their preferences according to the data given below.
Provide Your Input from Given Options:
1. Type a to Add Money
2. Type w to Withdraw Money
3. Type c to Check Balance
After reading selection from user input, the process stores the user input in the sel and sets b =1000 of structure shared where sel represents users selected task from the application and b represents current balance. Then it prints the selection as Your selection: selection and sends the data using shared memory and prints about the selection of the user.
After that, home is interrupted and another process which can be denoted by process opr which is a child process of home. Process opr receives and reads data from the shared memory and according to the user input data it executes some operations,
If, user input is a then, it provides users an input space to add money and after users enter the amount to be added it adds the amount with the current balance which is stored in b field of structure shared if the amount entered to be added by the user is a positive value greater than 0. After successful addition, it prints the acknowledgement of the operation and updated balance after addition. If the entered amount by the user is less than or equal 0 then it will print Adding failed, Invalid amount.
If, user input is w then, it provides users an input space to withdraw money and after users enter the amount to be withdrawn it withdraws the amount from the current balance which is stored in b field of structure shared if the amount entered to be withdrawn by the user is less than the current balance and a positive value greater than 0. After successful withdrawal, it prints the acknowledgement of the operation and updated balance after withdrawal. If the entered amount by the user is less than or equal 0 or it is less than the current balance then it will print Withdrawal failed, Invalid amount.
If, user input is c then, it prints the current balance which is stored in b field of structure shared.
For any other inputs opr process prints Invalid selection.
Finally before termination the process opr writes Thank you for using in the pipe and it terminates.
After the termination of its child opr, process home continues and reads the data from the pipe which was written by its child process opr and prints it. Then it terminates by removing the shared memory.
Provide a proper solution by executing two cooperating processes according to the flow of processes described in the scenario given above, ensuring proper communication between processes using shared memory.
Sample Output in the Terminal:
Execution Command in Terminal: ./p1
Provide Your Input From Given Options:
1. Type a to Add Money
2. Type w to Withdraw Money
3. Type c to Check Balance
a
Your selection: a
Enter amount to be added:
100
Balance added successfully
Updated balance after addition:
1100
Thank you for using
Execution Command in Terminal: ./p1
Provide Your Input From Given Options:
1. Type a to Add Money
2. Type w to Withdraw Money
3. Type c to Check Balance
a
Your selection: a
Enter amount to be added:
-600
Adding failed, Invalid amount
Thank you for using
Execution Command in Terminal: ./p1
Provide Your Input From Given Options:
1. Type a to Add Money
2. Type w to Withdraw Money
3. Type c to Check Balance
w
Your selection: w
Enter amount to be withdrawn:
600
Balance withdrawn successfully
Updated balance after withdrawal:
400
Thank you for using
Execution Command in Terminal: ./p1
Provide Your Input From Given Options:
1. Type a to Add Money
2. Type w to Withdraw Money
3. Type c to Check Balance
w
Your selection: w
Enter amount to be withdrawn:
-300
Withdrawal failed, Invalid amount
Thank you for using
Execution Command in Terminal: ./p1
Provide Your Input From Given Options:
1. Type a to Add Money
2. Type w to Withdraw Money
3. Type c to Check Balance
c
Your selection: c
Your current balance is:
1000
Thank you for using
Execution Command in Terminal: ./p1
Provide Your Input From Given Options:
1. Type a to Add Money
2. Type w to Withdraw Money
3. Type c to Check Balance
o
Your selection: o
Invalid selection
Thank you for using

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

1.Which are projected Teaching aids in advance learning system?

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago