naraku9333

Untitled

Jan 8th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. /***********************************************************************
  2. PROGRAM:        Assignment 1
  3. AUTHOR:         Sean Vogel
  4. LOGON ID        z1729629
  5. DUE DATE:       1/21/2014
  6.  
  7. FUNCTION:       Sort randomly generated numbers
  8.  
  9. INPUT:          none
  10.  
  11. OUTPUT:         A table of sorted integers
  12. **************************************************************************/
  13. #include “/home/onyuksel/courses/340/progs/p1/prog1.h”
  14. #include <iostream>
  15. #include <ctime>
  16. #include <iomanip>
  17. #include <algorithm>
  18. #include <vector>
  19.  
  20. /********************************************************************************
  21. FUNCTION:       void getRndNums(std::vector<int>& v)
  22.  
  23. ARGUMENTS:      std::vector to store random numbers
  24.  
  25. RETURNS:        void
  26.  
  27. NOTES:          store VEC_SIZE randomly generated numbers in vector
  28. ************************************************************************************/
  29. void getRndNums(std::vector<int>& v);
  30.  
  31. /********************************************************************************
  32. FUNCTION:       void printVec(std::vector<int>& v)
  33.  
  34. ARGUMENTS:      std::vector of integers to print to stdout
  35.  
  36. RETURNS:        void
  37.  
  38. NOTES:          print integers in vector to stdout
  39. ************************************************************************************/
  40. void printVec(std::vector<int>& v);
  41.  
  42. const int VEC_SIZE = 250;
  43. const int LOW = 1;
  44. const int HIGH = 10000;
  45. const int SEED = 1;// time(0);
  46. const int NUM_ITEMS = 12;
  47. const int ITEM_W = 5;
  48.  
  49. int main()
  50. {
  51.     std::vector<int> iVec;
  52.     getRndNums(iVec);
  53.     std::sort(iVec.begin(), iVec.end());
  54.     printVec(iVec);
  55. }
  56.  
  57. void getRndNums(std::vector<int>& v)
  58. {
  59.     srand(SEED);
  60.     for (std::size_t i = 0; i < VEC_SIZE; ++i)
  61.     {
  62.         v.push_back(rand() % (HIGH - LOW + 1) + LOW);
  63.     }
  64. }
  65.  
  66. void printVec(std::vector<int>& v)
  67. {
  68.     const std::size_t size = v.size();
  69.     for (std::size_t i = 0; i < size; ++i)
  70.     {
  71.         std::cout << std::setw(ITEM_W) << v[i];
  72.         if (!((i + 1) % NUM_ITEMS))
  73.             std::cout << std::endl;
  74.     }
  75.     std::cout << std::endl;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment