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

Read a data file and store all of the input data in a two dimensional array. Per

ID: 3663122 • Letter: R

Question

Read a data file and store all of the input data in a two dimensional array. Perform calculations on the data and store the results in the 2 dimensional array. Sort the array and print the results in a report.

Instructions

Read in the input file , datas shown below. This 50 record file consists of a (8-digit numeric) student id, 8 assignment's points, midterm points, lab exercise points, CodeLab points, and final points. All of the input data, calculated totals, percents, and grades (and plus or minus) must be stored in only one 2 dimensional array. The specifications for determination of the grades is the same as assignment 1 (or the course syllabus). Your output reports should be "very similar" to the output shown below. The point totals, percents, and grades must be follow the exact calculations. This is the same as assignment 1. You are to produce two output reports, one sorted by student id and one sorted by total points (in decending order). The two output reports must be written to separate files.

The Student Data Input File ( put this data into a .txt file )

Output Report Sorted by Student Id

Stdnt Id Ex ----- Assignments ----- Tot Mi Fin CL Pts Pct Gr
-------- -- ----------------------- --- -- --- -- --- --- --
01234567 57 16 14 20 8 10 19 11 9   99 53   21 16 246   62 D
12745220 55 20 17 16 18 19 15 20 4 114 22   64 19 274   69 D+
22645995 60 13 15 17 18 17 10 12 14 106 74 122 17 379   95 A
33339883 55 20 17 12 20 20 20 11 13 122 40 113 16 346   87 B
34029990 56   8 18 3 10 16 17 12 7   88 56 113 18 331   83 B
44576634 49 20 6 20 20 20 19 18 20 137 52   53 19 310   78 C+
46479276 39 20 7 13 16 7 15 18 10   99 26   52 18 234   59 F
47032460 60 18 18 14 11 17 18 19 6 110 61 101 20 352   88 B+
...

Output Report Sorted by Total Points (decending)

Stdnt Id Ex ----- Assignments ----- Tot Mi Fin CL Pts Pct Gr
-------- -- ----------------------- --- -- --- -- --- --- --
22645995 60 13 15 17 18 17 10 12 14 106 74 122 17 379   95 A
73528933 48 19 18 18 17 16 17 16 18 123 70 119 19 379   95 A
94958157 60 20 20 20 20 16 18 17 15 130 75   94 17 376   94 A
87305446 57 20 19 19 17 14 16 17 20 128 66   98 19 368   92 A
88258087 33 18 18 15 19 10 20 19 20 129 64 113 20 359   90 A-
90076387 57 20 16 9 9 19 17 20 17 118 67   97 18 357   89 B+
89168351 52 15 16 11 14 10 17 20 15 108 59 120 14 353   88 B+
92067579 45 19 16 15 17 19 19 8 9 114 51 122 20 352   88 B+
...

Program requirements

You must use a 2-dimensional array for all of the data.

Your solution must include at least 5 functions. And ...

At least one function must include a two dimensional array argument.

At least one function must include an argument that consists of one row of a two dimensional array.

At least one function must include an argument that consists of one element of a two dimensional array.

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

struct student{
   public:
       string ID;
       int ex_mrk;
       int* ass_mrk;
       int mid_mrk;
       int fin_mrk;
       int cod_mrk;
       student(string id,int ex,int* l,int mid,int fin,int cod){
           ID = id;
           ex_mrk = ex;
           ass_mrk = l;
           mid_mrk = mid;
           fin_mrk = fin;
           cod_mrk = cod;
       }
};

int best_seven(int* l,int n){
   sort(l, l + n);
   int sum = 0;
   for (int i = 1; i < n; i++)
       sum += l[i];
   return sum;
}

int total_per(int n){
   if (n % 4 == 0 || n % 4 == 1) return n/4;
   return n/4 + 1;
}

