100% Guaranteed Results


COMP5710 – Questions: Contact XIAOPU PENG Problem Descriptions: Solved
$ 20.99
Category:

Description

5/5 – (1 vote)

The purpose of this assignment is to reinforce the lecture material on program slice. For each of the source code fragments below, list the program slice for the variable indicated. (include the braces to make sure the program is executable.) Each problem is worth 50 points.

Problem 1:
For the following program, list the program slice by ONLY USING LINE NUMBERS for “average” in statement 26.

1. int exam() {
2. A = 0;
3. B = 0;
4. C = 0;
5. Fail = 0;
6. Count = 0;
7. TotalMarks = 0;
8. while (!eof()) {
9. scanf(“%d”, Mark);
10. if (Mark >= 90) {
11. A = A + 1;
12. } else if (Mark >= 80) {
13. B = B + 1;
14. } else if (Mark >= 60) {
15. C = C + 1;
16. }
17. if (Mark < 60){
18. Fail = Fail + 1;}
19. Count = Count + 1;
20. TotalMarks = TotalMarks + Mark;
21. }
22. printf(“Out of %d, %d passed and %d failed “, Count, A + B + C, Fail);
23. printf(“%d students got A”, A);
24. printf(“%d students got B”, B);
25. printf(“%d students got C”, C);
26. average = TotalMarks / Count;
27. printf(“The average was %d “, average);
28. PassRate = (Count – Fail) / Count * 100;
29. printf(“This is a pass rate of %d “, PassRate);
30. return 0;
31. }
Problem 2:
For the following program, list the program slice by ONLY USING LINE NUMBERS for “countEven” in statement 21.

1 #include<iostream.h>
2 void main(){
3 int countEven=0; 4 int countOdd=0;
5 int countZero=0;
6 int arr[10], i;
7 for(i=0; i<10; i++){
8 cin>>arr[i];
9 }
10 for(i=0; i<10; i++){
11 if(arr[i]%2==1){
12 countOdd++;
13 }
14 if(arr[i]==0){
15 countZero++;
16 }
17 if(arr[i]%2==0){
18 countEven++;
19 }
20 }
21 cout<<“Even Numbers = “<<countEven<<” “;
22 cout<<“Odd Numbers = “<<countOdd<<” “;
23 cout<<“Zero = “<<countZero<<” “;
24 }

Reviews

There are no reviews yet.

Be the first to review “COMP5710 – Questions: Contact XIAOPU PENG Problem Descriptions: Solved”

Your email address will not be published. Required fields are marked *

Related products