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...
in this code I have used array two times . I need a way to make...
in this code I have used array two times . I need a way to make the program functional using a string to store the results and print it again later . this game should be array free. import java.util.Scanner; import java.util.Random;//starter code provided public class inputLap { public static char roller; public static String playerName; public static int printed=0; public static int rounds=8,lives=0,randy; public static int tries[]=new int[4];//use arrays to store number of tries in each life public static...
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.
Hello, I need to convert this java array into an array list as I am having...
Hello, I need to convert this java array into an array list as I am having trouble please. import java.util.Random; import java.util.Scanner; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in); int[] data = new int[1000]; int count = 0; while (!choice.equals("No")) { int randomInt = 2 * (random.nextInt(5) + 1); System.out.println(randomInt); data[count++] = randomInt; System.out.print("Want another random number (Yes / No)? "); choice =...
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...
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?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT