[computer science] c programming

sehj
a11.pdf

COMP 2160 Programming Practices

Assignment 1

Page 1 of 1

Due Date: February 3rd at 11:59pm

OBJECTIVES Familiarization with C

NOTES  Please read and follow instructions carefully; not doing so will result in a loss of marks.  You must complete Honesty Declaration form digitally in UMLearn.  Your code must follow the programming standards (available in UMLearn).  You can write your code on any machines; remember to verify your code on the macOS systems

(lab machines).  You must include a README file which describes how to compile and run your solution. You can

also explain your concerns or personal opinions regarding this assignment.  Use submission tool (handin) in CS Unix system as described in Assignment Submission

Guidelines (available in UMLearn).

QUESTION 1 Convert LongWord.java to the equivalent C program named longword.c. While you are converting it into C, make following changes:

 file read and write: read lines from standard input and print the results to standard output  string return in getLongestWord: take a pointer to a pre-allocated buffer and save the longest

word in it. Hint: your function will look like void getLongestWord( const char line[], char word[] )

That is, your converted C program should continuously read lines from standard input, find the longest word using the function getLongestWord, and print the results to standard output. The program ends when it hits EOF. Make sure that your converted C program generates the same output to the Java program’s.

QUESTION 2 Convert MergeSort.java to the equivalent C program named mergesort.c.

 define your own boolean type instead of using integer as Boolean  use C random function provided in stdlib.h

o initialize using srand( time( NULL ) ); // you need to include time.h as well o get next random integer using rand( );

Again, the C program should generate the same output to the Java program’s. (Hint: use diff tool to check)