Question: Please help me for this homework problem, thanks!! Review the lecture slides which discuss Very Simple Programming Languages (VSPL). Next, observe the VSPL defined below
Please help me for this homework problem, thanks!!
- Review the lecture slides which discuss Very Simple Programming Languages (VSPL). Next, observe the VSPL defined below and identify which sequences are valid.
| | ::= a | b | c | d | e |
| | ::= V | W | X | Y | Z |
| | ::= 0 | 1 | 2 | 3 | 4 |
| | ::= |
| | ::= |
| | ::= |
| | ::= |
Which of the following are valid sequences? You must clearly identify for each of the following sequences, which are valid and which are invalid. Each sequence is worth 1 point.
Submit your answer as hw02q1.pdf. [10 points]
- CSE204
- ebcXYZ125
- XYZcde344
- VWXa10
- edc135790Z
- dYaZeWkV
- Zbad00
- aZ21
- XYZabc23
- Ey701
- 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. Submit in a PDF file hw02q2.pdf.
For questions 2.1 and 2.2, submit your program as hw02q2.c file and the screenshot file as hw02q2.pdf(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
