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

In C++ Overview: The assignment is to complete two programs that will read stude

ID: 3786310 • Letter: I

Question

In C++

Overview:

The assignment is to complete two programs that will read student names and grade information from a data file. The grade information will consist of quiz, test, student program and final exam scores in the following format: name   quizzes  tests  programs  final

The programs will use this information to compute each student’s final grade average according to a weighting given below, and then use that final average to assign a letter grade. The final step will be to output a neatly formatted list of student names, averages, and grades, sorted by final average from highest to lowest.

The two programs should behave identically, but will be implemented differently. The first program will make use of parallel arrays to store the data and do the computations. The second will make use of an array of structs to accomplish the same thing.

A working executable file called grades will be supplied. Use it to guide decisions on what output formatting should look like and to verify computations. .

Program 1:

The first program will be named array.cpp. An incomplete template for the program is supplied in the location specified above. The supplied template contains a main routine that defines a set of parallel arrays to hold and process student data. In addition, a compiler directive sets the array sizes which limits the number of students that can be processed.

What you need to do:  

- Prompt the user for the name of a data file

o Exit gracefully if there is a problem finding or opening the data file

? Read the student names and scores from the data file into the parallel arrays. You can assume that if the file contains data, it is well formatted. But you should:

o Keep a count of the number of students read (Detect the end of the file!)

o Stop reading if the number of entries in the file is greater than the array size   (ignore the extra entries)

? Output a cleanly formatted table of the data read

? Compute the final average and the final letter grade for each student and store them in the extra supplied arrays.

o The final average is weighted as follows:               

quizzes: 5%        tests: 30%         programs: 40%         final: 25%

o The letter grade should be based on a 90/80/70/60 scale, where 90% or higher is an ‘A’, greater than or equal to 80% but less than 90% is a ‘B’, and so on…

? Sort the names, averages, and letter grade arrays based on the average for each student – from high to low   Note: there is no need to sort the arrays containing the original data!

? Output the final sorted results. The listing should contain the student’s name, average and letter grade. (i.e. the arrays that were sorted in the last step)

Program 2:

The second program performs the same task as the first. The output should be identical. The one, significant difference is that this program uses an array of structs to store and process the data rather than parallel arrays. The struct to be used is called student and is defined in the supplied template file struct.cpp.

What you need to do:

? Convert the completed array.cpp program to use an array of student objects (structs) rather than the parallel arrays used in the first program.

? Much of the code that you wrote will be reusable. Simply copy and modify it, as needed.

General Notes:

The programs should be written in modular form. That is, the main routine should only contain the needed variables (arrays or structs) and calls to functions. Appropriate prototypes should be declared at the top of the file with function definitions appearing after the main function. Suggested functions are prototyped in the template files. You will, however, need to add prototypes for the sorting function as well as any additional functions that you deem necessary to support the sorting. Be sure to test thoroughly! Write additional test files! In particular, what happens with different size input files? What happens if the number of entries exceeds the array size limit? Compare your program’s behavior to the supplied example program. (Again: to simplify the input processing, you may assume that any lines that exist in the input data file are properly formatted as described in the overview.) Final note: the program should be well formatted and adhere to departmental documentation guidelines. Templates are provided in CodeDocTemplate.txt, as mentioned above. Only the function definitions need to have the function documentation – it is not needed for the prototypes. Grading Rubric: 1. Program must compile 2. Modular program, using functions 3. Read data file a. Prompt the user for a file name b. Open file, or abort with an appropriate message on an error c. Read the data into the array(s) d. Keep track of the number of entries (Detect the end of the file) e. Limit the number of entries to the array size (ignore additional entries) 4. Output the data read in a well formatted list 5. Compute the numerical average and final letter grades a. These can both be done in one function 6. Sort the array data according to the average grade   a. (Note, for array.cpp, only the name average and grade arrays need be sorted) 7. Output the name, average, and final letter grades in sorted order, neatly formatted 8. The program must be well commented/documented a. Using the departmental standard for documentation

in file scores.dat

Bob 87 78 73 75
Katy 80 80 79 75
James 85 90 84 85
Victoria 72 73 54 73
Jake 98 96 91 94
Matthew 93 91 84 80
Wesley 80 75 73 73
Dana 90 90 84 91
Edwin 72 69 61 77
Allysha 77 72 39 55
Kevin 82 78 72 75
Jolie 94 91 93 93

arrray.cpp file

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

#define ARRAYSIZE 12

// prototypes
int readDatafile(string[], int[], int[], int[], int[], int);
void calcAvgGrade( ... );
void dumpData( ... );
void dumpSorted( ... );

// add prototypes and functions as needed for sorting

main() {
string names[ARRAYSIZE]; // student names
int quizzes[ARRAYSIZE]; // student quiz score
int tests[ARRAYSIZE]; // student test score
int progs[ARRAYSIZE]; // student progam score
int final[ARRAYSIZE]; // student final exam score

float avg[ARRAYSIZE]; // student final average
char grade[ARRAYSIZE]; // student final letter grade

}

// open and read the datafile
// this should return the number of entries read!!!
int readDatafile(string n[], int q[], int t[], int p[], int f[], int max) {
string fname; // file name
ifstream ifs; // input file stream
int num=0; // number of students read
}

// output the data that was read in
void dumpData( ... ) {
}

// calculate the grade average and the letter grade
void calcAvgGrade( ... ) {
}

// output the final sorted information
void dumpSorted( ... ) {
}

struct.cpp

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

#define ARRAYSIZE 12

// struct definition for a student object
struct student {
string name; // student name
int quizzes; // student quiz score
int tests; // student test score
int progs; // student progam score
int final; // student final exam score
float average; // student final average   
char grade; // student final letter grade
};

// prototypes
int readDatafile(student[], int);
void calcAvgGrade( ... );
void dumpData( ... );
void dumpSorted( ... );

// additional prototypes for sorting

main() {
student slist[ARRAYSIZE];

}

// open and read the datafile
int readDatafile(student list[], int max) {
string fname;
ifstream ifs;
int num=0;

}

Explanation / Answer

//pls rate my answer

//program1

//arrray.cpp file
#include <iostream>
#include <fstream>
#include <iomanip>
#include<string>
using namespace std;
#define ARRAYSIZE 12
// prototypes
int readDatafile(string[], int[], int[], int[], int[], int);
void calcAvgGrade(char grade[], float avg[],int quizzes[], int tests[], int progs[], int final[],int count);
void dumpData(string names[], int quizzes[], int tests[], int progs[], int final[],float avg[],char grade[],int count);
void dumpSorted(string names[], int quizzes[], int tests[], int progs[], int final[], float avg[], char grade[],int count);
// add prototypes and functions as needed for sorting
int main() {
   string names[ARRAYSIZE]; // student names
   int quizzes[ARRAYSIZE]; // student quiz score
   int tests[ARRAYSIZE]; // student test score
   int progs[ARRAYSIZE]; // student progam score
   int final[ARRAYSIZE]; // student final exam score
   float avg[ARRAYSIZE]; // student final average
   char grade[ARRAYSIZE]; // student final letter grade
   //call readDatfile to fill the array from file
   int count = readDatafile(names, quizzes, tests, progs, final, 100);
   //calculate average
   calcAvgGrade(grade, avg, quizzes, tests, progs, final, count);
   dumpData(names, quizzes, tests, progs, final, avg, grade, count);
   cout << "---------------------------sorted output-------------------------------------------------" << endl;
   dumpSorted(names, quizzes, tests, progs, final, avg, grade, count);
}
// open and read the datafile
// this should return the number of entries read!!!
int readDatafile(string n[], int q[], int t[], int p[], int f[], int max) {
   string fname; // file name
   ifstream ifs; // input file stream
   int num = 0; // number of students read
   string q1, t1, p1,f1;
   cout << "Enter file name to open" << endl;
   cin >> fname;
   ifs.open(fname);
   //check file is open
   if (!ifs)
   {
       cout << "Not able to open input file ";
       return -1;
   }
   while (!ifs.eof())
   {
       ifs >> n[num] >> q1 >> t1 >> p1 >> f1;
       q[num] = stoi(q1);
       t[num] = stoi(t1);
       p[num] = stoi(p1);
       f[num++] = stoi(f1);
   }
   return num;
}
// output the data that was read in
void dumpData(string names[], int quizzes[], int tests[], int progs[], int final[], float avg[], char grade[],int count) {
  
   cout << setw(10) << "names" << setw(8) << "quizzes"<< setw(7) << "tests" << setw(6) <<"progs" << setw(6) << "final" << setw(6) << "avg" << setw(2) << " grade" << endl;
   for (int i = 0; i < count; i++)
   {
       cout << setw(10) << names[i] << setw(8) << quizzes[i] << setw(7) << tests[i] << setw(6) << progs[i] <<setw(6) << final[i] << setw(6) << avg[i] << setw(2) << grade[i] << endl;
   }

}
// calculate the grade average and the letter grade
void calcAvgGrade(char grade[], float avg[], int quizzes[], int tests[], int progs[], int final[],int count) {

   for (int i = 0; i < count; i++)
   {
       avg[i] = 0.05*quizzes[i] + 0.3*tests[i] + 0.4*progs[i] + 0.25*final[i];
       if (avg[i] >= 90)
       {
           grade[i] = 'A';
       }
       if (avg[i] < 90 && avg[i] >= 80)
       {
           grade[i] = 'B';
       }
       if (avg[i] < 80 && avg[i] >= 70)
       {
           grade[i] = 'C';
       }
       if (avg[i] < 70 && avg[i] >= 60)
       {
           grade[i] = 'D';
       }
       if (avg[i] < 60 && avg[i] >= 50)
       {
           grade[i] = 'E';
       }
       if (avg[i] <= 40 )
       {
           grade[i] = 'F';
       }
   }
}
// output the final sorted information
void dumpSorted(string names[], int quizzes[], int tests[], int progs[], int final[], float avg[], char grade[],int count) {
   float tmp;
   //sort array
   for (int i = 0; i < count; i++)
   {
       for (int j = 0 ; j < count; j++)
       {
           if (avg[j] < avg[j + 1])
           {
               tmp = avg[j];
               avg[j] = avg[j + 1];
               avg[j + 1] = tmp;
           }
       }
   }
   //print sorted array
   cout << setw(10) << "names" << setw(8) << "quizzes" << setw(7) << "tests" << setw(6) << "progs" << setw(6) << "final" << setw(6) << "avg" << setw(2) << " grade" << endl;
   for (int i = 0; i < count; i++)
   {
       //cout << names[i] << " " << quizzes[i] << " " << tests[i] << " " << progs[i] << " " << final[i] << " " << avg[i] << " " << grade[i] << " " << endl;
       cout << setw(10) << names[i] << setw(8) << quizzes[i] << setw(7) << tests[i] << setw(6) << progs[i] << setw(6) << final[i] << setw(6) << avg[i] << setw(2) << grade[i] << endl;
   }
  
}

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

//output1

Enter file name to open
scores.dat
names quizzes tests progs final avg grade
Bob 87 78 73 75 75.7 C
Katy 80 80 79 75 78.35 C
James 85 90 84 85 86.1 B
Victoria 72 73 54 73 65.35 D
Jake 98 96 91 94 93.6 A
Matthew 93 91 84 80 85.55 B
Wesley 80 75 73 73 73.95 C
Dana 90 90 84 91 87.85 B
Edwin 72 69 61 77 67.95 D
Allysha 77 72 39 55 54.8 E
Kevin 82 78 72 75 75.05 C
Jolie 94 91 93 93 92.45 A
---------------------------sorted output---------------------------
---------
names quizzes tests progs final avg grade
Bob 87 78 73 75 93.6 C
Katy 80 80 79 75 92.45 C
James 85 90 84 85 87.85 B
Victoria 72 73 54 73 86.1 D
Jake 98 96 91 94 85.55 A
Matthew 93 91 84 80 78.35 B
Wesley 80 75 73 73 75.7 C
Dana 90 90 84 91 75.05 B
Edwin 72 69 61 77 73.95 D
Allysha 77 72 39 55 67.95 E
Kevin 82 78 72 75 65.35 C
Jolie 94 91 93 93 54.8 A

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

//program2

