axyd

CS172_20160503 (In-class Arrays)

May 3rd, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main(){
  6.     int aSize = 30;
  7.     char again = 'y';
  8.     while (again == 'y' | again == 'Y'){
  9.         vector <int> INT(aSize);
  10.        
  11.         for (int i = 0; i < aSize; i++){ //assign value
  12.             cout << "Enter value for array INT at position " << i << ": ";
  13.             cin >> INT.at(i);
  14.         }
  15.  
  16.         vector <int> INT1(INT); //copy arrays
  17.  
  18.  
  19.         cout << "\nThe value of INT1 at position 5 is: " << INT1.at(5) //get value at 5
  20.             << "\nThe capacity of INT1 array is: " << INT1.capacity() << endl
  21.             << "The values of the INT1 are: \n";
  22.  
  23.         for (int x = 0; x < aSize; x++){           
  24.             cout << INT1.at(x) << ",";
  25.             if ((x+1) == aSize){ //clear if 30
  26.                 INT1.clear();
  27.                 cout << "\n\n";
  28.             }
  29.         }
  30.  
  31.         cout << "\nIs INT1 clear? " << INT1.empty();
  32.         cout << "\nEnter y or Y to go again: ";
  33.         cin >> again;
  34.     }
  35. }
Add Comment
Please, Sign In to add comment