string grade(int n){
   if (n >= 90) return "A";
   if (n >= 80 && n < 88) return "B";
   if (n == 88 || n == 89) return "B+";
   if (n >= 70 && n < 78) return "C";
   if (n == 78 || n == 79) return "C+";
   if (n >= 60 && n < 68) return "D";
   if (n == 68 || n == 69) return "D+";
   if (n >= 50 && n < 58) return "E";
   if (n == 58 || n == 59) return "E+";
   return "F";
}

struct compare_ID{
   inline bool operator() (const student* s1, const student* s2){
       return (s1->ID < s2->ID);
   }
};

struct compare_Total{
   inline bool operator() (const student* s1, const student* s2){
       int best_1 = best_seven(s1->ass_mrk,8);
       int total_mrk_1 = s1->ex_mrk + best_1 +s1->mid_mrk+s1->fin_mrk+s1->cod_mrk;

       int best_2 = best_seven(s2->ass_mrk,8);
       int total_mrk_2 = s2->ex_mrk + best_2 + s2->mid_mrk + s2->fin_mrk + s2->cod_mrk;

       return (total_mrk_1 < total_mrk_2);
   }
};

int main(){
   ifstream infile;
   string filename = "input.txt";
   infile.open(filename.c_str());
   string ID;
   int ex_mrk;
   int* ass_mrk;
   int mid_mrk;
   int fin_mrk;
   int cod_mrk;
  
   vector<student*> std;
   while (!infile.eof()){
       infile >> ID >> ex_mrk;
       ass_mrk = new int[8];
       for (int i = 0; i < 8; i++)
           infile >> ass_mrk[i];
       infile >> mid_mrk >> fin_mrk >> cod_mrk;
       student* temp_std = new student(ID,ex_mrk,ass_mrk,mid_mrk,fin_mrk,cod_mrk);
       std.push_back(temp_std);
   }
   infile.close();
  
   sort(std.begin(), std.end(), compare_ID());
   ofstream outfile;
   filename = "output_1.txt";
   outfile.open(filename.c_str());
   outfile << "Stdnt Id Ex -------- Assignments ------- Tot Mi Fin CL Pts Pct Gr" << endl;
   for (int i = 0; i < std.size(); i++){
       outfile << std[i]->ID << ' ' << std[i]->ex_mrk << ' ';
       for (int j = 0; j < 8; j++)
           outfile << std[i]->ass_mrk[j] << ' ';
       int best = best_seven(std[i]->ass_mrk,8);
       outfile << ' ' << best << ' ' << std[i]->mid_mrk << ' ' << std[i]->fin_mrk << ' ' << std[i]->cod_mrk << ' ';
       int total_mrk = std[i]->ex_mrk+best+std[i]->mid_mrk+std[i]->fin_mrk+std[i]->cod_mrk;
       int per = total_per(total_mrk);
       outfile << total_mrk << ' ' << per << ' ' << grade(per) << endl;
   }
   outfile.close();

   sort(std.begin(), std.end(), compare_Total());
   filename = "output_2.txt";
   outfile.open(filename.c_str());
   outfile << "Stdnt Id Ex -------- Assignments ------- Tot Mi Fin CL Pts Pct Gr" << endl;
   for (int i = 0; i < std.size(); i++){
       outfile << std[i]->ID << ' ' << std[i]->ex_mrk << ' ';
       for (int j = 0; j < 8; j++)
           outfile << std[i]->ass_mrk[j] << ' ';
       int best = best_seven(std[i]->ass_mrk,8);
       outfile << ' ' << best << ' ' << std[i]->mid_mrk << ' ' << std[i]->fin_mrk << ' ' << std[i]->cod_mrk << ' ';
       int total_mrk = std[i]->ex_mrk+best+std[i]->mid_mrk+std[i]->fin_mrk+std[i]->cod_mrk;
       int per = total_per(total_mrk);
       outfile << total_mrk << ' ' << per << ' ' << grade(per) << endl;
   }
   outfile.close();

   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