在这个并行数组中,我看不到或弄清楚为什么要打印内存地址而不是输入的值。求C++大神赐教,指点一些关于这个问题的好教程,以便我学习。代码如下。
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <ios>
using namespace std;
// Assign a constant
const int rowSize = 6;
const int columnSize = 4;
void displayWelcome()
{
cout << "\tCorporation X\n";
cout << "Quartily Reports for the six Entities\n";
cout << "Showing you the Highest Average out of the six\n";
cout << endl;
}
// Assign Words in a row of 6
string* entitiesArray(string(entities)[rowSize])
{
string entitiesName[rowSize] = {"East ","West ","Central ","Midwest"
,"South ","South East "};
//string entitiesName;
for(int i=0; i < rowSize; i++)
{
cout << entitiesName[i] << endl;
}
return entitiesName;
}
// Assign numbers to a 6x4
double* entriesArray(double(corpArray)[rowSize][columnSize])
{
// Assign Random Numbers to the Array
srand(time(0));
double rowSum = 0.0, average = 0.0;
for (int r = 0; r < rowSize; ++r)
{
rowSum = 0;
for (int c = 0; c < columnSize; ++c)
{
corpArray[r][c] = rand() % 101;
cout << setw(5) << left << corpArray[r][c] << " ";
rowSum += corpArray[r][c];
average = rowSum / 4;
}
cout << average;
cout << endl;
}
return 0;
}
// Parallel Array This is where is prints the Memory Address
void pArray(string &theEntitiesArray,double &theEntriesArray)
{
string entity = &theEntitiesArray;
double entry = &theEntriesArray;
for(int row_index = 0; row_index < 6; row_index++)
{
cout << setw(10) << entity <<endl;
for (int col_index = 0; col_index < 4; col_index++)
{
cout << setw(10) << entry << endl;
}
}
}
int main(int argc, const char * argv[])
{
// Declare an Array & Variables
double corpArray[rowSize][columnSize];
string entities[rowSize];
double* theEntriesArray;
string* theEntitiesArray;
char parallelArray;
displayWelcome();
theEntitiesArray = entitiesArray(entities);
theEntriesArray = entriesArray(corpArray);
pArray(*theEntitiesArray, *theEntriesArray);
cout << endl;
return 0;
}