Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <cmath>
    #include <list>
    using namespace std;
    bool IntegralPart(double One, double Two)
    {
    return ( int(One) == int(Two) );
    }
    struct is_near
    {
    bool operator() (double One, double Two)
    {
    return (fabs(One - Two) < 5.0);
    }
    };
    int main ()
    {
    double Array[] = { 10.05, 3.70, 12.02, 10.25, 14.24, 11.47, 76.32, 82.35, 95.31, 52.95 };
    list<double> ListData(Array, Array + 8);
    ListData.sort();
    ListData.unique();
    ListData.unique (IntegralPart);
    ListData.unique (is_near());
    for (list<double> :: iterator iter = ListData.begin(); iter != ListData.end(); ++iter)
    cout << ' ' << *iter;
    cout << '\n';
    return 0;
    }
    1. 10.05 3.70 12.02 10.25
    2. 14.24 11.47 76.32 82.35
    3. 82.35 95.31 52.95
    4. 3.7 10.05 76.32 82.35
    5. None of these
Correct Option: D

In this program, We are eliminating the values by using the unique operation in the list.



Your comments will be displayed only after manual approval.