The producer program in this lab produces 10 random integer numbers. The numbers
ID: 3699218 • Letter: T
Question
The producer program in this lab produces 10 random integer numbers.
The numbers range in value from 3 to 7.
Each random number will be output separated by a space.
Sample output is shown below:
3 5 3 7 3 7 3 4 3 4
Write a program to receive each of the random numbers generated by the producer and create a histogram with a bargraph to display the frequency of the numbers received.
Pipe the output of the producer program into the consumer program as follows:
On 32-bit linux:
./Prod32bitOS.out | ./Cons32bitOS.out
On 64-bit linux:
./Prod64bitOS.out | ./Cons64bitOS.out
HINT: Use scanf in the receiver to get the numbers.
Sample Output:
Values Received: 4, 4, 6, 6, 6, 7, 7, 3, 6, 5
----- HISTOGRAM -----
3: *
4: **
5: *
6: ****
7: **
END OF PROGRAM RUN
The producer program in this lab produces 10 random integer numbers.
The numbers range in value from 3 to 7.
Each random number will be output separated by a space.
Sample output is shown below:
3 5 3 7 3 7 3 4 3 4
Write a program to receive each of the random numbers generated by the producer and create a histogram with a bargraph to display the frequency of the numbers received.
Pipe the output of the producer program into the consumer program as follows:
On 32-bit linux:
./Prod32bitOS.out | ./Cons32bitOS.out
On 64-bit linux:
./Prod64bitOS.out | ./Cons64bitOS.out
HINT: Use scanf in the receiver to get the numbers.
Sample Output:
Values Received: 4, 4, 6, 6, 6, 7, 7, 3, 6, 5
----- HISTOGRAM -----
3: *
4: **
5: *
6: ****
7: **
END OF PROGRAM RUN
Explanation / Answer
Please find my code:
//this is the producer program
//as not specified language of code
//I write this code in c
//save this as Prod64bitOS.c
//after that do the same for the Cons64bitOS.c
//and then compile and run as shown in the output image
//below is the image of two code and the code itself
//Prod64bitOS.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int min = 3, max = 7, total = 10;
// Use current time as seed for random generator
//for pseudo random number generator
srand(time(0));
int i;
for (i = 0; i < total; i++) {
int num = rand() % (max -min + 1) + min;
printf("%d ", num);
}
return 0;
}
//SECOND PROGRAM
//Cons64bitOS.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
//In this program consumer program which reads the
//pipelined data i.e; data send by the Producer program
//As the input is read usign the stdin function
//as we know the numbers is only between 3 and 7
//so we make a array which stores the number of
//occurences of particular digit
//initlialize the hash array with 0 value
int hash[10]={0};
int num,i;
printf("Values received:");
//for reading the data and updating the hash array
while(scanf("%d",&num)!=EOF){
printf("%d, ",num );
hash[(int)num]+=1;
}
printf(" -----HISTOGRAM----- ");
//for printing the output
for(i=3;i<=7;i++)
{
printf("%d: ",i );
int j=hash[i];
while(j--){
printf("*");
}
printf(" ");
}
printf("END OF RUNNING PROGRAM ");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.