1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài tập về số phức

2 1,1K 6
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Bài tập về số phức
Trường học University of Science
Chuyên ngành Computer Science
Thể loại Bài tập
Thành phố Hanoi
Định dạng
Số trang 2
Dung lượng 22 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Trang 1

#include<conio.h>

class Complex

{

public:

Complex (int th=0,int a=0) //constructor

{

thuc=th;

ao=a;

}

void Print() //ham xuat so phuc

{

if(thuc==0)

{

printf("%di",ao);

}

else

{

if(ao>0)

{

printf("%d+%di",thuc,ao);

}

else if(ao<0) printf("%d%di",thuc,ao);

else printf("%d",thuc);

}

}

// dinh nghia toan tu chong

friend Complex operator*(const Complex& x,const Complex& y); friend Complex operator+(const Complex& x,const Complex& y); friend Complex operator-(const Complex& x,const Complex& y); private:

int thuc,ao;

};

//cai dat toan tu chong

Complex operator*(const Complex& x,const Complex& y)

{

Complex z(x.thuc*y.thuc-x.ao*y.ao,x.ao*y.thuc+x.thuc*y.ao); return z;

}

Complex operator+(const Complex& x,const Complex& y)

{

Complex z(x.thuc+y.thuc,x.ao+y.ao);

return z;

}

Complex operator-(const Complex& x,const Complex& y)

Trang 2

{

Complex z(x.thuc+y.thuc,-x.ao-y.ao); return z;

}

int main()

{

Complex x(0,-3),y(4,5);

x.Print();printf("\n");

y.Print();printf("\n");

Complex z;

z=x+y; //tinh tong

z.Print();printf("\n");

z=x-y; //tinh tong

z.Print();printf("\n");

z=x*y; //tinh tich

z.Print();printf("\n");

getch();

return 0;

}

Ngày đăng: 27/10/2013, 23:15

TỪ KHÓA LIÊN QUAN

w