Please implement this program in C++.
I am trying to use Unix system calls for creating processes and
inter-process communication to solve a problem. I will have three
related processes (the Parent, Child_1 and Child_2). I will also
have four pipes that will be used to provide IPC between these
processes to solve a problem.
The problem:
The main problem I am trying to solve is to generate some numbers
and identify if they are prime. However, the 3 processes will share
the work as follows:
1) Parent generates the numbers (e.g., numbers between 1 to 10) and
sends them to Child_1 via pipe-A.
2) Child_1 reads pipe A, and sends the even numbers back to Parent
using pipe B.
3) Child_1 sends the odd numbers to Child_2 for further processing,
using pipe C.
4) Child_2 read pipe C and checks the (odd) numbers arriving from
Child_1 to see if they are prime numbers, then uses pipe D to send
the prime numbers to the Parent for final printing. The remaining
odd numbers are ignored.
5) The Parent should read each pipe (pipe B) and (pipe D),
immediately display each number received, and also insert the
numbers in their own corresponding Template Stacks (Even_S and
Prime_S). Once both child processes have terminated, the parent
should pop and print each Stack.
#include<iostream.h>
using namespace std;
int prime(int );
int even(int);
class parent
{
public:
int n,p,i;
cout<<"\n enter up to given range";
cin>>n;
for(int i=2;i<=n;i++)
{
p=prime(i);
if(prime==true)
cout<<i<<" ";
}
return 0;
}
class child1 implements parent
{
public:
int prime(int i)
{
int p=true;
for(int j=2;j<=n/2;j++)
{
if(i%j==0)
{
p=false;
break;
}
}
return p;
}
int main()
{child ch=new child();
ch.prime();
}
output:
enter up to given range: 10
2 3 5 7
Please implement this program in C++. I am trying to use Unix system calls for creating...