Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************************************
- PROGRAM: Assignment 1
- AUTHOR: Sean Vogel
- LOGON ID z1729629
- DUE DATE: 1/21/2014
- FUNCTION: Sort randomly generated numbers
- INPUT: none
- OUTPUT: A table of sorted integers
- **************************************************************************/
- #include “/home/onyuksel/courses/340/progs/p1/prog1.h”
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- #include <algorithm>
- #include <vector>
- /********************************************************************************
- FUNCTION: void getRndNums(std::vector<int>& v)
- ARGUMENTS: std::vector to store random numbers
- RETURNS: void
- NOTES: store VEC_SIZE randomly generated numbers in vector
- ************************************************************************************/
- void getRndNums(std::vector<int>& v);
- /********************************************************************************
- FUNCTION: void printVec(std::vector<int>& v)
- ARGUMENTS: std::vector of integers to print to stdout
- RETURNS: void
- NOTES: print integers in vector to stdout
- ************************************************************************************/
- void printVec(std::vector<int>& v);
- const int VEC_SIZE = 250;
- const int LOW = 1;
- const int HIGH = 10000;
- const int SEED = 1;// time(0);
- const int NUM_ITEMS = 12;
- const int ITEM_W = 5;
- int main()
- {
- std::vector<int> iVec;
- getRndNums(iVec);
- std::sort(iVec.begin(), iVec.end());
- printVec(iVec);
- }
- void getRndNums(std::vector<int>& v)
- {
- srand(SEED);
- for (std::size_t i = 0; i < VEC_SIZE; ++i)
- {
- v.push_back(rand() % (HIGH - LOW + 1) + LOW);
- }
- }
- void printVec(std::vector<int>& v)
- {
- const std::size_t size = v.size();
- for (std::size_t i = 0; i < size; ++i)
- {
- std::cout << std::setw(ITEM_W) << v[i];
- if (!((i + 1) % NUM_ITEMS))
- std::cout << std::endl;
- }
- std::cout << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment