Question

In: Computer Science

I need to be able to store 5000 names into an array. I currently have a...

I need to be able to store 5000 names into an array. I currently have a code that generates one random name. I just need to generate an array of 5000 the same way.

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <iomanip>

using namespace std;

string RandomFirstGen(int namelength);

int main(){

srand(time(NULL));
int namelength = rand()%(16-8+1)+8;
cout<<"name is: "<<RandomFirstGen(namelength)<<endl;

return 0;
}

string RandomFirstGen(int namelength){
for (int i=0; i<=5000 ; i++){
const int MAX = 26;
char alphabet[MAX] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z'};
string name = "";
for (int i = 0; i < namelength; i++)
name = name + alphabet[rand() % MAX];
return name;

}
}

Solutions

Expert Solution

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <iomanip>

using namespace std;

string RandomFirstGen(int namelength);

int main(){

        srand(time(NULL));
        int namelength = rand()%(16-8+1)+8;
        //created array with 5000 to store names
        string arr[5000];
        //iterating 5000 times to generate names
        for(int i=0;i<5000;i++){
                namelength = rand()%(16-8+1)+8;
                //getting the name and putting in the array
                arr[i]=RandomFirstGen(namelength);
        }
        //printing the 5000 names
        for(int i=0;i<5000;i++)
                cout<<"name "<<i+1<<" is: "<<RandomFirstGen(namelength)<<endl;

        return 0;
}

string RandomFirstGen(int namelength){
for (int i=0; i<=5000 ; i++){
const int MAX = 26;
char alphabet[MAX] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z'};
string name = "";
for (int i = 0; i < namelength; i++)
name = name + alphabet[rand() % MAX];
return name;

}
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

Please Like and Support me as it helps me a lot


Related Solutions

I need the code for a C++ program that creates an array of 5000 String objects...
I need the code for a C++ program that creates an array of 5000 String objects that will store each word from a text file. The program will read in each word from a file, and store the first 5000 words in the array. The text file should be read in from the command line.
Java homework problem: I need the code to be able to have a message if I...
Java homework problem: I need the code to be able to have a message if I type in a letter instead of a number. For example, " Please input only numbers". Then, I should be able to go back and type a number. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class LoginGui {    static JFrame frame = new JFrame("JFrame Example");    public static void main(String s[]) {        JPanel panel...
Create an unsorted LIST class. Each list should be able to store 100 names.
Create an unsorted LIST class. Each list should be able to store 100 names.
c++ I need a code that will fill an array size of 1000, an array of...
c++ I need a code that will fill an array size of 1000, an array of size 2000, and an array size of 10000, with random int values. Basically like this: array1[1000] = filled all with random numbers array2[2000] = filled all with random numbers array3[10000] = filled all with random numbers C++ no need for print
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't...
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't need the number entries. I attached the balance sheet in case you need it for reference Problem - Your required tasks are as follows: On the designated worksheet, prepare in journal entry form the adjusting journal entries for the following items. Letter entries to correspond to the below information and present them in alphabetical order. (Round all numbers to the nearest dollar) On June...
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't...
I JUST NEED THE NAMES OF THE ADJUSTING ENTRY ACCOUNTS FOR A) THROUGH I). I don't need the numbers. I attached the balance sheet in case you need it for reference Problem - Your required tasks are as follows: On the designated worksheet, prepare in journal entry form the adjusting journal entries for the following items. Letter entries to correspond to the below information and present them in alphabetical order. (Round all numbers to the nearest dollar) a) On June...
I have to figure this out in Excel. I have 4 columns with names in a...
I have to figure this out in Excel. I have 4 columns with names in a spreadsheet. I am trying to find the duplicates between columns and count them. Example A B C D Steve John Chris John Sarah Steve John Sarah Carl Chris Paul Paul Jenna Logan Sarah Jenna Moe Norman Joe Logan I am trying to identify the names that show up in multiple columns and count the times they show up, all in Excel. Which excel functions...
Create an array list (names) that will hold the names of several hall of fame soccer...
Create an array list (names) that will hold the names of several hall of fame soccer players. 2. Place your name on the screen as the master recorder:              “Master Hall of Fame Recorder: John Paul Jones” 3. Ask the user how many names they would like to record. (input 5 when the program runs) 4. Create a loop that will ask for the “Hall of fame member #1: “, etc Add in the following names: Pele Rooney Maradona Messi...
A grocery store chain like Tesco Malaysia need to be responsive and be able provide customers what they need, when they need it, where they need it.
A grocery store chain like Tesco Malaysia need to be responsive and be able provide customers what they need, when they need it, where they need it.Determine FOUR (4) responsive approaches that can be taken by a convenience store supply chain to be responsive?Based on above answers, describe TWO (2) risks in above approaches?
I need to write a function the will take in an array (of type double), and...
I need to write a function the will take in an array (of type double), and will return the array with all of the elements doubled while using pass-by-reference and addressing and/or pointers. This is what i have so far, but im messing up in line 31 where i call the function i believe so im not returning the correct array? please help edit. #include <iostream> #include <iomanip> using namespace std; double *doubleArray ( double arr[], int count, int SIZE);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT