CS962 Assignment 1
CS962 Assignment 1
Synopsis
$ ./double root double root square integer_number operation_offset
Example 1
$ ./root square double 4 0
8
Since, the order of the operations in the chained pattern is from left to right and offset is 0.
Hence, the chained pattern should be viewed as, starting with square:
double(square(root(4))) = 8
Example 2
$ ./square root double root 8 2
4
The order of the operations in the chained pattern is from left to right and offset is 2. Hence,
the chained pattern should be viewed as, starting with double:
root(square(root(double(8)))) = 4
Example 3
$ ./square root double 4 1
16
The order of the operations in the chained pattern is from left to right and offset is 1. Hence,
the chained pattern should be viewed as, starting with root:
square(double(root(4))) = 16
Output
Print the final result only (as shown in the example).
1
Note
• At least 1 unary operation and utmost 100 unary operations will be specified during
testing.
• You can assume that the result of operations will always fit in unsigned long long data
type.
• If square root of number is a fraction then round off the result to the nearest integer, e.g.
2.5 should be rounded to 3 and 2.4 should be rounded to 2. This needs to be done every
time square root is performed. For example: Answer for chain of operations done below
will be 8.
Error handling
In case of any error print “UNABLE TO EXECUTE” as output.
- fork - malloc
- exec* family - free
- str* family - exit
- ato* family - wait/ waitpid
- printf, sprintf - sqrt
- round
Testing
Run the script Part1/run tests.sh for running the provided sample test cases which contains
3 test cases. A sample output after running the script would be:
Test 1 is Passed
Test 2 is Passed
Test 3 is Passed
2
dir1
dir11
file11.txt
file12.txt
dir12
dir21
file23.txt
file21.txt
file22.txt
file1.txt
file2.txt
Syntax
$./task2 <relative path to a directory> <size in KB> <file type integer>
You can use the below mentioned APIs to implement this part of the assignment. Refer to
man page of these APIs to know about their usage.
3
dir1 (4096 B)
dir11 (4096 B)
file11.txt (2285 B)
file12.txt (0 B)
dir12 (4096 B)
dir21 (4096 B)
file23.txt (3351 B)
file21.txt (161918 B)
file22.txt (209340 B)
file1.txt ( 39 B)
file2.txt ( 59 B)
Example
Figure 2 shows the structure of a directory called dir1 (present in the path /home/os/Docu-
ments) with size of each file in Bytes
Output
The listing 2 list the desired output for directory structure shown in the figure 2
Implementation
• Navigate to the Part2 folder of code base, there is a find task1.c find task2.c, and
find task3.c files. You should implement each task in the corresponding files.
• The testcase folder contains the dir1 directory for testing the output of your program.
5
3 Submission
• Make sure that your implementation doesn’t print unnecessary data. Your output should
match exactly with the expected output specified in each question.
• You have to submit zip file named your roll number.zip Eg: 12345.zip containing only
the following files in specified folder format:
12345.zip
|
|------ 12345
|------- Part1
| |----- square.c
| |----- double.c
| |----- root.c
|
|-------- Part2
|----- find_task1.c
|----- find_task2.c
|----- find_task3.c
• Your submission will be evaluated on a recent Linux distribution (Ubuntu 22.04) with
GCC compiler
• Include a README report describing the instructions for compiling and executing the
program
• Use of Boost library is not allowed. Boost is not part of the standard C/C++ distribution