Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include<cmath>
- #include<cstdlib>
- #include<ctime>
- namespace Patrik
- {
- class Complex{
- private:
- int x,y;
- public:
- Complex():x(1),y(1){}
- Complex(int a,int b):x(a),y(b){}
- int get_x(){
- return x;
- }
- int get_y(){
- return y;
- }
- void set_x(int a){
- x = a;
- }
- void set_y(int a){
- y = a;
- }
- float modul(){
- return sqrt(x*x+y*y);
- }
- friend bool operator==( Complex& I, Complex& II){
- return I.modul() == II.modul();
- }
- friend bool operator!=(Complex& I, Complex& II){
- return I.modul() != II.modul();
- }
- friend bool operator<=(Complex& I, Complex& II){
- return I.modul() <= II.modul();
- }
- friend bool operator>=(Complex& I, Complex& II){
- return I.modul() >= II.modul();
- }
- friend bool operator<(Complex& I, Complex& II){
- return I.modul() < II.modul();
- }
- friend bool operator>(Complex& I, Complex& II){
- return I.modul() > II.modul();
- }
- Complex& operator=(const Complex& ref){
- x = ref.x;
- y = ref.y;
- return *this;
- }
- friend ostream& operator<<(ostream& out,Complex& II){
- out << II.get_x() << " + " <<II.get_y() << "i"<<endl;
- return out;
- }
- };
- }
- namespace Juzbasic
- {
- class Complex{
- private:
- int x,y;
- public:
- Complex():x(1),y(1){}
- Complex(int a,int b):x(a),y(b){}
- int get_x(){
- return x;
- }
- int get_y(){
- return y;
- }
- void set_x(int a){
- x = a;
- }
- void set_y(int a){
- y = a;
- }
- friend bool operator==( Complex& I, Complex& II){
- return I.x == II.x && I.y == II.y;
- }
- friend bool operator!=(Complex& I, Complex& II){
- return !(I==II);
- }
- friend bool operator<(Complex& I, Complex& II){
- if(I.x == II.x){
- return I.y < II.y;
- }
- else
- return I.x < II.x;
- }
- friend bool operator>(Complex& I, Complex& II){
- if(I.x == II.x){
- return I.y > II.y;
- }
- else
- return I.x > II.x;
- }
- friend bool operator<=(Complex& I, Complex& II){
- return (I == II) || (I<II);
- }
- friend bool operator>=(Complex& I, Complex& II){
- return (I == II) || (I>II) ;
- }
- Complex& operator=(const Complex& ref){
- x = ref.x;
- y = ref.y;
- return *this;
- }
- friend ostream& operator<<(ostream& out,Complex& II){
- out << II.get_x() << " + " <<II.get_y() << "i"<<endl;
- return out;
- }
- float modul(){
- return sqrt(x*x+y*y);
- }
- };
- }
- void sort(Patrik::Complex A[]){
- for(int i=0;i<9;i++){
- for(int j=0;j<10-1-i;j++){
- if(A[j] > A[j+1]){
- Patrik::Complex temp =A[j];
- A[j] = A[j+1];
- A[j+1] = temp;
- }
- }
- }
- }
- void sort(Juzbasic::Complex A[]){
- for(int i=0;i<9;i++){
- for(int j=0;j<10-1-i;j++){
- if(A[j] > A[j+1]){
- Juzbasic::Complex temp =A[j];
- A[j] = A[j+1];
- A[j+1] = temp;
- }
- }
- }
- }
- int main(){
- srand((unsigned)time(NULL));
- Patrik::Complex a[10];
- Juzbasic::Complex b[10];
- for(int i=0;i<10;i++){
- int X =1+ rand()/(RAND_MAX/100);
- int Y =1+ rand()/(RAND_MAX/100);
- b[i].set_x(X);
- b[i].set_y(Y);
- a[i].set_x(X);
- a[i].set_y(Y);
- }
- for(int i =0;i<10;i++){
- cout <<a[i];
- }
- sort(a);
- cout<<endl;
- cout<<endl;
- cout<<endl;
- for(int i =0;i<10;i++){
- cout <<a[i];
- }
- cout<<endl;
- for(int i =0;i<10;i++){
- cout <<b[i];
- }
- sort(b);
- cout<<endl;
- cout<<endl;
- cout<<endl;
- for(int i =0;i<10;i++){
- cout <<b[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement