Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct range{
- int first, second;
- void input(){cout << "Input first second: "; cin >> first >> second;}
- int check(){ return first < second ? 1 : 0; }
- void output(int in_range){cout << (in_range == 0 ? "Out off range" : "In range") << "[" << first << ";" << second <<").\n";}
- int is_in_range(int pnt){return (pnt >= first && pnt < second) ? 1 : 0;}
- static void rangePrintUnion(range ob1, range ob2);
- };
- void range::rangePrintUnion(range ob1, range ob2)
- {
- int i;
- range u;
- if (ob1.is_in_range(ob2.first) && ob1.is_in_range(ob2.second)) {
- u = ob1;
- }
- else if (ob2.is_in_range(ob1.first) && ob2.is_in_range(ob1.second))
- {
- u = ob2;
- }
- else if (ob1.is_in_range(ob2.second)) {
- u.first = ob2.first;
- u.second = ob1.second;
- }
- else if (ob1.is_in_range(ob2.first))
- {
- u.first = ob1.first;
- u.second = ob2.second;
- }
- else
- {
- u = ob2;
- for (i = ob1.first; i < ob1.second; i++) cout << i << " ";
- }
- for (i = u.first; i < u.second; i++) cout << i << " ";
- cout << endl;
- }
- void main()
- {
- int t;
- range ob1, ob2;
- ob1.input();
- ob2.input();
- if (!ob1.check()) cout << "Range [" << ob1.first << ";" << ob1.second << ") is incorrect.\n";
- if (!ob2.check()) cout << "Range [" << ob2.first << ";" << ob2.second << ") is incorrect.\n";
- cout << "input num: "; cin >> t;
- ob1.output(ob1.is_in_range(t));
- ob2.output(ob2.is_in_range(t));
- ob1.rangePrintUnion(ob1, ob2);
- cin.ignore();
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment