20 likes | 158 Vues
In this programming quiz, you'll create a header file (`header.h`) for two C modules (`file1.c` and `file2.c`). The first module reads a non-zero integer and an operation code, while the second module performs mathematical operations based on that code. You'll also write UNIX commands to compile the program, rename the executable to `quiz2`, enable debugging with GDB, and run the program using input redirection from an `input.txt` file, saving output to `my.output.txt`.
E N D
ENEE150 QUIZ 2 Spring 2012, Section 0202 You are writing a program which contains two modules, file1.c and file2.c, and a header file, header.h. The two .c modules are printed below. file1.c #include "header.h" int n1=0; int main() { int op, answer; printf("Enter non-zero integer and operation code: \n"); scanf("%i %i", &n1, &op); answer = compute(op); if(answer==INVALID_OPERATION) printf("INVALID\n"); else printf("answer = %i\n", answer); } file2.c #include "header.h" #define INVALID_OPERATION 0 int compute(int op) { if (op==1) return(n1*n1); else if(op==2) return(n1+n1); else return INVALID_OPERATION; }
1. In the box below, write the necessary header.h file for the code to compile and run properly. header.h Assume header.h, file1.c, and file2.c, and an input file, input.txt, all reside in the current directory. 2. Write the UNIX command that will compile the program, re-name the executable to quiz2, and enables the code to be debugged using GDB. 3. Write the UNIX command that will run the program with input.txt as the input, and redirect the output to a file called my.output.txt