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

I am having problems with my programming assignment. I know how to declare a var

ID: 3622017 • Letter: I

Question

I am having problems with my programming assignment. I know how to declare a variable for input and output files and I know how to declare arrays. But I can't seem to integrate them together to make a working application. Here is what I am supposed to do.

1. Create a text file that contains 10 student names and 5 grades that range in value from 0 to 100.
The file should contain the following information in this order:
First Name Last Name Grade1 Grade2 Grade3 Grade4 Grade5 .
For example, the first 2 lines of this file might be:
John Doe 89.52 89 56.52 99.54 100.00
Sara Jones 78.50 89.23 99.50 23.22 50.12
2. Create a CPP application that does the following:
a. Define a variable for file read access and a variable for file write access
b. Define a 2 dimensional array with 10 rows and 2 columns – each row will contain the data
that corresponds to a line in the text file. The two columns in each row will contain the
first and last names of the student
c. Define a parallel 2 dimensional array with 10 rows and 5 columns – each row will contain
the data that corresponds to a line in the text file. 5 columns in each row will contain the
grades for the associated student that is in the corresponding array defined in the
previous item.
d. Define other variables as needed
e. Open the read access file
f. Read the first line of the file data (first name, last name, all 5 grades
g. Loop through the text file created in step # 1 until you reach the end of file (eof):
i. Fill the first array with the last name and first name from the student data file.
ii. Fill the second array with the 5 grades for each student in the data file.
iii. Read the next line of data
h. Close the input file
i. Once you have completed filling in the 2 dimensional array:
i. Open the output file
ii. In a For loop, traverse both the student names and student grades arrays.
iii. Call a function to calculate the average for each student
iv. Call a second function to calculate the grade the student received based on his
average based on the following grading scale:
1. 90 - 100 = A
2. 80 – 89.99 = B
3. 70 – 79.99 = C
4. 60 – 69.99 = D
5. Below 60 = F
v. Output to the screen the following information:
Last Name First Name grade1 grade2 grade3 grade4 grade5 average letter grade
For example:
Doe, John 89.52 89 56.52 99.54 100.00 Avg: 86.92 Grade: B
vi. Write the last name, first name (separated by a comma and a space), average
and letter grade for each student to the output file. For Example:
Doe, John 86.92 B
vii. Close the output file

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#define tests 5
double getAverage(double[][tests],int);
char getGrade(double);
int main()
{string name[10][2];
int students,i,j;
double average,grades[10][5];
char grade;
ifstream in;
ofstream out;
in.open("input.txt");       
if(in.fail())           
   { cout<<"input file did not open please check it ";
   system("pause");
   return 1;
   }
i=0;
in>>name[i][0];
while(in)
   {in>>name[i][1];
   for(j=0;j<tests;j++)
        in>>grades[i][j];
   i++;
    in>>name[i][0];   
   }
students=i;
in.close();  
out.open("output.txt");           
for(i=0;i<students;i++)
    {average=getAverage(grades,i);
    grade=getGrade(average);
    cout<<name[i][1]<<", "<<name[i][0]<<" ";
    for(j=0;j<tests;j++)
         cout<<grades[i][j]<<" ";
    cout<<"Avg: "<<setprecision(2)<<fixed<<average<<" Grade: "<<grade<<endl;
    out<<name[i][1]<<", "<<name[i][0]<<" "<<setprecision(2)<<fixed<<average<<" "<<grade<<endl;
    }  
out.close();
system("pause");
return 0;
}
double getAverage(double g[][tests],int n)
{double sum=0;
int i;
for(i=0;i<tests;i++)
     sum+=g[n][i];
return sum/tests;
}    
char getGrade(double a)
{if(a>=90)
      return 'A';
else if(a>=80)
      return 'B';
else if(a>=70)
      return 'C';
else if(a>=60)
      return 'D';
else
      return 'F';
}