.


:




:

































 

 

 

 


-




this, - , . , . - +, *, /, <<, >> Complex.

#include <iostream.h>// 29

#include <stdio.h>

#include <conio.h>

class Complex {

double re, im;

public:

Complex (double r=0,double i=0)//

{re=r;im=i;}

friend Complex operator+(Complex, Complex);

friend Complex operator*(Complex, Complex);

friend Complex operator/(Complex, Complex);

friend ostream & operator<<(ostream &stream, Complex ob);

friend istream & operator>>(istream &stream, Complex ob);

};

ostream &operator<<(ostream &stream, Complex ob) {

stream <<"("<< ob.re << ", " << ob.im <<")"<< '\n';

return stream;

}

istream &operator>>(istream &stream, Complex &ob){

//double a,b;

//scanf("(%lf,%lf)",&a,&b);

//ob=Complex(a,b);

stream >> ob.re >> ob.im;

return stream;

}

Complex operator+(Complex a1, Complex a2){

return Complex(a1.re+a2.re,a1.im+a2.im);

}

Complex operator*(Complex a1, Complex a2){

return Complex(a1.re*a2.re-a1.im*a2.im, a1.re*a2.im+a1.im*a2.re);

}

Complex operator/(Complex a1, Complex a2){

double r=a2.re,i=a2.im;

double tr=r*r+i*i;

return Complex((a1.re*r+a2.im*i)/tr,(a1.im*r-a1.re*i)/tr);

}

int main(){

Complex a(1.,2.),b(2.,2.),c;

c=a+b;

cout<<c<<a*b<<a/b<<endl;

cout<<"Enter complex number:";

cin>>c;

cout<<c;

while(!kbhit());

return 0;

}

:

(3,4) (-2,6) (0.75,0.25)

//Enter complex number:(5,7)<>

//(5,7)

-, friend Complex, , . , , (this ). C++ complex.h complex, , .

.

#include <iostream.h>// 29

#include <conio.h>

struct Node{ //

char info; //

int count; //

Node* nextl,*nextr; //

Node(char newinfo='a') {

info=newinfo;

nextl=nextr=0;

count=1;}

};

class Tree { //

public:

Node* root; //

Tree() { //

root=0;}

void push(Node * &wer, char dat) { //

if(wer==0){

wer = new Node;

wer->nextl=0;

wer->nextr=0;

wer->info = dat;}

else if(dat<wer->info) push(wer->nextl, dat);

else if(dat>wer->info) push(wer->nextr, dat);

else wer->count++; //root=wer;

}

void insert(char dat) { //

if (root==0) root=new Node(dat);

else push(root, dat);

}

void look(node *&wer) { //

if (wer!=0) {

look(wer->nextl);

cout<<" "<<wer->info<<" - "<<wer->count;

look(wer->nextr);

}

}

Tree operator+(char c) {

Tree temp;

insert(c);

temp.root=root;

return temp;}

Tree operator=(Tree ob2) {

root=ob2.root;

return *this;}

friend ostream &operator<<(ostream &stream,Tree ob);

};

ostream &operator<<(ostream &stream,tree ob) {

ob.look(ob.root);

return stream;}

int main(){

Tree q;

Node *n;

char c,key='a';

do {

cout << "Input a char until *: ";

cin >> c;

q.insert(c); }//

while(c!= '*');

q.look(q.root); //

cout << "Input a char:";

cin>>c;

q=q+c;

cout<<q;

while(!kbhit());

return 0;

}





:


: 2015-10-01; !; : 409 |


:

:

, ; , .
==> ...

1703 - | 1484 -


© 2015-2024 lektsii.org - -

: 0.013 .