Thread: Quartiles.

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    62

    Quartiles.

    Write a program to compute and print the quartiles (that is, the quarter of the numbers
    with the largest values, the next highest quarter, and so on) of a set of integers .

    This is giving me some problems. I am able of finding q2 what would be the median but how would I devide the entire set of integers into an upper and a lower half? This is the code I got so far:
    Code:
    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<algorithm>
    
    using std::cout;            using std::cin;
    using std::vector;
    
    int main()
    {
        // Ask for the numbers.
        cout << "Please enter the set of integers: \n";
    
        //Integers is a vector that will hold the set f integers while "x" is the currently processed integer.
        vector<double>;
        double x;
    
        while(cin >> x)
        {
            integers.push_back(x);
        }
    
        // Sorting the set of integers.
        sort(integers.begin(), integers.end());
    
        // Count the amount of integers given and store the result.
        const unsigned int r = integers.size();;
    
        // See if a set of numbers has been given.
        if(r == 0)
        {
            cout << "No set of integers was entered. Please try again.";
        }
    
        // Calculate Q2.
        double q2;
        q2 = r % 2 == 0 ? (integers[mid] + integers[mid -1]) / 2 : integers[mid];
    
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    62
    No suggestions?

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    I'm not too sure what quartiles are. But can you not find the [mid] of the vector, and then use that as the upper end or lower end depending on which quartile you are going for? Effectively you will cut the vector of numbers in half?

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    So for example, you would do vector[0] to vector[mid] and then you would do vector[mid] to vector[size-1]

Popular pages Recent additions subscribe to a feed