I have a problem to solve, and I came so close with algorithm, but I am having hard time organizing them so they work.
I will post the question and the codes I have.
Can someone help me organizing them?
The program is expected to read input information from a textfile called “grade.txt” and write its output to the terminal.
The format of the input file is: First line will have two integer values, as x and y.
For example, 3 and 4. First number, 3, indicates the number of the students. Second number, 4, specifies the number of homework. There will be x rows, each with y columns (3 rows and 4 columns) where each column will hold a grade between 0-100. Below, you can see the contents of a possible input file:
3 3
92 90 70
80 90 20
90 70 88
Your program is to calculate the average of any number of grades (expect up to 10 grades in each row). Include at least 3 functions:
• main, which declares the a two-dimensional grades array (10 by 10), calls the other methods, and writes output of the grades, their average and a letter grade ( >= 90 is A, >= 80 is B, >=70 is C, >= 60 is D, and E otherwise).
• get_grades, which gets input of integer grades from a file to the 2-dimensional array.
• calculate_average, which uses the grades array and passes the average back to main.
#include <iostream>
#include <fstream>
using namespace std;
int get_grades() // GET GRADES //
{
int student;
int hw;
int gradebook = [10][10];
in_stream >> student;
in_stream >> hw;
ifstream OpenFile; // ifstream --> input
OpenFile.open("grade.txt"); // Open file grade.txt
char ch;
while (OpenFile)
{
OpenFile.get(ch);
cout << ch;
}
for (int i=0; i< student; i++)
for (int j=0; j<hw ; j++)
in_stream >> gradebook [i][j];
}
int calculate_average (main) // calculate average //
{
int Avg (int[],int)
int total = 0;
for (int k=0; k<Avg; k++)
total += student_1[k];
return (total/hw)
}
int main () // MAIN //
{
int student_1[10];
for (int i=0; i<student_1; i++)
cout << "student # " << i << "\t";
{
for (int j=0; j<hw ; j++)
cout << gradebook [i][j] << "\t";
student_1[j] = gradebook [i][j];
}
int avg (student_1[], hw);
int Avg = total / 100;
char grade;
switch (temp)
{
case 100 : grade = 'A Plus!';
break;
case 90 : grade = 'A';
break;
case 80 : grade = 'B';
break;
case 70 : grade = 'C';
break;
case 60 : grade = 'D';
break;
default : grade = 'F';
} // switch
cout << endl;
}