axyd icon

CS172_20160503 (In-class Arrays)

axyd | PRO | 05/03/16 03:30:50 PM UTC | 0 ⭐ | 641 👁️ | Never ⏰ | []
C++ |

830 B

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <vector>
using namespace std;
 
int main(){
    int aSize = 30;
    char again = 'y';
    while (again == 'y' | again == 'Y'){
        vector <int> INT(aSize);
        
        for (int i = 0; i < aSize; i++){ //assign value
            cout << "Enter value for array INT at position " << i << ": ";
            cin >> INT.at(i);
        }
 
        vector <int> INT1(INT); //copy arrays
 
 
        cout << "\nThe value of INT1 at position 5 is: " << INT1.at(5) //get value at 5
            << "\nThe capacity of INT1 array is: " << INT1.capacity() << endl
            << "The values of the INT1 are: \n";
 
        for (int x = 0; x < aSize; x++){            
            cout << INT1.at(x) << ",";
            if ((x+1) == aSize){ //clear if 30
                INT1.clear();
                cout << "\n\n";
            }
        }
 
        cout << "\nIs INT1 clear? " << INT1.empty();
        cout << "\nEnter y or Y to go again: ";
        cin >> again;
    }
}

Comments