Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ Previous Program: #include #include #include using namespace std; //Funct

ID: 3717964 • Letter: I

Question

In c++

Previous Program:

#include
#include
#include

using namespace std;

//Function that prints student details
void printResults(int sid[], double avg[], char grades[], int cnt)
{
    int i=0;

    cout << fixed << setprecision(2);

    //Printing header
    cout << " " << left << setw(10) << "SID" << left << setw(10) << "Average" << left << setw(10) << "Grade" << " ";

    //Iterating over each student
    for(i=0; i     {
        //Printing data
        cout << left << setw(10) << sid[i] << left << setw(10) << avg[i] << left << setw(10) << grades[i] << " ";
    }
}

//Helper function for countGrades
int cntGrade(char grade, char grades[], int cnt)
{
    int i, c=0;

    //Iterating over grades
    for(i=0; i     {
        //Comparing grade
        if(grade == grades[i])
        {
            //incrementing count
            c += 1;
        }
    }

    return c;
}

//Counting count of each grade
void countGrade(char grades[], int cnt)
{
    int i;
    //Printing count of each grade

    //Printing header
    cout << " " << left << setw(6) << "Grade" << left << setw(6) << "Count" << " ";

    for(i=65; i<=70; i++)
    {
        //Skipping grade E
        if(i!=69)
        {
            //Printing result
            cout << left << setw(6) << char(i) << left << setw(6) << cntGrade(char(i), grades, cnt) << " ";
        }
    }
}

//Computing overall average of class
double overallAvg(double avg[], int cnt)
{
    int i;
    double sum=0, oAvg;

    //Iterating over each average
    for(i=0; i     {
        //Accumulating average
        sum += avg[i];
    }

    //Calculating overall average
    oAvg = sum / (double)(cnt);

    return oAvg;
}

//Main function
int main()
{
    //Opening file in read mode
    fstream fin("studentScores.dat");

    //Parallel arrays
    int sid[100];
    double avg[100];
    char grade[100];

    int t1, t2, t3, p1, p2, p3, p4, p5, p6, f;
    double tAvg, pAvg, totAvg;

    //To hold number of students
    int stuCnt=0;

    //Reading data from file
    while(fin.good())
    {
        //Reading id
        fin >> sid[stuCnt];

        //Reading test values and program values and final
        fin >> t1 >> t2 >> t3 >> p1 >> p2 >> p3 >> p4 >> p5 >> p6 >> f;

        //Calculating averages
        tAvg = (t1+t2+t3) / 3.0;
        pAvg = (p1+p2+p3+p4+p5+p6) / 6.0;

        //Calculating final average
        totAvg = (tAvg*0.50) + (pAvg * 0.25) + (f * 0.25);

        //Storing in array
        avg[stuCnt] = totAvg;

        //Finding grade
        if(totAvg > 89.5)
        {
            grade[stuCnt] = 'A';
        }
        else if(totAvg > 79.5 && totAvg <= 89.5)
        {
            grade[stuCnt] = 'B';
        }
        else if(totAvg > 69.5 && totAvg <= 79.5)
        {
            grade[stuCnt] = 'C';
        }
        else if(totAvg > 59.5 && totAvg <= 69.5)
        {
            grade[stuCnt] = 'D';
        }
        else
        {
            grade[stuCnt] = 'F';
        }

        //Incrementing student count
        stuCnt+=1;
    }

    //Closing file
    fin.close();

    //Writing results
    printResults(sid, avg, grade, stuCnt);

    //Counting grades
    countGrade(grade, stuCnt);

    //Printing overall average
    cout << " Overall Average: " << overallAvg(avg, stuCnt) << " ";

    return 0;
}

CSC135 Program #7-Arrays2D (student averages) You are to modify the program that you wrote for Program #6 (Arrays) to make use of 2D (two dimensional) arrays. Refer to that assignment for details not specified here First, name your program: arrays.cpp you can copy it from the old program as follows cp arrays.cpp arrays2D.cpp In the previous program, you read student data from a file called studentScores.dat. You loaded the information into three parallel arrays, computing the average and letter grades for each student. You will do the same for this assignment, however, ALL of the data must be stored in parallel arrays first, two of which will be 2-dimensional, BEFORE any computation may be ne Specifically, you should read the student id number (SID) as before into an array. The tests and programs scores should be loaded into two separate 2D arrays. The 2D array containing the test information will have 3 columns for each student's 3 test scores. Similarly, the 2D array for the program scores will have 6 columns for the 6 program scores. All of this should be done in one function Once the data have been loaded into the 3 parallel arrays, you can proceed to determine the average and the letter grade for each student and store them in parallel arrays, as was done in the previous assignment. Finally, complete the assignment, as before, by generating the numbers of each grade (A, B, C, D, F), and the overall class average as described in the prior assignment

Explanation / Answer

using namespace std;


void printResults(int sid[], double avg[], char grades[], int cnt)
{
    int i=0;

    cout << fixed << setprecision(2);
    cout << " " << left << setw(10) << "SID" << left << setw(10) << "Average" << left << setw(10) << "Grade" << " ";

    for(i=0; i <avg ; i ++)

    {

        cout << left << setw(10) << sid[i] << left << setw(10) << avg[i] << left << setw(10) << grades[i] << " ";
    }
}


int cntGrade(char grade, char grades[], int cnt)
{
    int i, c=0;
    for(i=0; i <grade;i++)

{
        if(grade == grades[i])
        {
   
            c += 1;
        }
    }

    return c;
}
void countGrade(char grades[], int cnt)
{
    int i;
cout << " " << left << setw(6) << "Grade" << left << setw(6) << "Count" << " ";

    for(i=65; i<=70; i++)
    {

        if(i!=69)
        {          cout << left << setw(6) << char(i) << left << setw(6) << cntGrade(char(i), grades, cnt) << " ";
        }
    }

double overallAvg(double avg[], int cnt)
{
    int i;
    double sum=0, oAvg;
    for(i=0; i <oAvg;i++)    {
        sum += avg[i];
    }


    oAvg = sum / (double)(cnt);

    return oAvg;
}
int main()
{
    fstream fin("studentScores.dat");
    int sid[100];
    double avg[100];
    char grade[100];

    int t1, t2, t3, p1, p2, p3, p4, p5, p6, f;
    double tAvg, pAvg, totAvg;
    int stuCnt=0;
    while(fin.good())
    {
     
        fin >> sid[stuCnt];


        fin >> t1 >> t2 >> t3 >> p1 >> p2 >> p3 >> p4 >> p5 >> p6 >> f;

  
        tAvg = (t1+t2+t3) / 3.0;
        pAvg = (p1+p2+p3+p4+p5+p6) / 6.0;


        totAvg = (tAvg*0.50) + (pAvg * 0.25) + (f * 0.25);


        avg[stuCnt] = totAvg;

   
        if(totAvg > 89.5)
        {
            grade[stuCnt] = 'A';
        }
        else if(totAvg > 79.5 && totAvg <= 89.5)
        {
            grade[stuCnt] = 'B';
        }
        else if(totAvg > 69.5 && totAvg <= 79.5)
        {
            grade[stuCnt] = 'C';
        }
        else if(totAvg > 59.5 && totAvg <= 69.5)
        {
            grade[stuCnt] = 'D';
        }
        else
        {
            grade[stuCnt] = 'F';
        }
        stuCnt+=1;
    }


    fin.close();
    printResults(sid, avg, grade, stuCnt);
    countGrade(grade, stuCnt);
    cout << " Overall Average: " << overallAvg(avg, stuCnt) << " ";

    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote