Question

I have a programming assignment for a introductory c++ class and I am really struggling writing...

I have a programming assignment for a introductory c++ class and I am really struggling writing this program.

Below are the assignment requirements, I am unable to use vectors in stl and I keep getting a ton of compiling errors.

Thank you chegg experts. You have really helped me out this semester. Your responses and code has cleared up so many issues ive had.

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.

#include <iostream>

#include <ctime>

#include <cstdlib>

using namespace std;

int main()

{

srand(time(NULL));

string test_password;

int repetitions = 0;

// generate a test password

// loop 100000 and count repetitions

// report to user how many repetitions of test_password

return 0;

}

Sample Output

PuceZebu41$$ was generated 78 times out of 100000 repetitions

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE IN C++:

#include <iostream>

#include <ctime>

#include <cstdlib>

using namespace std;

//function to randomly create a password and return it

string create_password()

{

//declaring the array

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[]={"!$", "$$", "~!~", "^#^"};

//randomly selecting an index in the arrays

int color_index=rand()%6, animal_index=rand()%8;

int number_index=rand()%9, symbol_index=rand()%4;

//using the index to form a string and returning it

return colors[color_index]+animals[animal_index]+numbers[number_index]+symbols[symbol_index];

}

int main()

{

//seeding the generator

srand(time(NULL));

string test_password;

int repetitions = 0; //to count number of repetitions of test password

test_password=create_password(); //generating test password

for(int i=0; i<100000; i++) //iterating 100000 times

{

string password=create_password(); //generating a password

if(password==test_password) //checking if it is test password

repetitions+=1; //incrementing count

}

//count

cout << test_password << " was generated " << repetitions << " out of 100000 repetitions.\n";

return 0;

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
I have a programming assignment for a introductory c++ class and I am really struggling writing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • Hello, I need a c program called int* create_random_array(int n) that returns a random array of...

    Hello, I need a c program called int* create_random_array(int n) that returns a random array of size an. Alternatively, you can initialize a pointer to an array (called Rand) and write a function called void(create_array(int * Rand, int n) which assigns an array of size n to Rand. Note: Plese utilize rand(fi) and srand() from stdlib.h for this code

  • I ONLY NEED PART 4 I HAVE DONE 1,2,3 Arrays This assignment is designed in small...

    I ONLY NEED PART 4 I HAVE DONE 1,2,3 Arrays This assignment is designed in small progressive parts, with the intention of developing the skill of working with arrays. Do each part separately. Include in your submission the code and output for Part I, then the code and output for Part 2, etc. into a Word document. Specification: Part 1. Write a main function that declares an array of 10 int’s. Assign each element in the array a value between...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • Please write a C# program For this part of the lab, you'll be writing methods to...

    Please write a C# program For this part of the lab, you'll be writing methods to work with 1D arrays. We will expect you to know how to create an array, and store and retrieve information from them. Continue working in the same project and “Program.cs” file. You will be generating random numbers, but the class Random is part of the standard library (don’t need any additional using statements). You should consider developing the methods for this project incrementally. In...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • Add a member function template called RemoveRandom to the ArrayBag class (so add it to ArrayBag.h...

    Add a member function template called RemoveRandom to the ArrayBag class (so add it to ArrayBag.h). The RemoveRandom member function should remove a random entry from the list (so use your srand and rand functions). Do not forget to TEST... that means you will need to add the prototype and test with a simple main. All you need to submit though is the member function implementation Add an overloaded constructor to the ArrayBag class (so add it to 2. ArrayBag.h)....

  • (c programming): write a program that contains a function named getName, that does not get any...

    (c programming): write a program that contains a function named getName, that does not get any parameter and returns a character array of a random name from a constant list of 30 names, in a global array. the function returns that random name. each name in the list is a character string that consists of not more than 20 characters(not including finishing 0). the name consists of only characters from the american alphabet (a-zA-Z) and does not contain any "white"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT