I'm a newbie to C++ programming. Need some help working with STD::arrays. I'm trying to pass the values of an array to a function, then display the value. Please see code below. So far i am able to pass the value to getName function but nothing gets pass to setName. Any help is greatly appreciated.
const size_t num = 20;
array< string, num > one = {"Mike Johnson Hary Da"};
array< string, num > test = {"Hary Da Johnson Mike"};
You are creating two array type data variables "one" and "test", that is supposed to have have 20 strings. However, you have given a default value for the first element in only in both variables. So, both "one" and "test" have element on 0th index, and rest of 19 indices have empty string.
1 2
Records studentone(one);
Records studenttwo(test);
You are then creating records using those variables "one" and "test".
1 2 3 4 5 6 7 8
for ( size_t i = 0; i < num; ++i)
studentone.setName(one[i]);
for ( size_t n = 0; n < num; ++n)
studenttwo.setName(test[n]);
studentone.displayMessage();
studenttwo.displayMessage();
In the for loop, you are looping 20 times, for both "studentone" and "studenttwo" and setting values of "one" and "test" instances private string variable "fullName" 20 times using variable "one" and "test" in main function. However, "one" and "test" both contain empty string for last 19 indices. So, display message will display the last element that was set, which is basically an empty string.