Assume that there will be an object file named “sub.o\" which implements a funct
ID: 3629459 • Letter: A
Question
Assume that there will be an object file named “sub.o" which implements a functionwhose prototype is given in the header file sub.h". The header file sub.h" consists of the following line.
int sub(int n, int *A, int *B);
However, you do not know what this function is doing. For your testing purpose, you may produce such a function, e.g., returning the maximum value among the 2n integers in the two arrays.
You are also given an ASCII file named input.txt". The first line of this file contains an integer
n. There are n additional lines in the file, where the ith additional line contains two integers xi and yi. A sample of "input.txt" is the following.
5
1 2
3 4
5 6
7 8
9 10
You need to write a driver that does the following:
1) Open an input file (for reading) named input.txt". You program should output an error message and stop, if the file does not exist in the current directory.
2) Read the first integer in the file into an integer var named n.
3) Dynamically allocate memory for an array A of size n, and an array B of size n.
4) Read data from the input file into the arrays, so that A[i - 1] = xi and B[i - 1] = yi for
i = 1; 2; …., n.
5) Close the input file.
6) Open an output file (for writing) named output.txt".
7) Write n into the output file (in the first line). Then write A[i] and B[i] in the next line, for
i = 0; 1; : : : ; n - 1.
8) Call the function sub by the command
result = sub(n, A, B);
9) Write the value of result into the output file.
10) Close the output file.
11)Stop.
If the function “sub" returns the maximum among the 2n array elements, the file “output.txt"
corresponding to the sample “input.txt" will be:
5
1 2
3 4
5 6
7 8
9 10
10
Besides writing the source code of the driver, you also need to create a makeFile named “Make-
file". The make¯le should produce an executable file named “proj1". You should submit (in one
tar file) the file MakeFile", “sub.h", and the source code of your driver, which is either “main.c"
or “main.cpp".