The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Write a C program Sort.c that performs a merge sort on 2
number sequences produced by the program in Q1. Sort.c
should spawn 2 processes and each of the children processes
would exec() the Gen program to produce a sequence.
Sort.c should also specify the filenames for the number
sequences when spawning the children processes. The parent
process should then wait for the termination of the children
processes and perform a merge sort on the 2 data files. The
final sorted sequence is written to the file "Sort.out".
Â
COMP 340, Fall 2014Instructor: Dan HarrisAssignment #2Date: March 17, 2016Due on March 2, 2016.* late assignment will be graded-down progressively by10% for each day late.Q1. Write a C program Gen.c that generates a ordered sequenceof 20 random numbers within a range of 1000 to 9999. Theprogram is invoked by a command line% gen datfile1In the above line, gen is the executable, datfile1 is theargument to the execution of gen. It specifies the name ofthe output file for the 20 random numbers.To make Gen.c possible, your main() program should acceptarguments like#include <stdio.h>void main (int argc, char *argv[]){char *fname = argv[1];....fp = fopen(fname,"w");....Q2. Write a C program Sort.c that performs a merge sort on 2number sequences produced by the program in Q1. Sort.cshould spawn 2 processes and each of the children processeswould exec() the Gen program to produce a sequence.Sort.c should also specify the filenames for the numbersequences when spawning the children processes. The parentprocess should then wait for the termination of the childrenprocesses and perform a merge sort on the 2 data files. Thefinal sorted sequence is written to the file "Sort.out".The algorithm for merge sort could be roughly described as1. read num1 from datafile12. read num2 from datafile23. write the smaller between num1 and num2 to output4. "refill" num1 or num2 according to which one has beenoutputted in step(3).5. repeat (3) and (4) until both files are exhausted.END.
Attachments: