Answer to Question #176211 in C++ for meng

Question #176211

a.    Declare an array of string title with 4 elements.

b.    Initialize the array with the follows: “Mid1”, “Mid2”, “Final”, “total”.

c.     Declare an array of integers scores with 4 elements.

d.    Use the loop to read from the scores array the three scores and calculate total and put the result in the fourth array element.

e.    Declare an array of float percentage with 4 elements.

f.      Calculate the percentage of the score in each of element, assuming that the full mark is 60

g.    Print the three arrays.

 

The output should be as follows:-

 ---------------------------

Enter your score in Mid1: 20

Enter your score in Mid2: 15

Enter your score in Final: 12

 

Mid1 20 33.3%

Mid2 15 25.0%

Final 12 20.0%

Total 47 78.3%


1
Expert's answer
2021-03-29T16:30:37-0400
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    float max = 60;
    string title[] = { "Mid1", "Mid2", "Final", "Total" };
    int score[4];
    score[3] = 0;
    for (int i = 0; i < 3; ++i)
    {
        cout << "Enter your score in " << title[i] << ": ";
        cin >> score[i];
        score[3] += score[i];
    }
    float percentage[] =
    {
    score[0] * 100 / max,
    score[1] * 100 / max,
    score[2] * 100 / max,
    score[3] * 100 / max
    };
    cout << "\r\n";
    for (int i = 0; i < 4; ++i)
    {
        cout << title[i] << " \t" << score[i] << " \t" << fixed << setprecision(1) << percentage[i] << "%\r\n";
    }
    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
APPROVED BY CLIENTS