here are x number of sections in a course. In each section y number of quizzes a
ID: 3770307 • Letter: H
Question
here are x number of sections in a course. In each section y number of quizzes are conducted. The average for each quiz in all the sections need to be found out. To solve this, write program which has the main process as Director process, which reads a file containing marks of all quizzes of all sections and creates x number of Manager processes. Each Manager process will take care of solving for a section. Each manager process will create y number of worker process and pass one quiz to each of them and they calculate and print the average.
Read x and y as input from the user. All quizzes are graded out of 20 points. Assume the number of students in all the sections is same and it is 10 per section. The input file should contain the data according to the value of x and y.
The input text file will look like the following: [for x=2 and y=2]
Explanation / Answer
#include //Always use meaningful names for types typedef unsigned char boolean; #define True 't' #define FALSE (!True) //this is a really neat trick for swapping values efficiently void swap(long* a,long *b) { *a=*a^*b;*b=*b^*a;*a=*a^*b; } //Here's a readability improvement #define until(condition) while(!(condition)) int main(int n, char*args[]){ double *d; int i; char input[5]; //should be long enough for most doubles. boolean sorted = FALSE; //In C, you need to specify the array size beforehand, so ask printf("Please enter the length of the array "); gets(input); //scan the input string and convert to a value sscanf(input,"%s",&input[0]); n=(long)atol(input); //allocate space, make sure you get the order of arguments right. d = calloc(sizeof(double),n); //Get and sort the array until (sorted) { for (i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.