Question

In: Computer Science

What will be the values of A, B, C and D after execution of the following...

What will be the values of A, B, C and D after execution of the following procedure using the “Scores”

dataset?

Note: Consider fractions up to 2 decimal places e.g. 10 / 3 = 3.33, 20 / 3 = 6.67

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Maintain five variables A, B, C, D, percentage and initialize them to 0

Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. Calculate percentage: divide TOTAL marks by 3 and store the result in percentage

Step 6. If percentage ≥ 85 then increment A

Step 7. If percentage < 85 and percentage ≥ 70 then increment B

Step 8. If percentage < 70 and percentage ≥ 60 then increment C

Step 9. If percentage < 60 then increment D

Step 10. Move the current card to another pile called Pile 2 and repeat from step 3

Solutions

Expert Solution

I am writing the code in C++ and i will use stack for database or storing pile's data I am pasting the code here and in the line after this // i will explain that line:

I am explaing the logic what to do, first of all we have to create data list where we can store our score then one by one we need to take data and do operation for calculating percentage then increment of A,B,C,D variable then we will store that store into second data list we will run this program until pile1 will empty.

Program code:

#include<iostream>

#include<stack>       // to create a stack it is neccessary to add stack header file in the program.

using namespace std;

int main()

{

    stack <int> pile1;     // intializing first stack with name of pile1.

    stack <int> pile2;     //intializing second stack with name of pile2

    int A=0,B=0,C=0,D=0,percentage=0; // declaring these variable according to question.

    float fraction;     // one more variable for storing fraction value

    pile1.push(280);   // now adding score in pile1 list.

    pile1.push(210);

    pile1.push(270);

    pile1.push(180);

    pile1.push(150);

    pile1.push(260);

    pile1.push(220);

    pile1.push(240);

    while(!pile1.empty())    // checking for pile1 is empty or not if empty then it will terminated or stop iteration

    {

        fraction = pile1.top() / 3;    // here we are taking stack top element or one of them score for calculation of percentage as question is asking

        percentage = fraction;      //giving fraction value to percentage.

        if(percentage >= 85)    //comparing percentage value

        {

            A++;              // if true then it will increment A.

        }

        else if(percentage < 85 && percentage >= 70)

        {

            B++;        // if true then it will increment B

        }

        else if(percentage < 70 && percentage >= 60)

        {

            C++;        // if true then it will increment C.

        }

        else if(percentage < 60)

        {

            D++;      //if true then it will increment D

        }

        pile2.push(pile1.top());   //here moving that score into pile2 list

        pile1.pop();    // removing that element from plie1 list so can next element of list will access.

    }

    cout<<"Value of A is "<<A<<endl;   // now printing all the value of A, B, C, and D

    cout<<"Value of B is "<<B<<endl;

    cout<<"Value of C is "<<C<<endl;

    cout<<"Value of D is "<<D<<endl;

    return 0;

}

and the output will be

Value of A is 3
Value of B is 3
Value of C is 1
Value of D is 1.


Related Solutions

What are the values of a, b, c, d, and e after the following statements? int...
What are the values of a, b, c, d, and e after the following statements? int a = 5, b = 2, c = 8, d = 7, e = 4; int x = c - b + a; a = a + x - d; b = c * d - x; c = e + a / 2; d = x - c * a; e = x + d - c;
What are the values in arrays a, b, and c after the following code executes (list...
What are the values in arrays a, b, and c after the following code executes (list all of the elements of the arrays)? double[] a = new double[4]; double[] b = {6,4,2}; a[a.length-1] = b[b.length-1]; double[] c = b; c[0] = -1; b[1] = c[2]; c = a; c[0] = -2; a[1] = c[3];
Consider the cross: A/a; b/b; C/c; D/d; E/e x A/a; B/b; c/c; D/d; e/e a) what...
Consider the cross: A/a; b/b; C/c; D/d; E/e x A/a; B/b; c/c; D/d; e/e a) what proportion of the progeny will phenotypically resemble the first parent? b) what proportion of the progeny will genotypically resemble neither parent?
Using the program below, identify the values of pid at lines A, B, C, and D....
Using the program below, identify the values of pid at lines A, B, C, and D. (Assume that the actual pids of the parent and child are 2600 and 2603, respectively.)   #include <sys/types.h>   #include <stdio.h>   #include <unistd.h>      int main()   {   pid_t pid, pid1;        /* fork a child process */     pid = fork();        if (pid lt; 0) { /* error occurred */       fprintf(stderr, "Fork Failed");       return 1;     }     else if (pid == 0) { /* child process */       pid1 = getpid();       ...
For each of the following simplicial complexes ,X = {[a], [b], [c], [d], [a, b], [c,...
For each of the following simplicial complexes ,X = {[a], [b], [c], [d], [a, b], [c, d]}, and X = {[a], [b], [c], [d], [e], [a, b], [b, c], [c, d], [a, d], [a, c], [a, e], [b, e], [a, b, c]},give a basis for each non-zero Hj(X).
Consider the following propositional formula: (((A ^ B) -> C) ^ ((A ^ C) -> D))...
Consider the following propositional formula: (((A ^ B) -> C) ^ ((A ^ C) -> D)) -> ((A ^ B) -> D) Perform the following tasks for this formula: Convert this formula into CNF form and write a numbered list of all clauses obtained from this formula.
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables...
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables and display the resulting value.
create a decision tree for a,b,c,d what do u need? a,b,c,d are the elements that needs...
create a decision tree for a,b,c,d what do u need? a,b,c,d are the elements that needs to be sorted
What is meant by chemical equilibrium? Given the following reaction: A + B <--> C +D...
What is meant by chemical equilibrium? Given the following reaction: A + B <--> C +D (reversible reaction), how would you drive the following reaction away from equilibrium to produce more of substances A and B?
Find the proof of the following ((a ∧ b) ∨ (c ∧ d)), (a → e),...
Find the proof of the following ((a ∧ b) ∨ (c ∧ d)), (a → e), (b → f), (c → f), (d → e) ⊢ e
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT