Guest User

Untitled

a guest
Jun 29th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h>
  4. #include <fstream>
  5. #include <time.h>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. menu:
  13. system("cls");
  14.  
  15. string choice;
  16. string username;
  17. string passLength;
  18. string lowercases = "abcdefghijklmnopqrstuvqxyz";
  19. string uppercases = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  20. string numbers = "1234567890";
  21. string symbols = "`~!@#$%^&*()_+-={[}]|\:'<,>.?/";
  22. string password;
  23. string sym;
  24. string num;
  25. string upper;
  26. string lower;
  27. string choices[4];
  28. string exit;
  29. string word;
  30. string strx;
  31. bool playingGame = true;
  32. int inty;
  33. int intx;
  34. int number;
  35. bool upperCase = false;
  36. bool lowerCase = false;
  37. bool IsSymbols = false;
  38. bool IsNumbers = false;
  39. bool requiredLength = true;
  40. bool userLength = true;
  41. bool length = true;
  42. bool isLetter = false;
  43. bool response1 = true;
  44. bool response2 = true;
  45. bool response3 = true;
  46. bool response4 = true;
  47. bool palindromeIdentifier = true;
  48.  
  49. cout << " Main Menu" << endl;
  50. cout << " ----------------" << endl;
  51. cout << endl;
  52. cout << "Choose a program to run:" << endl;
  53. cout << endl;
  54. cout << "1. Password Generator" << endl;
  55. cout << "2. Palindrome Identifier" << endl;
  56. cout << "3. FizzBuzz" << endl;
  57. cout << endl;
  58. cout << "4. Exit" << endl;
  59. cout << endl;
  60. getline(cin, choice);
  61. if (choice == "1")
  62. {
  63. system("cls");
  64. srand(time(NULL));
  65. while (userLength)
  66. {
  67. cout << "Enter a username:" << endl;
  68. getline(cin, username);
  69. if (username.length() >= 1)
  70. {
  71. userLength = false;
  72. cout << endl;
  73. }
  74. else
  75. {
  76. cout << "You must enter at least 1 character" << endl;
  77. cout << endl;
  78. }
  79. }
  80.  
  81. while (requiredLength)
  82. {
  83. cout << "Enter a length for your password (At least 15 characters recommended):" << endl;
  84. getline(cin, passLength);
  85. cout << endl;
  86. try
  87. {
  88. intx = stoi(passLength);
  89. }
  90. catch (invalid_argument)
  91. {
  92. intx = 0;
  93. }
  94. if (intx <= 5 || intx >= 129)
  95. {
  96. cout << "You must enter number between between 6 and 128." << endl;
  97. cout << endl;
  98. }
  99. else
  100. {
  101. requiredLength = false;
  102. }
  103. }
  104.  
  105. while (response1)
  106. {
  107. cout << "Include uppercase characters?: (yes/no)" << endl;
  108. getline(cin, upper);
  109. if (upper == "yes" || upper == "Yes" || upper == "y")
  110. {
  111. upperCase = true;
  112. response1 = false;
  113. }
  114. else if (upper == "no" || upper == "No" || upper == "n")
  115. {
  116. uppercases.clear();
  117. response1 = false;
  118. }
  119. else
  120. {
  121. cout << endl;
  122. cout << "Please type yes or no." << endl;
  123. }
  124. cout << endl;
  125. }
  126.  
  127. while (response2)
  128. {
  129. cout << "Include lowercase characters?: (yes/no)" << endl;
  130. getline(cin, lower);
  131. if (lower == "yes" || lower == "Yes" || lower == "y")
  132. {
  133. lowerCase = true;
  134. response2 = false;
  135. }
  136. else if (lower == "no" || lower == "No" || lower == "n")
  137. {
  138. lowercases.clear();
  139. response2 = false;
  140. }
  141. else
  142. {
  143. cout << endl;
  144. cout << "Please type yes or no." << endl;
  145. }
  146. cout << endl;
  147. }
  148.  
  149. while (response3)
  150. {
  151. cout << "Include numbers?: (yes/no)" << endl;
  152. getline(cin, num);
  153. if (num == "yes" || num == "Yes" || num == "y")
  154. {
  155. IsNumbers = true;
  156. response3 = false;
  157. }
  158. else if (num == "no" || num == "No" || num == "n")
  159. {
  160. numbers.clear();
  161. response3 = false;
  162. }
  163. else
  164. {
  165. cout << endl;
  166. cout << "Please type yes or no." << endl;
  167. }
  168. cout << endl;
  169. }
  170.  
  171. while (response4)
  172. {
  173. cout << "Include symbols?: (yes/no)" << endl;
  174. getline(cin, sym);
  175. if (sym == "yes" || sym == "Yes" || sym == "y")
  176. {
  177. IsSymbols = true;
  178. response4 = false;
  179. }
  180. else if (sym == "no" || sym == "No" || sym == "n")
  181. {
  182. symbols.clear();
  183. response4 = false;
  184. }
  185. else
  186. {
  187. cout << endl;
  188. cout << "Please type yes or no." << endl;
  189. }
  190. cout << endl;
  191. }
  192.  
  193. choices[0] = lowercases;
  194. choices[1] = uppercases;
  195. choices[2] = symbols;
  196. choices[3] = numbers;
  197.  
  198. if (IsSymbols || IsNumbers || lowerCase || upperCase == true)
  199. {
  200. while (length)
  201. {
  202. if (password.length() == intx)
  203. {
  204. length = false;
  205. cout << "Your username is: " << username << endl;
  206. cout << "Your password is: " << password << endl;
  207. ofstream file;
  208. file.open("C:/Users/iD Student/Desktop/" + username + ".txt");
  209. file << "Username: " << username << endl;
  210. file << "Password: " << password << endl;
  211. file.close();
  212. cout << endl;
  213. cout << "Your login has been saved to the desktop as " << username << ".txt" << endl;
  214. cout << endl;
  215. cout << "Press enter to return to the menu." << endl;
  216. getline(cin, exit);
  217. system("cls");
  218. goto menu;
  219. }
  220. else
  221. {
  222. number = rand() % 4;
  223. if (choices[number].length() >= 1)
  224. {
  225. password += choices[number][rand() % choices[number].length()];
  226. }
  227. else
  228. {
  229. number = rand() % 4;
  230. }
  231. }
  232. }
  233. }
  234. else
  235. {
  236. cout << "You must pick at least one type of character to generate a password." << endl;
  237. cout << "Press enter to return to the menu." << endl;
  238. getline(cin, exit);
  239. system("cls");
  240. goto menu;
  241. }
  242. }
  243. else if (choice == "2")
  244. {
  245. system("cls");
  246. cout << "Insert a word:" << endl;
  247. getline(cin, word);
  248.  
  249. while (palindromeIdentifier)
  250. {
  251. if (word.length() <= 1)
  252. {
  253. cout << "That is a palindrome." << endl;
  254. palindromeIdentifier = false;
  255. cout << "Press enter to return to the menu." << endl;
  256. cout << endl;
  257. getline(cin, exit);
  258. system("cls");
  259. goto menu;
  260. }
  261.  
  262. else if (word[0] == word[word.length() - 1])
  263. {
  264. word.erase(word.begin());
  265. word.erase(word.end() - 1);
  266. }
  267.  
  268. else
  269. {
  270. cout << "That is not a palindrome." << endl;
  271. palindromeIdentifier = false;
  272. cout << "Press enter to return to the menu." << endl;
  273. cout << endl;
  274. getline(cin, exit);
  275. system("cls");
  276. goto menu;
  277. }
  278. }
  279. }
  280. else if (choice == "3")
  281. {
  282. system("cls");
  283. while (playingGame)
  284. {
  285. cout << "Insert a number" << endl;
  286. getline(cin, strx);
  287. cout << endl;
  288. try
  289. {
  290. inty = stoi(strx);
  291. }
  292. catch (invalid_argument)
  293. {
  294. inty = 2;
  295. }
  296.  
  297. if ((inty % 3 == 0) && (inty % 5 == 0))
  298. {
  299. cout << "FizzBuzz" << endl;
  300. cout << endl;
  301. cout << "Press enter to return to the menu." << endl;
  302. getline(cin, exit);
  303. system("cls");
  304. goto menu;
  305. }
  306. else if (inty % 3 == 0)
  307. {
  308. cout << "Buzz" << endl;
  309. cout << endl;
  310. cout << "Press enter to return to the menu." << endl;
  311. getline(cin, exit);
  312. system("cls");
  313. goto menu;
  314. }
  315. else if (inty % 5 == 0)
  316. {
  317. cout << "Fizz" << endl;
  318. cout << endl;
  319. cout << "Press enter to return to the menu." << endl;
  320. getline(cin, exit);
  321. system("cls");
  322. goto menu;
  323. }
  324. else
  325. {
  326. cout << "The number must be divisible by 3, 15, or both." << endl;
  327. cout << endl;
  328. }
  329. }
  330. }
  331. else if (choice == "4")
  332. {
  333. system("exit");
  334. }
  335. else
  336. {
  337. cout << "Please select a valid option." << endl;
  338. cout << "Press enter to restart" << endl;
  339. getline(cin, exit);
  340. goto menu;
  341. }
  342. }
Add Comment
Please, Sign In to add comment