// arrays of structs

#include <iostream>
#include <iomanip>
#include <cstdlib>  // for rand()
#include <string>
using namespace std;

struct Thing
{
    string name;
    int randy;
};

const int ArraySize = 5;

void initialize(Thing*);
void print(Thing*);

int main()
{
    Thing stuff[ArraySize];
    initialize(stuff);
    print(stuff);
}

void initialize(Thing* arrayOfThings)
{
    string fiveNames[5] = {"John","Paul","George","Ringo"};
    for (int i = 0; i < ArraySize; i++) {
        arrayOfThings[i].name = fiveNames[i];
        arrayOfThings[i].randy = rand() % 10 + 1;
    }
}

void print(Thing* arrayOfThings)
{
    for (int i = 0; i < ArraySize; i++)
            cout << setw(10) <<  arrayOfThings[i].name << setw(5) << arrayOfThings[i].randy << endl;
}

******  OUTPUT  ******

      John    2
      Paul    8
    George    5
     Ringo    1
             10