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

// This is the code that I\'m working on! #include <iostream> #include <cstdlib>

ID: 3665544 • Letter: #

Question

// This is the code that I'm working on!

#include <iostream>

#include <cstdlib>

#include <fstream>

using namespace std;

struct student_info

{

int num_of_stud;

int ids;

double score1, score2, average;

char letter_grade;

};

void s_sort(student_info x[], int n)

{

int m; // keep the index of current smallest value

student_info hold;

for (int k=0; k<=n-2; k++) {

m = k;

for (int j=k+1; j <= n-1; j++) {

if (x[j].ids < x[m].ids)

m = j;

}

hold = x[m];

x[m] = x[k];

x[k] = hold;

}

return;

}

int main()

{

student_info access[30];

string filename;

ifstream fin;

ofstream fout;

int i = 0;

cout << "Enter an input file: ";

getline(cin, filename);

fin.open(filename.c_str());

if (fin.fail())

{

cout << "File failed to open.";

exit(1);

}

while (!fin.eof())

{

fin >> access[i].num_of_stud;

fin >> access[i].ids;

fin >> access[i].score1;

fin >> access[i].score2;

i++;

}

access[i].average = access[i].score1+access[i].score2/2;

cout << "--------------------------" << endl << "Course Report" << endl << "--------------------------" << endl;

for (int j = 0; j < i; j++)

{

cout << access[j].ids << " " << access[j].average << " " << access[j].letter_grade

<< endl;

}

cout << "--------------------------";

}

1. (20 points) Develop a C++ program named hw6_1.cpp that reads a data file holding the records of students' id and scores of two exams. Your program letter grade of each student. Then, your program should print out the students arranged from highest numeric average, to lowest. The output should go back to the console, not a file should determine the numeric average and You should create a struct to hold the student's id, numeric average, and letter grade. Furthermore, you are to use an array to hold this data. The following shows a sample input data file. Please note that the file has the number of students on the first line. Sample Input File 1000 87.0 92.5 2000 100.0 100.0 3000 79.0 81.0 4000 99.0 98.5 5000 65.0 61.9 A sample run of your program might look like this. Note that the user's input are highlighted in bold. Sample Execution Enter an input file: C:\Temp\input.txt Course Report 2000 -100.00 (A) 4000 - 98.75 (A) 1000 - 89.75 (B) 3000- 80.00 (B) 5000 -63.45 (D)

Explanation / Answer

#include <iostream>

#include <cstdlib>

#include <fstream>

using namespace std;

struct student_info

{

int num_of_stud;

int ids;

double score1, score2, average;

char letter_grade;

};

void s_sort(student_info x[], int n)

{

student_info temp;

}

return x;

}

int main()

{

student_info access[30];

string filename;

ifstream fin;

ofstream fout;

int i = 0;

cout << "Enter an input file: ";

getline(cin, filename);

fin.open(filename.c_str());

if (fin.fail())

{

cout << "File failed to open.";

exit(1);

}

while (!fin.eof())

{

fin >> access[i].num_of_stud;

fin >> access[i].ids;

fin >> access[i].score1;

fin >> access[i].score2;

i++;

}

access[i].average = access[i].score1+access[i].score2/2;

cout << "--------------------------" << endl << "Course Report" << endl << "--------------------------" << endl;

foir(i=0;i<=n;i++)

{ student_info s1[10];

access[i].sort(s);

}

for (i= 0; i<n; i++) /* displaying id's and names in descending order of numeric average */

{

cout << access[i].ids << " " << access[i].average << " " ;

  

}

}