Answer to Question #43788 in C++ for tim

Question #43788
Write a program that creates two string arrays, one to store names of 5 boys and another to
store names of 5 girls. Read the names from the user. The program then matches the boys
and the girls randomly and displays the 5 pairs of matched couples.

Your program should not repeat any boy’s or girl’s name in the matching.
1
Expert's answer
2014-07-04T10:23:49-0400
#include <iostream>
#include <string>
#include <algorithm> // for random_shuffle()
#include <ctime> // for time()
#include <cstdlib> // for srand()

using namespace std;

int main()
{
stringboy[5] = {};
stringgirl[5] = {};

// read boys name
for (int i = 0; i < 5; i++)
{
cout << "Enter boy name: ";
cin >> boy[i];
}

// read girls name
for (int i = 0; i < 5; i++)
{
cout << "Enter girl name: ";
cin >> girl[i];
}

// for new random eachtime
srand(time(0));
// girls randomizing
random_shuffle(&girl[0], &girl[5]);

for (int i = 0; i < 5; i++)
{
cout << "Pair " << i + 1 << ": " << boy[i] << " & " << girl[i] << endl;
}

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS