Vector

The STL Vector container

// Project 04-02
// Name: VectorData

#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int>myDataVector{};

    int inputValue{};

    cout << "Enter a positive integer to add to the vector, or negative integer to quit!" << endl;
    cin >> inputValue;
    while (inputValue >= 0)
    {
        myDataVector.push_back(inputValue);
        cout << "Enter a positive integer to add to the vector, or negative integer to quit!" << endl;
        cin >> inputValue;
    }
    
    cout << endl;
    cout << "Now here are double the amounts: " << endl;

    for (int value : myDataVector) {
        cout << value*2 << endl;
    }

    return 0;
}
// Project 04-03
// Name: Weight Tracking with Parallel Vectors

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    
    const int NUM_PEOPLE = 5;
    vector<string>fullNames{};
    vector<double>weights{};

    string fullname{};
    int weight{};

    for (int i = 0; i < NUM_PEOPLE; i++) {
        cout << "Please enter a name: ";
        getline(cin, fullname);
        cout << "Please enter " << fullname << "'s weight: ";
        cin >> weight;
        cin.get();  // Consume newline character
        fullNames.push_back(fullname);
        weights.push_back(weight);
    }

    cout << endl << endl;

    for ( int i = 0; i < NUM_PEOPLE; i++) {
        cout << fullNames[i] << " weighs " << weights[i] << " Kg" << endl;
    }

    return 0;
}