Home Forums Job & Work Life 죄송한데 C++ 문제 좀 This topic has [3] replies, 0 voices, and was last updated 6 years ago by 1234. Now Editing “죄송한데 C++ 문제 좀” Name * Password * Email Topic Title (Maximum Length 80) 혼자 보고 있는데 이해가 안가는 부분이 있습니다. 문제: Many web sites and software packages require you to create passwords that contain at least one digit and one special character. Your task is to write a program that generates such a password of a given length. The characters should be chosen randomly. 1. We will write a password-generating function and call it from the program’s main function. We could include multiple digits and special characters, but for simplicity, we decide to include just one of each. We need to decide which special characters are valid. For our solution, we will use the following set: + - * / ? ! @ # $ % & we will use only lowercase letters in the English alphabet. 2.There is just one parameter: the length of the password. ( 해결됨: the length of the password 를 입력값으로 잡아주는지....) 3.string make_password(int length) 4.Make an empty string called password. Randomly generate length - 2 letters and append them to password. (해결됨:여기서 왜 이렇게 되는지 ....) Randomly generate a digit and insert it at a random location in password. Randomly generate a symbol and insert it at a random location in password. 5. /** Returns a string containing one character randomly chosen from a given string. @param characters the string from which to randomly choose a character @return a substring of length 1, taken at a random index (왜 substring of length1 이 되는지....) */ string random_character(string characters) (여기서부터는 좀 도움이 필요합니다) /** Inserts one string into another at a random position. @param str the string into which another string is inserted @param to_insert the string to be inserted @return the result of inserting to_insert into str */ string insert_at_random(string str, string to_insert) Now we can translate the pseudocode of Step 4 into C++: string make_password(int length) { string password = ""; ( 해결됨: 여기서 왜 이렇게 잡아주나요?) for (int i = 0; i < length - 2; i++) (해결됨: i=0, i++,이건 알겠는데 i < length - 2 이 부분은 어떻게 이해해야 하는지...) { password = password + random_character("abcdefghijklmnopqrstuvwxyz"); } string random_digit = random_character("0123456789"); password = insert_at_random(password, random_digit); string random_symbol = random_character("+-*/?!@#$%&"); password = insert_at_random(password, random_symbol); return password; } 미리 감사합니다. I agree to the terms of service Update List