This Assignment Is to Introduce You to the Concept of Input/Output, Conditional, Loop
Total Page:16
File Type:pdf, Size:1020Kb
Assignment 2 COMP 1002/1402A - SUMMER 2008 Due: Saturday July 26th at 11:55pm
This assignment is to introduce you to the concept of input/output, conditional, loop statements, type declaration, library functions, and user-defined functions in C. It is also to provide you with experience in dealing with useful commands in Unix. You MUST submit your solutions through RAVEN in accordance with the rules specified in the course outline. Answers to all questions should be organized neatly into a single easy-to-follow report document. Include a readme.txt file in your Raven submission, if there are any special instructions for the TA. You should submit the source codes and any other files required to compile and run your program for part 1. For part 2, write your commands with the same order in a doc format file. [Total 30 marks]
Part 1. Design and implement a program to calculate functions as follow, for input numbers from 1 to N (use N=5), and then print the results in a suitable table. You can use C library functions such as: sqrt, cbrt, log, and exp to calculate the roots, but not for calculating the powers: [14 marks, 2 marks each] 1. int square (int N) {//find square of N (N*N)} 2. int cube (int N) {//find cube of N (N*N*N)} 3. int quartics (int N) {//find quartics of N (N*N*N*N)} 4. float square_root (int K) {//find square root of K} 5. float cube_root (int K) {//find cube_root of K} 6. float quartic_root (int K) {//find quartic_root of K} 7. void show() {//print the above results in an organized table} Create a Makefile to compile your program and to produce the relevant executable file. Your Makefile should be written in a way to minimize the amount of compilation, link, and loading for your program. For example if you edited one of the files (in case of having different files in your program) it should not cause the re-compilation of the other files. Also use “clean” target in your Makefile to remove the un-used object (*.o) files. [1 mark] Part 2. Use the man pages to get details on the following commands and work on them to get the final results: [15 Marks] 1- Use pipes to combine the “ls” and “grep” commands to list all the directories in the current directory that have “rwx” permissions for all user, group, and other. 2- Use “tr” command to output the file “test.txt” all in uppercase. Redirect the output in “test-bak.txt”. 3- Use “grep” or “egrep” command to get a listing of all lines of file “test.txt” that contain only digits. 4- Use “chmod” command to change the permissions of “test.txt” so that it has “rwx” for user, no permission for group, and “x” for other. Write the same command with “chmod” using octal numbers to create permissions. 5- Use “find” command to print the full path name of all files (not directories) in your computer’s file system that have the name starting with “test*”. 6- Use pipes to combine ”tail” and “grep” commands to do the following: if string “Tutorial” is in the last 5 lines of file “test.txt”, then print the lines it is in. 7- Use pipes to combine “head”, “tail” and “grep” commands to do the following: if string “Tutorial” is in lines 11-17 of file “test.txt”, then print the lines it is in. 8- Use “ls” command to list the files in the current directory that are not java or text files (do not end in .java or .txt) 9- Use “echo” command and output redirection to create a file called “test2.txt” that contains only one line: “this is first line in test2.txt” 10- Use “echo” command and output redirection again to add a new line to test2.txt as: “this is second line in test2.txt” 11- Use “sort” command to sort the first two fields in file “test.txt” after character “*” (fields are separated with *) 12- Use “find” command to list all files in your current directory that have “c” extension and redirect the list in file “find.out” 13- Use pipes to combine “find” and “grep” commands to do the following: to print all lines in files “f*” (their names start with “f”) that contain the string “new”, in the current directory 14- Use pipes to combine “find” and “grep” commands to do the following: to print all file names starting with “f” in the current directory, whose names contains string “new” 15- Use pipes to combine “cat” and “grep” commands to do the following: print number of lines in “test1.txt” and “test2.txt” that contain string “helloc”