Advertisement
JamesDamico

BCS 370 - Assignment 1

Sep 8th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <climits>
  6. #include <random>
  7.  
  8. void randomStream(std::string &fileName, int &length);
  9.  
  10. int main()
  11. {
  12. std::string fileName;
  13. int length;
  14.  
  15. std::cout << "Please input a filename:" << std::endl;
  16. std::cin >> fileName;
  17.  
  18. std::cout << "How many iterations:" << std::endl;
  19. std::cin >> length;
  20.  
  21. randomStream(fileName, length);
  22.  
  23. return 0;
  24. }
  25.  
  26.  
  27. void randomStream(std::string &fileName, int &length)
  28. {
  29. std::ofstream outFile;
  30. outFile.open(fileName);
  31.  
  32. if (outFile)
  33. {
  34. std::random_device rd;
  35. std::mt19937 gen(rd());
  36. std::uniform_int_distribution<> dis(0, 5);
  37.  
  38. for (int i = 0; i < length; ++i)
  39. {
  40. int randNum = dis(gen);
  41.  
  42. if (randNum == 1){
  43. std::uniform_int_distribution<> dis(INT_MIN, INT_MAX);
  44. int minMax = dis(gen);
  45. outFile << "A " << minMax << std::endl;
  46. }
  47. else if (randNum == 2){
  48. outFile << "D" << std::endl;
  49. }
  50. else if (randNum == 3){
  51. outFile << "P" << std::endl;
  52. }
  53. else if (randNum == 4) {
  54. outFile << "E" << std::endl;
  55. }
  56. else if (randNum == 5) {
  57. outFile << "C" << std::endl;
  58. }
  59. else {
  60. outFile << "S" << std::endl;
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement