#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    16
    Rep Power
    0

    I need to learn more about Vectors


    I am doing a program that declares a vector of real numbers, and inputs values until a 0 is entered. Add the values to the vector by using push_back(), and compute bothe the average and the maximum value of the numbers. Output the average and the maximum. The use double zero = 0.0; //start maxt at -infinity double max = -1.0/zero; These states will initialize max to have the infinity value. The first real number entered will become the new maximum.

    I am not asking for anyone to write the code, but to tell me if anyone knows of any good websites that I can go to so I will understand about vectors better so I can do this program. I am totally confused on the whole vector thing. Thanks.
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    Vectors are really easy to use:

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <vector>
    
    using namespace std;
    
    int main(){
        int i, j;
        vector < double > myVect;
    
        srand(10);
        //load up a bunch of data...
        for (i=0; i<5; i++){
            myVect.push_back((double) rand() + ((double)rand() / 1000.0));
        }
    
        cout << "Read data out using iterators...\n";
        vector < double >::iterator iter = myVect.begin();
        while (iter != myVect.end()){
            cout << (*iter) << "\n";
            iter++;
        }
    
        cout << "\n\nRead data out using array dereferencing...\n";
        for (i=0; i<myVect.size(); i++){
            cout << myVect[i] << "\n";
        }
    
        return 0;
    }
    google for "vector" and "c++" and you should find plenty.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo