#include "stdafx.h"
#include
#include
using namespace System;
using namespace std;
int main( )
{
using namespace std;
double pi = 3.14159265359;
complex c1 ( polar ( 5.0 ) ); // Default argument = 0
complex c2 ( polar ( 5.0 , pi / 6 ) );
complex c3 ( polar ( 5.0 , 13 * pi / 6 ) );
cout << "c1 = polar ( 5.0 ) = " << c1 << endl;
cout<< "c2 = polar ( 5.0 , pi / 6 ) = " << c2 << endl;
cout<<"c3 = polar (5.0, 13*pi / 6 ) = " << c3 << endl;
double absc1 = abs ( c1 );
double argc1 = arg ( c1 );
cout << "C1 moduli c1 dan quyidagilar yordamida tiklanadi: abs ( c1 ) = "
<< absc1 << endl;
cout << "C1 argumenti c1 dan quyidagilar yordamida tiklanadi:\n arg ( c1 ) = "
<< argc1 << " radians, qaysiki " << argc1 * 180 / pi
<< " darajasi." << endl;
double absc2 = abs ( c2 );
double argc2 = arg ( c2 );
cout << "C2 moduli c2 dan s2 yordamida tiklanadi: abs ( c2 ) = "
<< absc2 << endl;
cout << "C2 argumenti c2 dan quyidagilar yordamida tiklanadi:\n arg ( c2 ) = "
<< argc2 << " radianda, qaysiki " << argc2 * 180 / pi
<< " darajalar." << endl;
if ( (arg ( c2 ) <= ( arg ( c3 ) + .00000001) ) ||
(arg ( c2 ) >= ( arg ( c3 ) - .00000001) ) )
cout << " c2 & c3 komplex sonlar bir xil argumentlardan "
<< "tashkil topgan."<< endl;
else
cout << " c2 & c3 komplex sonlar bir xil argumentlardan "
<< "tashkil topmagan."<< endl;
getchar();
}
Dastur natijasi:
c1 = polar ( 5.0 ) = (5,0)
c2 = polar ( 5.0 , pi / 6 ) = (4.33013,2.5)
c3 = polar ( 5.0 , 13 * pi / 6 ) = (4.33013,2.5)
C1 moduli c1 dan quyidagilar yordamida tiklanadi: abs ( c1 ) = 5
C1 argumenti c1 dan quyidagilar yordamida tiklanadi:
arg ( c1 ) = 0 radians, qaysiki 0 darajasi.
C2 moduli c2 dan s2 yordamida tiklanadi: abs ( c2 ) = 5
C2 argumenti c2 dan quyidagilar yordamida tiklanadi:
arg ( c2 ) = 0.523599 radians, qaysiki 30 darajalar.
c2 & c3 komplex sonlar bir xil argumentlardan tashkil topgan.
comj() complex funksiyasiga misol:
Funksiya shabloni:
template
complex conj(const complex& complexNum);
Dastur matni:
#include "stdafx.h"
#include
#include
int main( )
{
using namespace std;
complex c1 ( 4.0 , 3.0 );
cout << "Komplex raqam c1 = " << c1 << endl;
double dr1 = real ( c1 );
cout << " c1 ning haqiqiy qismi bu haqiqiy ( c1 ) = "
<< dr1 << "." << endl;
double di1 = imag ( c1 );
cout << " c1 ning no'malum qismi bu imag ( c1 ) = "
<< di1 << "." << endl;
complex c2 = conj ( c1 );
cout<<"c1 ning komplex kasr qismi bu c2 = conj(c1)= "
<< c2 << endl;
double dr2 = real ( c2 );
cout << " c2 ning haqiqiy qismi bu real ( c2 ) = "
<< dr2 << "." << endl;
double di2 = imag ( c2 );
cout << " c2 ning no'malum qismi bu imag ( c2 ) = "
<< di2 << "." << endl;
complex c3 = c1 * c2;
cout<<"(c1 * conj (c1) ) ning haqiqiysi bu c1 * c2 = "
<< real( c3 ) << endl;
getwchar();
}
Dastur natijasi:
Komplex raqam c1 = (4,3)
c1 ning haqiqiy qismi bu haqiqiy ( c1 ) = 4.
c1 ning no'malum qismi bu imag ( c1 ) = 3.
c1 ning komplex kasr qismi bu c2 = conj ( c1 )= (4,-3)
c2 ning haqiqiy qismi bu real ( c2 ) = 4.
c2 ning no'malum qismi bu imag ( c2 ) = -3.
(c1 * conj (c1) ) ning haqiqiysi bu c1 * c2 = 25
imag() complex funksiyasiga misol:
Funksiya shabloni:
template
Type imag(const complex& complexNum);
Dastur matni:
#include "stdafx.h"
#include
#include
int main( )
{
using namespace std;
complex c1 ( 4.0 , 3.0 );
cout << " c1 komplex son = " << c1 << endl;
double dr1 = real ( c1 );
cout << " c1 ning haqiqiy qismi bu real ( c1 ) = "
<< dr1 << "." << endl;
double di1 = imag ( c1 );
cout << " c1 ning noma'lum qismi bu imag ( c1 ) = "
<< di1 << "." << endl;
getchar();
}
Dastur natijasi:
c1 komplex son = (4,3)
c1 ning haqiqiy qismi bu real ( c1 ) = 4.
c1 ning noma'lum qismi bu imag ( c1 ) = 3.
polar() complex funksiyasiga misol:
Funksiya shabloni:
template
complex polar(const Type& _Modulus, const Type& _Argument = 0);
Dastur matni:
#include "stdafx.h"
#include
#include
int main( )
{
using namespace std;
double pi = 3.14159265359;
complex c1 ( polar ( 5.0 ) );
// Default argument = 0
complex c2 ( polar ( 5.0 , pi / 6 ) );
complex c3 ( polar ( 5.0 , 13 * pi / 6 ) );
cout << "c1 = polar ( 5.0 ) = " << c1 << endl;
cout << "c2= polar ( 5.0 , pi / 6 ) = " << c2 << endl;
cout << "c3= polar(5.0, 13*pi / 6 ) = " << c3 << endl;
if ( (arg ( c2 ) <= ( arg ( c3 ) + .00000001) ) ||
(arg ( c2 ) >= ( arg ( c3 ) - .00000001) ) )
cout << " c2 & c3 komplex sonlar bir xil argumentlardan "<< "tashkil topgan."<< endl;
else
cout << " c2 & c3 komplex sonlar bir xil argumentlardan "<< "tashkil topmagan." << endl;
double absc2 = abs ( c2 );
double argc2 = arg ( c2 );
cout << " c2 ning moduli bu : abs ( c2 ) = "
<< absc2 << endl;
cout << " c2 argumenti bu :\n arg ( c2 ) = "
<< argc2 << " radianda, qaysiki " << argc2 * 180 / pi
<< " daraja." << endl;
getchar();
}
Dastur natijasi:
c1 = polar ( 5.0 ) = (5,0)
c2 = polar ( 5.0 , pi / 6 ) = (4.33013,2.5)
c3 = polar ( 5.0 , 13 * pi / 6 ) = (4.33013,2.5)
c2 & c3 komplex sonlar bir xil argumentlardan tashkil topgan.
c2 ning moduli bu : abs ( c2 ) = 5
c2 argumenti bu :
arg ( c2 ) = 0.523599 radianda, qaysiki 30 daraja.
Komplex sonlar uchun qayta yuklangan teng emas operatori - operator!= ga misol:
Operator shabloni:
template <class Type>
bool operator!=(
const complex& left,
const complex& right);
template <class Type>
bool operator!=(
const complex& left,
const Type& right);
template <class Type>
bool operator!=(
const Type& left,
const complex& right);
Dastur matni:
#include "stdafx.h"
#include
#include
int main( )
{
using namespace std;
double pi = 3.14159265359;
complex cl1 ( polar (3.0, pi / 6 ) );
complex cr1a ( polar (3.0, pi /6 ) );
complex cr1b ( polar (2.0, pi / 3 ) );
cout << " cl1 komplex sonning chap tarafi= " << cl1 << endl;
cout<<"cr1a komplex sonning birinchi o'ng tarafi = " <
cout<<"cr1b komplex sonning ikkinchi o'ng tarafi = " <
if ( cl1 != cr1a )
cout << " cl1 & cr1a komplex sonlar teng emas." << endl;
else
cout << " cl1 & cr1a komplex sonlar teng." <
if ( cl1 != cr1b )
cout << " cl1 & cr1b komplex sonlar teng emas."<< endl;
else
cout << " cl1 & cr1b komplex sonlar teng." << endl;
cout << endl;
complex cl2a ( 3, 4 );
complex cl2b ( 5,0 );
int cr2a =3;
int cr2b =5;
cout<<"cl2a komplex sonning birinchi chap tarafi ="<
cout<<"cr2a komplex sonning birinchi o'ng tarafi = " << cr2a << endl;
if ( cl2a != cr2a )
cout << " cl2a & cr2a komplex sonlar teng emas." << endl;
else
cout << " cl2a & cr2a komplex sonlar teng." << endl;
cout<<"cl2b komplex sonning ikkinchi chap tarafi="<
cout<<"cr2b komplex sonning ikkinchi o'ng tarafi="<
if ( cl2b != cr2b )
cout << " cl2b & cr2b komplex sonlar teng emas." << endl;
else
cout << " cl2b & cr2b komplex sonlar teng." << endl;
cout << endl;
double cl3a =3;
double cl3b =5;
complex cr3a ( 3, 4 );
complex cr3b ( 5,0 );
cout<<"cl3a komplex sonning birinchi chap tarafi="<
cout<<"cr3a komplex sonning birinchi o'ng tarafi="<
if ( cl3a != cr3a )
cout << " cl3a & cr3a komplex sonlar teng emas." << endl;
else
cout << " cl3a & cr3a komplex sonlar teng." << endl;
cout<<"cl3b komplex sonning ikkinchi chap tarafi="<
cout<<"cr3b komplex sonning ikkinchi o'ng tarafi="<
if ( cl3b != cr3b )
cout << " cl3b & cr3b komplex sonlar teng emas." << endl;
else
cout << " cl3b & cr3b komplex sonlar teng." << endl;
cout << endl;
getchar();
}
Dastur natijasi:
cl1 komplex sonning chap tarafi= (2.59808,1.5)
cr1a komplex sonning birinchi o'ng tarafi = (2.59808,1.5)
cr1b komplex sonning ikkinchi o'ng tarafi = (1,1.73205)
cl1 & cr1a komplex sonlar teng.
cl1 & cr1b komplex sonlar teng emas.
cl2a komplex sonning birinchi chap tarafi = (3,4)
cr2a komplex sonning birinchi o'ng tarafi = 3
cl2a & cr2a komplex sonlar teng emas.
cl2b komplex sonning ikkinchi chap tarafi = (5,0)
cr2b komplex sonning ikkinchi o'ng tarafi = 5
cl2b & cr2b komplex sonlar teng.
cl3a komplex sonning birinchi chap tarafi = 3
cr3a komplex sonning birinchi o'ng tarafi= (3,4)
cl3a & cr3a komplex sonlar teng emas.
cl3b komplex sonning ikkinchi chap tarafi = 5
cr3b komplex sonning ikkinchi o'ng tarafi = (5,0)
cl3b & cr3b komplex sonlar teng.
Do'stlaringiz bilan baham: |