Please assist with creating a program using arrays and functions for student grades. These are the requirements:
To create and execute a C++ program with functions and arrays that will read student information input from an input text file, calculate the test average, program average, course average, and the letter grade earned and output the result to the monitor as well as to an output text file. Program must allow grades to be calculated for unknown but finite number of students’ records in the input text file. For this assignment, the maximum number of students is limited to 40. The letter grade earned is based on the course average as noted below.

Course Average

Letter Grade

90 - 100
A
80 - 89
B
Below 80

F


The following is required:

  • Your program must prompt the user for and read the input text file name/path.
  • You are required to use one or more functions for each of the following:
    • Output descriptive header.
    • Read a student’s name and scores into two dimensional string and integer arrays ( string names[40][2] and int scores[40][6] ). Must use an outer while loop and two inner for loops.
    • Calculate the total ( int total[40] and two for loops)
    • Calculate the program average, test average, course averages, (float averages[40][3] and two for loops). You may also declare three 1D float arrays for the averages and use one or more functions.
    • Calculate the letter grade (char grades[40] and one outer for loop)..
    • Output student name, total points, program average, test average, and course average to a text file as well as the monitor. Must use an outer for loop.

Note: You must check for file input/output stream failure.

Program Input


The input must be read from a text file located on a disk. It must consist of the following information:

· Student’s First Name (alphabetic);
· Student’s Last Name (alphabetic);
· First Program Grade (a number between 0 and 100);
· Second Program Grade (a number between 0 and 100);
· Third Program Grade (a number between 0 and 100);
· First Test Grade (a number between 0 and 100);
· Second Test Grade (a number between 0 and 100);
· Third Test Grade (a number between 0 and 100);


this is what I have thus far which isn't running: :sad::sad::mad:

//Preprocessor Directives

#include<iostream>
#include<conio.h>
#include<iomanip>
#include<fstream>


using namespace std;

//Global constrants and global variables
void headerfn();
void inputfn(ifstream& inputFile,ofstream& outputFile,string names[],int scores[][],int count[]);
void totalfn(ifstream& inputFile, ofstream& outputFile,int total[]);
void averagesfn(ifstream& inputFile, ofstream& outputFile,float averages[][]);
void calculategradefn(char grade[]);

//Main function definition

void main()
{
    headerfn();
    //**************************************************************************************************    
//block in main
    //Declare and open/close files
    fin.open("input.txt");
    if(!fin)return;
    ifstream fin;
    ofstream fout;

    char inputFile[51];
    char outputFile[51];

    cout<<"Welcome to the IT210 Grade Calculator"<<endl;
    cout<<"Please enter the name/path of input file <e.g.input4.txt>: ";
    cin>>inputFile;
    cout<<endl;

    cout<<"Thank you! You entered";
    cin>>fileName;

    fin.open(inputFile);
    if (!fin)
    {
        cout<<"Cannot open the input file."<<endl;
        return 1;
    }
        

    cout<<"Enter the output file name: ";
    cin>>outputFile;
    cout<<endl;

    fout.open(outputFile);
    if (!fout)
    {
        cout<<"Cannot open the output file."<<endl;
        return 1;
    }

    fin.close();
    fout.close();
//************************************************************************************************
    


     string names[40][2]; 
     int scores[40][6];
     int total[40];
     float averages[40][3];
     char grade[40];
     int count;
     ifstream inputFile;
     ofstream outputFile;
     

     //input fn block
     void inputfn(string names[][],int scores[][], count);
     count=0;
     while (fin&&count<40)
     {fin>>name[count][0]
         >>name[count][1];

     for (int col=0; col<6;col++)
     {fin>>scores[count][col];}

     if (fin.peek()=='\n')fin.ignore();
     count++;
     }//end of while

     for (int row =0; row<count; row++)
     {
         total [row]=0;
         for (int col=0; col<6; col++)
         total[row]= total [row] + scores [row][col];
     }//end of outer loop

     for (int row=0; row<count; row++)
     {cout<<setw(20)<<name[row][0]+' '+name[row][1];
       for (int col=0; col<6;col++)
       {cout<<setw(5)<<scores[row][col];}
       cout<<setw(5)<<total[row];
       cout<<endl;
     }//end of outer for

     cout<<"Pres any key to continue...";
     getch();

}//end of main

//Function Definitions

}//end of headerfn


//definition of function calculateAverage
int calculateAverage(int number1, int number2, int number3)
{//start of function calculateAverage
int average;
average= number1+number2+number3/3;
return average;
}//end of function calculateAverage



//assign whether pass or fail

char assignGrade(int average)
{
if (average > 50) {
cout << "Pass:";
}
else if(average == average) {
cout << "Pass:";
}
else {
cout << "Fail:";
cout << "Fail:";
}
}

please edit your post and enclose the code in code tags. Read the links in my signature if you do not know how to do that.

Also what are specific questions?

Don't use void main . It's old and outdated, and so instead you should use int main .Here are some things wrong with your code:

void inputfn(ifstream& inputFile,ofstream& outputFile,string names[],int scores[][],int count[]);
void totalfn(ifstream& inputFile, ofstream& outputFile,int total[]);
void averagesfn(ifstream& inputFile, ofstream& outputFile,float averages[][]);

You're having some errors with these lines of code because you have to declare all dimensions of an array except the first one. This problem also occurs often in later parts of your program. So, for the scores, you would declare an array like int scores[][6] and for averages, you would use int averages[][3] .

You need to declare fin before trying to use it:

//block in main
//Declare and open/close files
fin.open("input.txt");
if(!fin)return;
ifstream fin;
ofstream fout;

You forgot to declare fileName :

cout<<"Thank you! You entered";
cin>>fileName;
string names[40][2];
int scores[40][6];
int total[40];
float averages[40][3];
char grade[40];
int count;
// why are you redeclaring these variables?
ifstream inputFile;
ofstream outputFile;

I'm unsure what you're trying to do here, as you're redefining inputfn , so you're not really calling anything, plus count doesn't have a type:

void inputfn(string names[][],int scores[][], count);
count=0;
while (fin&&count<40)
// it should be "names" not "name"
{fin>>name[count][0]
>>name[count][1];

for (int col=0; col<6;col++)
{fin>>scores[count][col];}

if (fin.peek()=='\n')fin.ignore();
count++;
}//end of while

for (int row =0; row<count; row++)
{
total [row]=0;
for (int col=0; col<6; col++)
total[row]= total [row] + scores [row][col];
}//end of outer loop

// again, you're using "name" instead of "names"
for (int row=0; row<count; row++)
{cout<<setw(20)<<name[row][0]+' '+name[row][1];

That's pretty much all the errors I can see.

Don't use void main . It's old and outdated, and so instead you should use int main .

void main( ) never was a C / C++ standard right from the interception of the language.


main() must return int. Not void, not bool, not float. int. Just int, nothing but int, only int.Some compilers accept void main(), but that is non-standard and shouldn't be used.

Even if the program with the misdeclared main() "works" (that is, compiles without error, and runs without crashing), it does result in a garbage (random) exit status being returned to the calling environment. You or your command invocation environment may not be noticing that particular glitch right now, but it is a glitch, and it may bite you later.

Hope it cleared the matter.

void main( ) never was a C / C++ standard right from the interception of the language.

What I meant is that Visual C++ is very old, and has been "encouraging" its own standards right from the beginning... (For example, the latest version of Visual Studio complains that the Standard Template Library is "deprecated", which is total crap.) In other words, Visual C++ never complained about void main() , but thanks for clearing that up.

For example, the latest version of Visual Studio complains that the Standard Template Library is "deprecated", which is total crap.

Didnt know about this one but it does the same thing with scanf( ).

Maybe it is hoping to create its own C++ standard within the actual standard, and whats more its actually encouraging newbies to use the non portable functions and headers( stdafx ?).

Maybe we should post a sticky at the top of forum saying "Don't listen to MS's crap". :D

Maybe it is hoping to create its own C++ standard within the actual standard, and whats more its actually encouraging newbies to use the non portable functions and headers( stdafx ?).

Yes, I think that is basically Microsoft's idea. They go against some of the C++ standards, and say, "this isn't our standard".

Maybe we should post a sticky at the top of forum saying "Don't listen to MS's crap". :D

Actually, that may not be such a bad idea. I don't know if you ever read CBoard, but at the moment they have a sticky in the General Discussions on how to port your apps to Visual Studio 2005:
http://cboard.cprogramming.com/showthread.php?t=78903

Probably the most important quote (many thanks to Bubba who kindly wrote this thread):

To get rid of all that deprecated crap define: _CRT_SECURE_NO_DEPRECATE

And sorry, I am getting a little bit off-topic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.