942-22 Bekchanov Bekzod
8-Amaliy ish.
Mavzu: Sonli sinflar va ular bilan ishlash. Complex sonlar, (vallaray, slice, gslice va h.k.)
Masala sharti:
Complex sinfidan foydalanib, ikkita kompleks sonlarni ko’paytiring.
Dastur kodi:
#include
using namespace std;
class Complex {
private:
double real;
double img;
public:
Complex(double r = 0, double i = 0) {
real = r;
img = i;
}
Complex operator*(Complex const& obj) {
Complex res;
res.real = real * obj.real - img * obj.img;
res.img = real * obj.img + img * obj.real;
return res;
}
void print() {
cout << real << " + i" << img << endl;
}
};
int main() {
Complex num1(4, 5);
Complex num2(6, 7);
Complex result = num1 * num2;
cout << "Ko'paytirilgan son: ";
result.print();
return 0;
}
Natija:
Do'stlaringiz bilan baham: |