Question: Please help me for this homework problem, thanks!! I know as the chegg policy, Multiple questions are posted. answered the first one. So please answer
Please help me for this homework problem, thanks!!
I know as the chegg policy, Multiple questions are posted. answered the first one.
So please answer 2.2 (if you answer 2.1 and 2.2 will be perfect, but 2.1 is need for 2.2, so I post all the material, thanks!)
- Read text section 1.4.2. Macros are available in most high-level programming languages. The body of a macro is simply used to replace a macro-call during the preprocessing stage. A macro introduces a "true inline" function that is normally more efficient than an "outline" function. However, macros suffer from the side-effect, unwanted, or unexpected modifications to variables. Macros should be used cautiously. The main purpose of the following programs is to demonstrate the differences between a function and a macro. Other purposes include demonstrating the differences between different programming environments, and learning different ways of writing comments, formatted input and output, variable declaration and initialization, unary operation ++, macro definition/call, function definition/call, if-then-else and loop structures, etc.
Observe each of the functions below and understand their functionality. You can use either
GNU gcc under Unix or Visual Studio to implement the code in this question
int subf(int a, int b) {
return a - b;
}
int cubef(int a) {
return a * a * a;
}
int minf(int a, int b) { if (a
return a;
}
else {
return b;
}
}
int oddf(int a) { if (a % 2 == 1) { return 1;
}
else {
return 0;
}
2.1 Write four macros to re-implement the given four functions. Name them: subm, cubem, minm, and oddm, respectively. [10 points]
2.2 Make a C file hw02q2.c having the four functions and four macros defined in previous question. Write a main() function to test these functions and macros. Use the following test cases in the main() to call your functions and macros in this order and observe the results: [5 points]
a = 3, b = 6; subf(a, b); subm(a, b); subf(a++, b--);
a = 3; b = 6; // reset a,b values subm(a++, b--);
a = 3; b = 6; cubef(a); cubem(a); cubef(--a); a = 3; b = 6; cubem(--a);
a = 3; b = 6; minf(a, b); minm(a, b); minf(--a, --b); a = 3; b = 6;
minm(--a, --b);
a = 2; b = 6; oddf(a); oddm(a); oddf(a++); a = 2; b = 6; oddm(a++);
You must insert print statements to print answer of every function call and macro above, so that the expected output looks like the following:

Your output should have actual answers, not zeros! Take a screenshot of the output. Mark the lines in color where the function-macro pair gives different results, like oddf(a++) and oddm(a++) in figure above. (show code please, thanks!)
subf(a, b) = 0 subm(a, b) = 0 subf(a++, b--) = 0 subm(a++, b--) = 0 cubef(a) = 0 cubem(a) = 0 cubef--a) = 0 cubem(--a) = 0 minf(a, b) = 0 minm(a, b) = 0 minf(--a, --b) = 0 minm(--a, --b) = 0 oddf(a) = 0 oddm(a) = 0 oddf(a++) = 0 oddm(a++) = 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