#include <iostream>
#include <fstream>
#include <iomanip>
#include<string>
using namespace std;
#define ARRAYSIZE 12
// struct definition for a student object
struct student {
   string name; // student name
   int quizzes; // student quiz score
   int tests; // student test score
   int progs; // student progam score
   int final; // student final exam score
   float average; // student final average   
   char grade; // student final letter grade
};
// prototypes
int readDatafile(student[], int);
void calcAvgGrade(student[],int count);
void dumpData(student[],int count);
void dumpSorted(student[], int count);
// additional prototypes for sorting
int main() {
   student slist[ARRAYSIZE];
   int count = readDatafile(slist, 100);
   //calculate average
   calcAvgGrade(slist,count);
   dumpData(slist, count);
   cout << "---------------------------sorted output-------------------------------------------------" << endl;
   dumpSorted(slist, count);


}
// open and read the datafile
int readDatafile(student list[], int max) {
   string fname;
   ifstream ifs;
   int num = 0;
   string q1, t1, p1, f1;
   cout << "Enter file name to open" << endl;
   cin >> fname;
   ifs.open(fname);
   //check file is open
   if (!ifs)
   {
       cout << "Not able to open input file ";
       return -1;
   }
   while (!ifs.eof())
   {
       ifs >> list[num].name >> q1 >> t1 >> p1 >> f1;
       list[num].quizzes = stoi(q1);
       list[num].tests = stoi(t1);
       list[num].progs = stoi(p1);
       list[num++].final = stoi(f1);
   }
   return num;

}

void calcAvgGrade(student list[], int count)
{
   for (int i = 0; i < count; i++)
   {
       list[i].average = 0.05*list[i].quizzes + 0.3*list[i].tests + 0.4*list[i].progs + 0.25*list[i].final;
       if (list[i].average >= 90)
       {
           list[i].grade = 'A';
       }
       if (list[i].average< 90 && list[i].average >= 80)
       {
           list[i].grade = 'B';
       }
       if (list[i].average < 80 && list[i].average >= 70)
       {
           list[i].grade = 'C';
       }
       if (list[i].average < 70 && list[i].average >= 60)
       {
           list[i].grade = 'D';
       }
       if (list[i].average < 60 && list[i].average >= 50)
       {
           list[i].grade = 'E';
       }
       if (list[i].average <= 40)
       {
           list[i].grade = 'F';
       }
   }

}
void dumpData(student list[], int count)
{
   cout << setw(10) << "names" << setw(8) << "quizzes" << setw(7) << "tests" << setw(6) << "progs" << setw(6) << "final" << setw(6) << "avg" << setw(2) << " grade" << endl;
   for (int i = 0; i < count; i++)
   {
       cout << setw(10) << list[i].name << setw(8) << list[i].quizzes << setw(7) << list[i].tests << setw(6) << list[i].progs << setw(6) << list[i].final << setw(6) << list[i].average << setw(2) << list[i].grade << endl;
   }

}
void dumpSorted(student list[], int count)
{
   float tmp;

   for (int i = 0; i < count; i++)
   {
       for (int j = 0; j < count; j++)
       {
           if (list[j].average < list[j+1].average)
           {
               tmp = list[j].average;
               list[j].average = list[j + 1].average;
               list[j + 1].average = tmp;
           }
       }
   }
   //print sorted array
   cout << setw(10) << "names" << setw(8) << "quizzes" << setw(7) << "tests" << setw(6) << "progs" << setw(6) << "final" << setw(6) << "avg" << setw(2) << " grade" << endl;
   for (int i = 0; i < count; i++)
   {
       cout << setw(10) << list[i].name << setw(8) << list[i].quizzes << setw(7) << list[i].tests << setw(6) << list[i].progs << setw(6) << list[i].final << setw(6) << list[i].average << setw(2) << list[i].grade << endl;
   }

}

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

output2

Enter file name to open
scores.dat
names quizzes tests progs final avg grade
Bob 87 78 73 75 75.7 C
Katy 80 80 79 75 78.35 C
James 85 90 84 85 86.1 B
Victoria 72 73 54 73 65.35 D
Jake 98 96 91 94 93.6 A
Matthew 93 91 84 80 85.55 B
Wesley 80 75 73 73 73.95 C
Dana 90 90 84 91 87.85 B
Edwin 72 69 61 77 67.95 D
Allysha 77 72 39 55 54.8 E
Kevin 82 78 72 75 75.05 C
Jolie 94 91 93 93 92.45 A
---------------------------sorted output----------------------------------------
---------
names quizzes tests progs final avg grade
Bob 87 78 73 75 93.6 C
Katy 80 80 79 75 92.45 C
James 85 90 84 85 87.85 B
Victoria 72 73 54 73 86.1 D
Jake 98 96 91 94 85.55 A
Matthew 93 91 84 80 78.35 B
Wesley 80 75 73 73 75.7 C
Dana 90 90 84 91 75.05 B
Edwin 72 69 61 77 73.95 D
Allysha 77 72 39 55 67.95 E
Kevin 82 78 72 75 65.35 C
Jolie 94 91 93 93 54.8 A