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]; }



LinkBack URL
About LinkBacks


