Answer to Question #161336 in C++ for Kefilwe Mamabolo

Question #161336

1. Write the exact output of the following algorithms:

1.1. Function calcValues(valX, valY)

 return (valX + valY/2)

JustValues

 a = 14

 b = 5

 totResults = 0

 for x = 1 to 5 step 3

 results = calcValues(a, b)

 totResults = totResults + results 

 next x

display “The result is” , totResult

display “The result is” , x

1.2 Function calculate (valX, valY)

 answer = valX + valY

 return answer

JustCalculations

a = 14

 b = 5

do while a < 5

 r = calculate(a, b)

 b = a + 5

 a = a + 1

 display “a =” , a, “b =” , b, “r=” , r

loop

end

1.3.1 sub calcProc (valA, refB)

value = valA * 3

refB = value - refB

End sub

Function calcFunc (valK)

return ((valK * 2) MOD 4)

MainModule

M = 4

L = 1

K = 2

do

J = CalcFunc (M)

Call CalcProc (J, K)

Display “L = “ L, “J = “ J, “K = “ K, “M = “ M

M = M + 1

Loop Until M > 5

end


1
Expert's answer
2021-02-04T13:49:11-0500

1.1

#include <iostream>
using namespace std;
float calcValues(int valX, int valY) {
    return valX + float (valY / 2.0);
}
int main () {
    int a = 14, b = 5, x;
    float totResult = 0, results;
    for (x = 1; x <= 5; x += 3) {
        results = calcValues(a, b);
        totResult += results;
    }
    cout << "The result (totResult) is: " << totResult;
    cout << "\nThe result (x) is: " << x;
}


1.2

#include <iostream>
using namespace std;
int calculate (int valX, int valY) {
    int answer = valX + valY;
    return answer;
}
int main () {
    int a = 14, b = 5, r;
    do {
        r = calculate(a, b);
        b = a + 5;
        a = a + 1;
    } while (a < 5);
    cout << "a = " << a << "\tb = " << b << "\tr = " << r;
}


1.3.1

#include <iostream>
using namespace std;
int calcProc (int valA, int refB) {
    int value = valA * 3;
    refB = value - refB;
}
int calcFunc (int valK) {
    return (valK * 2) % 4;
}
int main () {
    int M = 4, L = 1, K = 2, J;
    do {
        J = calcFunc(M);
        calcProc(J, K);
        cout << "L = " << L << "\tJ = " << J << "\tK = " << K << "\tM = " << M;
        M = M + 1;
    } while (M > 5);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog