I have this homework assignment that I have to do but it keeps telling me that I can't pass the 2-D array by refernce. How else would I be able to make a function handle the array initialization part? Help please
here's the code:
/***************************************************************
* Homework 11: Graded In-Class Assignment (11/3/11)
*
* Modify the In-Class Exercise-3 (11/3/11) so that
* 1. The information entry is handled by an appropriate function.
* The data will be stored in a two dimensional array of type string.
* 2. Program saves/writes the entered information in a tabular format
* to a file, using a function.
* 3. All functions will be called by main( ).
*
* DUE: 11/10/2011
*****************************************************************/
/*********************************************
* file name: gradedinclass.cpp
* programmer name: Hayder Sharhan
* date created: 11_9_11
* date of last revision:
* details of the revision:
* short description: using 2d arrays with functions
**********************************************/
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
// Declared constants
constint NUMBER_STUDENTS = 5;
constint NUMBER_VALUES = 3;
// Function prototypes
void programDescription();
// Add function prototypes here
void loadArray(string&);
void writeArray();
int main()
{
// Program description
programDescription();
// Declare variables
string stuInfo[NUMBER_STUDENTS][NUMBER_VALUES];
// Initialize variables -- load array data from user input
loadArray(stuInfo);
// Display results
writeArray(stuInfo);
return 0;
}
void programDescription()
{
cout << "This program reads student grade information from" << endl
<< "the user and displays it in a tabular format" << endl;
}
// Function implementation for loadArray()
void loadArray(string& stuInfo[NUMBER_STUDENTS][NUMBER_VALUES])
{
for (int i = 0; i < NUMBER_STUDENTS; i++)
{
for (int j=0; j < NUMBER_VALUES; j++)
{
cout << "\nEnter information for student " << i + 1 << ": " << endl;
cout << "\tLast Name>> ";
cin >> stuInfo[i][j];
cout << "\tOverall Average>> ";
cin >> stuInfo[i][j];
cout << "\tLetter Grade>> ";
cin >> stuInfo[i][j];
}
}
}
// Function implementation for writeArray()
void writeArray(string stuInfo[NUMBER_STUDENTS][NUMBER_VALUES])
{
// Display table header line
cout << endl
<< "Last Overall Letter" << endl
<< "Name Average Grade" << endl
<< "---- ------- ------" << endl;
// Display table data
for (int i = 0; i < NUMBER_STUDENTS; i++)
{
cout << left << setw(15);
for (int j = 0; j < NUMBER_VALUES; j++)
{
cout << stuInfo[i][j] << setw(20);
}
cout << endl;
}
}