[SOLVED] COMP5710 Homework 3

35.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (1 vote)

Problem Descriptions:
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:

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;
5 float testGrade, hwGrade;
6 printf(“Input the values for test grade and homework grade : “);
7 scanf(“%f %f”,&testGrade,&hwGrade);
8 float finalGrade = testGrade * testWeight + hwGrade * (1-testWeight);
9 if( finalGrade >= 90 ){
10 printf(“test grade %f homework grade %f result an A. “, testGrade, hwGrade);} 11 else if( finalGrade >= 80 && finalGrade < 90){
12 printf(“test grade %f homework grade %f result an B. “, testGrade, hwGrade);} 13 else if( finalGrade >= 70 && finalGrade < 80){
14 printf(“test grade %f homework grade %f result an C. “, testGrade, hwGrade);}
15 else if( finalGrade > =60 && finalGrade < 70){
16 printf(“test grade %f homework grade %f result an D. “, testGrade, hwGrade);}
17 else{
18 printf(“test grade %f homework grade %f result an F. “, testGrade, hwGrade);}
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;
27 cout << Swimming;
28 running = goal / runCa;
30 cout << running;}
31 return 0;
32 }

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.