Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone PLEASE help me with this program?? C Program: Your program should totally create exactly 3 new processes , each of which performs a

Can someone PLEASE help me with this program??

C Program:

  1. Your program should totally create exactly 3 new processes, each of which performs a different task.
  2. The root parent process prints both process IDs of its own and its parent, and generates one random integer in the range of 200~2000 by using the function rand(). Then print on the screen all the positive multiples of 33 that are no more than the generated random number.
  3. The first newly created process prints both process IDs of its own and its parent, create an array of integers and initialize it to {10, 20, 30, 40, 50, 60, 74, 89, 63}. Then calculates the average (stored in a float variable) of all the elements in the array, and outputs the average on the screen.
  4. The second newly created process prints both process IDs of its own and its parent, and generates 10 random integers in the range of 1000~2000 by using the function rand(). Then write these 10 random integers into an output file named data.txt (created by your program). This output file MUST be included in your project submission.
  5. The third newly created process prints its process ID, and reads the integers from an input file input.txt. The integers in the file are separated by a space. Then calculates the average (stored in a double variable) of all the integers in the file, and outputs the average and the number of integers on the screen (do NOT print all the integers to the screen in your final output).

Input.txt

80 60 79 61 78 62 5 100 90 21 47 568 18 17 27 160 8 15 9 200 15 212 13 20 4 13 51 19 6 14 10 13 12 11 5 30 21 29 22 28 23 27 24 26 35 45 36 44 37 43 38 42 5 9 41 40 90 51 89 52 87 53 86 54 85 25 50 31 49 32 48 33 47 34 46 155 84 56 83 15 57 82 58 81 59 97 80 90 100

readFromFile.c

// Reading from a sequential file #include

int main(void) { FILE *filePtr; // filePtr = input.txt file pointer // In C, a file is represented and accessed by a file pointer // FILE is a structure defined in

// fopen opens file; exits program if file cannot be opened if ((filePtr = fopen("input.txt", "r")) == NULL) { puts("File could not be opened"); } else { // file opened successfully int number; // store the integer read from the input.txt

// while not end of file while (!feof(filePtr)) {// The function int feof(FILE *stream) tests the // end-of-file indicator for the given data stream fscanf(filePtr, "%d", &number); printf("%d ", number); } fclose(filePtr); // fclose closes the file } }

writingToFile.c

// Creating and writing to a sequential file #include

int main(void) { FILE *filePtr; // filePtr = output.txt file pointer

// fopen() opens the file or creates the file if it does not exist // exit program if unable to create file if ((filePtr = fopen("output.txt", "w")) == NULL) { puts("File could not be opened"); } else { // File created or open successfully fprintf(filePtr, "%s 's age is %d ", "Smith", 20); } fclose(filePtr); // fclose() closes the file }

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions

Question

5. Describe the relationship between history and identity.

Answered: 1 week ago