Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write two versions (pipe version and shared memory version) of an interprocess c

ID: 3710325 • Letter: W

Question

write two versions (pipe version and shared memory version) of an interprocess communication program (A8p2_pipe.c, A8p2_shm.c or A8p2_pipe.cpp A8p2_shm.cpp) in C or C+t. Each version should create two processes using fork. One of them (the sender process) should send four intergers ab.cd in the range from 0 to 99 inclusive (that are interpreted as the coordinates of two points A,B in the plane A(ab) and BGd)) to the other (the receiver process). The sending process should printout the coordinates of the two points ACa.b) and B(cd). The receiving process should priutout the Manhattan distance between the two points A(ab) and B(Gd). Refer to https://en.wiktionary.org/wiki/Manhattan distance for the definition of Manhattan distance d(A,B) la-c+lb-dl. (30 points) Sample runs of the programs in 1 & 2 are shown below.| 'templ$ /A8p1 Hello am the child. Printing the Lower case version: hello an the parent. Printing the upper case version: HELLO child sent the coordinates of two points: A(9,44) and 8(67,87) parent process received the coordinates of two points: A(9,44) and 8(67,87) The Hanhattan distance between the two points is 58+43-101 parent sent the coordinates of two points: A(45,73) and 8(38,64) child received the coordinates of two points: A(45,73) and B(38,64) The Manhattan distance between the two points is 7+9-16 /templ$ /A8p2_shm templs ./A8p2 pipe

Explanation / Answer

#include<iostream>
//#include<conio>

using namespace std;
void coord(float a,float b,float c,float d)
{
float m,n,manh_dist;
m=a-c;
n=b-d;
  
if(m<0)
{
m=m*(-1);
}
else if(n<0)
{
n=n*(-1);
}
  
manh_dist=m+n;
cout<<manh_dist<<endl;
}


int main()
{
float a,b,c,d;
float s;
//clrscr();
cout<<"Enter coordinates of A: "<<endl;
cout<<"Enter 1st point (a): ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd point (b): ";
cin>>b;
cout<<endl;
cout<<"Enter coordinates of B: "<<endl;
cout<<"Enter 1st point (a'): ";
cin>>c;
cout<<endl;
cout<<"Enter 2nd point (b'): ";
cin>>d;
cout<<endl;
cout<<endl;

cout<<"Coordinates of point A("<<a<<","<<b<<")"<<endl;
cout<<"Coordinates of point B("<<c<<","<<d<<")"<<endl;

coord(a,b,c,d);
//getch();
}