Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
#include
3.
#include
4.
using namespace std;
5.
bool same_integral_part (double first, double second)
6.
{
7.
return ( int(first) == int(second) );
8.
}
9.
struct is_near
10.
{
11.
bool operator() (double first, double second)
12.
{
13.
return (fabs(first - second) < 5.0);
14.
}
15.
};
16.
int main ()
17.
{
18.
double mydoubles[] = { 12.15, 2.72, 73.0, 12.77, 3.14, 12.77, 73.35, 72.25, 15.3, 72.25 };
19.
list mylist (mydoubles, mydoubles + 10);
20.
mylist.sort();
21.
mylist.unique();
22.
mylist.unique (same_integral_part);
23.
mylist.unique (is_near());
24.
for (list :: iterator it = mylist.begin(); it != mylist.end(); ++it)
25.
cout
Options:
A .  2.72 12.15 72.25
B .  12.15 73.0 12.77
C .  73.35
D .  None of the mentioned
Answer: Option A

In this program, We are eliminating the values by using the unique operation in the list.
Output:
$ g++ seq4.cpp
$ a.out
2.72 12.15 72.25



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers