Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in C++ Description The purpose of this challenge is to employ the use of basic f

ID: 3596208 • Letter: I

Question

in C++

Description

The purpose of this challenge is to employ the use of basic functions and arrays. This challenge will allow you to create a strong password as suggested by this xkcd.

Do Not Use

Vectors from the stl

Requirements

1.Create a function string create_password()

2.In the create_password() function:

1.Create a string array called colors and initialize it to the following string values – be sure to indicate the first letters as uppercase for readability: Puce, Fuchsia, Sarcoline, Falu, Wenge, Sinopia

2.Create a string array called animals and initialize it to the following string values – be sure to indicate the first letters as uppercase for readability: Zebu, Ibex, Kudu, Lynx, Fugu, Tarsier, Narwhal, Okapi

3.Create a string array called numbers and initialize it to the following string values (they look like numbers, but make sure the values are set as strings): 31, 41, 59, 26, 53, 14, 867, 5309, 117

4.Create a string array called symbols and initialize it to the following string values: !$, $$, ~!~, ^#^

3.In the create_password() function:

1.You will use the rand() function to generate a random number that will be used as an index into each of the arrays. To use the rand() function to generate integers between 0 and 7, you might write something like animal_index = rand() % 8

   2.You will need to generate random integers to act as indexes into each of the arrays. Make sure that the indexes for each    array don’t go out of bounds of the arrays to avoid segmentation faults.

3.You will return a string that is a concatenation of a color, an animal, a number, and some symbols. A sample result of the    function is PuceZebu41$$ – this would be the result of random integers being generated as array indexes as follows: 0 for    the colors array, 0 for the animals array, 1 for the numbers array, 1 for the symbols array

4.in main():

   1.Create a string test_password

   2.Call the create_password() once to generate a random password and assign it to test_password

   3.Then, write a loop that will run 100,000 times calling the create_password() function within the loop. Examine the value    returned by the function and compare it to test_password. If the values match, increment a counter.

4.After the loop, report to the user the value of test_password and how many times the value stored in test_password was    generated within the loop. Basically, we are testing how often the function will generate the same password.

Sample main()

You will need to at least have your code as indicated by the sample main() below. You should have the included header files and srand() function. Then, add the rest of the functionality as indicated by the descriptions above.

Sample Output

Explanation / Answer

Here is the code :

#include <bits/stdc++.h>

using namespace std;

string create_password() {

//create string arrays
string colors[] = {"Puce", "Fuchsia", "Sarcoline", "Falu", "Wenge", "Sinopia"};
string animals[] = {"Zebu", "Ibex", "Kudu", "Lynx", "Fugu", "Tarsier", "Narwhal", "Okapi"};
string numbers[] = {"31", "41", "59", "26", "53", "14", "867", "5309", "117"};
string symbols[] = {"!$", "$$","~!~" ,"^#^" };
  
//generate random inde for all arrays
int color_index = rand() % 6;
int animal_index = rand() % 8;
int number_index = rand() % 9;
int symbol_index = rand() % 4;
  
//return concatenated string using random index strings from arrays
return colors[color_index] + animals[animal_index] + numbers[number_index] + symbols[symbol_index];
}

int main() {
  
string test_password;
// generate a test password
test_password = create_password();
  
// loop 100000 and count repetitions
int counter = 0;
for(int i = 0;i < 100000;i++){
  
if(create_password() == test_password)
counter++;
  
}
  
// report to user how many repetitions of test_password
cout<<"The password : "<<test_password<<" was generated "<<counter<<" times";
return 0;
}

Output :
The password : FuchsiaNarwhal31^#^ was generated 72 times


**If you have any query , please feel free to comment with details.
**Happy leaning :)