Question: Example of how the format should look. I need help with problem 2 below The purpose of this assignment is to reinforce the lecture material

Example of how the format should look. I need help with problem 2 below



The purpose of this assignment is to reinforce the lecture material on variable definition /usage and DU path. For each of the source code fragments below: 1) Construct a table listing all the line numbers where a variable is defined or used. You must list all the variables in each source code fragment. 2) Construct a DU Path table showing all paths from any definition to usage of every variable. A sample example is given below: int main() { 1. 2. char operator; 3. double 1stNum, 2ndNum; 4. printf("Enter an operator (+, -, *,): "); 5. scanf("%c", & operator); 6. printf("Enter two operands: "); 7. scanf("%f %1f", & 1stNum, & 2ndNum); 8. if (operator == '+) { 9. printf("%.11f + %.11f = %.11f", 1stNum, 2ndNum, 1stNum + 2ndNum); 10. } else if (operator == '-') { 11. printf("%.11f - %.11f = %.11f", 1stNum, 2ndNum, 1stNum - 2ndNum); 12. } else if (operator == '*') { 13. printf("%.11f * %.11f = %.11f", 1stNum, 2ndNum, 1stNum * 2ndNum); 14. } else if (operator == '/') { 15. printf("%.11f / %.11f = %.11f", 1stNum, 2ndNum, 1stNum / 2ndNum); 16. } else { 17. printf("Error! operator is not correct"); 18. } 19. return 0; 20. } DEF-USE Table: Variable operator DEF 2,5 USE 8, 10, 12, 14 1stNum 2nd Num 3,7 3,7 9, 11, 13, 15 9, 11, 13, 15 DU Path Table: # Variable operator # 1 2 3 4 1 1stNum 2. 3 DU Path 5-6-7-8 5-6-7-8-10 5-6-7-8-10-12 5-6-7-8-10-12-14 7-8-9 7-8-10-11 7-8-10-12-13 7-8-10-12-14-15 7-8-9 7-8-10-11 7-8-10-12-13 7-8-10-12-14-15 2nd Num 3 4 1 2 3 4 2 3 4 7 8 9 Problem 2 1 int main() { 2 double running: double runca; double swimming; 5 double swimca; double goal; double totalca; cout > running: 10 cout>runca; 12 cout > swimming; 14 cout > swimCa; 16 cout > goal; 18 totalCa = swimming * swimCa + running * runca; 19 if (totalca >= goal) cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
