1. Create the comparison class - funnyorder: Given two positive integers a and b
ID: 3533679 • Letter: 1
Question
1. Create the comparison class - funnyorder: Given two positive integers a
and b. Let a' be the remainder of (a divided by 10) and b' the remainder
of (b divided by 10). funnyorder returns true if a' < b'; returns false
otherwise. For example, 15 is "less" than 7 according to funnyorder.
2. print the set elements with a space between the elements
(with respect to funnyorder).
Here is an example:
input: 10 2 41 8 9 31 0
output 10 41 2 8 9
*/
#include <iostream>
#include <set>
using namespace std;
//1. define the funnyorder:
class funnyorder1{
bool operator()(int a, int b)
{
if (a <b)
return a;
}
}
class funnyorder2
{
bool operator()(int a, int b)
{
if(b < b)
return b;
}
}
int main()
{
set<int, funnyorder> A;
int in;
cout<<" Enter a sequence of positive integers (ends your sequence with 0):";
while(cin>>in)
{
if (in==0)
break;
A.insert(in);
}
//2. print the set elements
return 0;
}
Explanation / Answer
class funnyorder
{
public:
int a,a',b,b';
int function()
{
cout<<"enter value of a and b";
cin>>a>>b;
a'=a;
b'=b;
if(a'<b')
return 1;
else
return 0;
}
void print_seq()
{
int seq[10],i;
cout<<"enter sequence";
for(i=0;i<10;i++)
cin>>seq[i];
cout<<"sequence is ";
for(i=0;i<10;i++)
{
cout<<seq[i]<<" ";
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.