Sale!

# COMP 5710 Assignment 3 solved

Original price was: \$35.00.Current price is: \$30.00.

Category:

## Description

Problem Descriptions:
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:
1. int main() {
2. char operator;
3. double 1stNum, 2ndNum;
4. printf(“Enter an operator (+, -, *,): “);
5. scanf(“%c”, & operator);
6. printf(“Enter two operands: “);
7. scanf(“%lf %lf”, & 1stNum, & 2ndNum);
8. if (operator == ‘+’) {
9. printf(“%.1lf + %.1lf = %.1lf”, 1stNum, 2ndNum, 1stNum + 2ndNum);
10. } else if (operator == ‘-‘) {
11. printf(“%.1lf – %.1lf = %.1lf”, 1stNum, 2ndNum, 1stNum – 2ndNum);
12. } else if (operator == ‘*’) {
13. printf(“%.1lf * %.1lf = %.1lf”, 1stNum, 2ndNum, 1stNum * 2ndNum);
14. } else if (operator == ‘/’) {
15. printf(“%.1lf / %.1lf = %.1lf”, 1stNum, 2ndNum, 1stNum / 2ndNum);
16. } else {
17. printf(“Error! operator is not correct”);
18. }
19. return 0;
20. }
DEF –USE Table:
Variable DEF USE
operator 2, 5 8, 10, 12, 14
1stNum 3, 7 9, 11, 13, 15
2ndNum 3, 7 9, 11, 13, 15
DU Path Table:
Variable # DU Path
operator 1 5-6-7-8
2 5-6-7-8-10
3 5-6-7-8-10-12
4 5-6-7-8-10-12-14
1stNum 1 7-8-9
2 7-8-10-11
3 7-8-10-12-13
4 7-8-10-12-14-15
2ndNum 1 7-8-9
2 7-8-10-11
3 7-8-10-12-13
4 7-8-10-12-14-15
Problem 1
1 #include <stdio.h>
2 void main()
3 {
4 float testWeight=0.5;
6 printf(“Input the values for test grade and homework grade : “);
9 if( finalGrade >= 90 ){
17 else{
19 }
Problem 2
1 int main() {
2 double running;
3 double runCa;
4 double swimming;
5 double swimCa;
6 double goal;
7 double totalCa;
8 cout << “How long did you run? (in minutes) “;
9 cin >> running;
10 cout<<”How many the calories from running 1 minute?”
11 cin>>runCa;
12 cout << “How long did you swim? (in minutes) “;
13 cin >> swimming;
14 cout << ” How many calories from swimming 1 minute? “;
15 cin >> swimCa;
16 cout << “What’s your goal for today? (in calories)”;
17 cin >> goal;
18 totalCa = swimming * swimCa + running * runCa;
19 if (totalCa >= goal){
20 cout << “Take a break for the rest of your day.”}
21 else {
22 goal = goal – totalCa;
23 cout<<”Your left work towards today’s goal is:”;
24 cout<<goal;
25 Swimming = goal / swimCa;
26 cout << “Minutes you may swim: ”;
27 cout << Swimming;
28 running = goal / runCa;
29 cout << “Minutes you may run:”;
30 cout << running;}
31 return 0;
32 }