I am attempting to write a program which will take and array declared and initialized in the main and set to an array from a class via a constructor.
Here is the array from the main
//Variable declaration
char key[NUM_QUESTIONS] = {'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};//correct answers to test
This is array from the class
class TestGrader
{
private:
char answers[NUM_QUESTIONS];//20 characters which holds the correct answers to the test
Here is the prototype of the function
void setKey(char [NUM_QUESTIONS]);//prototype of setKey function
Here is the constructor
void TestGrader::setKey(char key[NUM_QUESTIONS])
{
for ( int i = 0; i < NUM_QUESTIONS; i++)
{
answers[i] = key[i];
}//End for ( int i = 0; i < NUM_QUESTIONS; i++)
}//End setKey function definition
I have done some modification so I could print out the answers array to see what it is and what prints is a line of strange symbols. I'm not sure what's wrong I can't find any errors in it. If further info is needed please let me know. Any help would very appreciated.
char key[NUM_QUESTIONS] = {'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};//correct answers to test
This is array from the classclass TestGrader
{
private:
char answers[NUM_QUESTIONS];//20 characters which holds the correct answers to the test
Here is the prototype of the function
void setKey(char [NUM_QUESTIONS]);//prototype of setKey function
Here is the constructor
void TestGrader::setKey(char key[NUM_QUESTIONS])
{
for ( int i = 0; i < NUM_QUESTIONS; i++)
{
answers[i] = key[i];
}//End for ( int i = 0; i < NUM_QUESTIONS; i++)
}