013 l2 guruh talabsi Boymatov Elbek 6-Laboratoriya ishi


Download 59.4 Kb.
Sana19.07.2020
Hajmi59.4 Kb.
#124304
Bog'liq
6-lab


013_l2 guruh talabsi Boymatov Elbek

          1. 6-Laboratoriya ishi

          2. Sonli klasslar


Topshiriq №1

Complex sinfidan foydalanib, ikkita kompleks sonlarni ayiring

#include

#include

using namespace std;

//**********COMPLEX CLASS************************

class Complex{

private:


double real,imag;

public:


Complex(){

real=imag=0;

}

Complex(double r){



real=r;

imag=0;


}

Complex(double r, double i){

real=r;

imag=i;


}

Complex(Complex &obj){

real=obj.real;

imag=obj.imag;

}

Complex add(Complex c){



Complex Add;

Add.real = real + c.real;

Add.imag = imag + c.imag;

return Add;

}

Complex sub(Complex c){



Complex Sub;

Sub.real = real - c.real;

Sub.imag = imag - c.imag;

return Sub;

}

void print(){



cout<

}

double getReal() const{



return real;

}

double getImag() const{



return imag;

}

void setReal(double re){



real = re;

}

void setImag(double im){



imag = im;

}

};



int main()

{

double real1,imag1,real2,imag2;



cout<<"Birinchi raqamning haqiqiy qismini kiriting: ";

cin>>real1;

cout<<"Birinchi raqamning mavhum qismini kiriting: ";

cin>>imag1;

Complex obj1(real1,imag1);

obj1.print();

cout<<"Ikkinchi raqamning haqiqiy qismini kiriting: ";

cin>>real2;

cout<<"Ikkinchi raqamning mavhum qismini kiriting: ";

cin>>imag2;

Complex obj2(real2,imag2);

obj2.print();

Complex c;

c = obj1.add(obj2);

cout<<"ikkita complex sonni qoshish : ("<

c= obj1.sub(obj2);

cout<

return 0;



}



          1. Topshiriq №2

Valarray sinfidan foydalanib, ikkita massivning farqini toping

#include

#include

using namespace std;

void show(valarray var, int n){

for(int i=0; i

cout<

}

}



void arrayDiff(valarray var1, valarray var2, int n)

{


int i = 0, j = 0;

while (i < n && j < n)

{

if (var1[i] < var2[j])



{

cout << var1[i]<<" ";

i++;

}


else if (var2[j] < var1[i])

{


cout << var2[j]<<" ";

j++;


}

else


{

i++;


j++;

}


}

}


int main()

{


valarray varr1(10);

valarray varr2(10);

for(int i=0; i<10; i++){

varr1[i]=rand()%15-5;

varr2[i]=rand()%15-5;

}

cout<<"Birinchi valarray: ";



show(varr1, 10);

cout<<"\nIkkinchi Valarray: ";

show(varr2, 10);

cout<<"\n\nIkkita massivning farqi: \n";

arrayDiff(varr1,varr2,10);

return 0;



}


Download 59.4 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling