Answer to Question #183256 in C++ for Abdullah

Question #183256

The marks of student in 3 subjects for 3 examseach are stored in an array.The result needs to be calculated by first taking average score of three exams for each of the subject.Store the average result obtained in an array.If any of the three averages are less than 60,mention which subjects need a retake.


1
Expert's answer
2021-04-20T08:00:40-0400
#include<bits/stdc++.h>
using namespace std;
void getSubjects(string data[],int x)
{
    int averageSubjectScore;
    int maxAvgScore = INT_MIN;


    // List to store subject name
    // having maximum average score
    vector<string> subjects;


    // Traversing the subject array
    for (int i = 0; i < x; i += 4)
    {


        // Find average score of a subject and add to arary
        averageSubjectScore = (stoi(data[i + 1]) + stoi(data[i + 2]) + stoi(data[i + 3])) / 3;


        if (averageSubjectScore < 60)
        {
            subjects.push_back(data[i]);
        }


    }
    //Display name of subject with < 60 average
    for (int i = 0; i < subjects.size(); i++) {
        cout <<subjects[i] + " ";
    }
}


// Main program code
int main()
{
    //List subject and score data as string array
    string data[] = {
                    "Algebra", "20", "30","10",
                    "Science", "100", "50", "40",
                    "Geography", "100", "50", "40"
                    };


    // Number of elements in string array
    int n= sizeof(data)/sizeof(data[0]);
    cout<<"You need to retake the following subject(s) with average below 60%: ";
    getSubjects(data,n);
}

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