Advertisement
rinab333

CSCI 340 assign 1

Jul 16th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. //terina burr
  2. //section 1
  3.  
  4. //due 09/06/15
  5.  
  6. //assignment one
  7.  
  8. #include <iostream>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <algorithm>
  12. #include <iomanip>
  13. using namespace std;
  14. int LOW = 1;
  15. int HIGH = 10000;
  16. int ITEM_W = 5;
  17. int NO_ITEMS =12;
  18. void genRndNums( vector<int>& v, int vec_size, int seed );
  19. //puts random numbers from one to ten thousand into vector v
  20.  
  21. void printVec( const vector<int>& v, int vec_size );
  22. //displays the vector to the screen
  23.  
  24. int main() {
  25.  
  26.  
  27.     vector<int> v;
  28.  
  29.     genRndNums( v, 100, 9 );
  30.  
  31.     sort(v.begin(), v.end());
  32.  
  33.     printVec(v, 100);
  34.  
  35.  
  36.     return 0;
  37.  
  38. }
  39.  
  40. void genRndNums( vector<int>& v, int vec_size, int seed ) {
  41.  
  42.     srand(seed);
  43.     int x;
  44.     for(int i = 0; i<vec_size; i++)
  45.     {
  46.         x = rand() % HIGH + LOW;
  47.         v.push_back(x);
  48.     }
  49.  
  50.  
  51. }
  52.  
  53.  
  54.  
  55. void printVec( const vector<int>& v, int vec_size ){
  56.  
  57.  
  58.     for(int   i =0; i < vec_size; i++)
  59.         {
  60.              cout.width(ITEM_W);
  61.             cout <<v[i];
  62.             cout.width(ITEM_W);        
  63.             if((i+1) % NO_ITEMS == 0)
  64.             {
  65.                  cout<<endl;
  66.  
  67.             }
  68.         }      
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement