Lớp Số Phức – Complex Number Class In C++ | Angels Fall First

Angels fall first
  • About
  • Pages

    • Home
    • About
  • Categories

    • An toàn và bảo mật thông tin
    • Các vấn đề khác
    • Cấu trúc dữ liệu và giải thuật
    • Computer Vision
    • CUDA
    • Dev tools
    • Hệ điều hành Windows
    • Hỏi đáp – thắc mắc
    • Kỹ thuật lập trình C
    • LaTeX
    • Lập trình C trên Windows
    • Lập trình Hướng đối tượng và C++
    • Music
    • Olympic Tin học ACM – Programming Contest
    • Phần mềm
    • Sách hay-Tiếng Việt
    • Simple about some things
    • Truyện cười
    • Đề cương ôn tập

Lớp số phức – Complex Number class in C++

March 6, 2012 — 4fire

#include <iostream.h> #include <iomanip.h> class ComplexN { float a; float b; public: ComplexN(){}; ComplexN(float a1, float b1):a(a1),b(b1){}; friend ostream & operator << (ostream &,const ComplexN &);

friend istream & operator >> (istream &, ComplexN &); ComplexN operator + (const ComplexN &); ComplexN operator - (const ComplexN &); ComplexN operator * (const ComplexN &); };

istream & operator >> (istream & is, ComplexN & r) { cout << “Phan thuc:”; is >> r.a; cout << “Phan ao:”; is >> r.b; return is; }

ostream & operator << (ostream & os,const ComplexN & r) { os << setprecision(2) << r.a;

if(r.b>0.0) os << ” + ” << setprecision(2) << r.b << “*i”; else os << setprecision(2) << r.b << “*i”;

return os;

}

ComplexN ComplexN::operator+(const ComplexN & r)

{

float a1 = a + r.a; float b1 = b + r.b;

return ComplexN(a1,b1);

}

ComplexN ComplexN::operator-(const ComplexN & r)

{

float a1 = a – r.a; float b1 = b – r.b;

return ComplexN(a1,b1);

}

main()

{

ComplexN z1, z2;

cin >> z1; cin >> z2; cout << “z1 = ” << z1 << endl; cout << “z2 = ” << z2 << endl; cout << “z1+z2 = ” << z1+z2 << endl;;

return 0; }

Share this:

  • Facebook
  • X
Like Loading...

Related

Posted in Lập trình Hướng đối tượng và C++. Leave a Comment »

Leave a comment Cancel reply

Δ

« Danh sách liên kết với C++ – Linked list in C++ SVD benchmark on Windows – that why Matlab is the champion » Proudly powered by WordPress
  • Links

    • 4zoom lớp đại học-Một thời đã rất xa
    • Barcelona FC site
    • Blackmore's Night
    • LiveTv.ru
    • Nightwish
    • Phần mềm mã nguồn mở
    • Rootkit
    • Secret Garden
    • Sopcast Links
    • Tàng thư viện
    • Tạp chí MSDN online
    • Tech Radar
    • The Codeplex site
    • The CodeProject site
    • The Verge
  • Archives

    • February 2015
    • January 2015
    • March 2014
    • January 2014
    • November 2013
    • May 2013
    • February 2013
    • January 2013
    • November 2012
    • September 2012
    • July 2012
    • May 2012
    • April 2012
    • March 2012
    • February 2012
    • October 2011
    • June 2010
    • March 2010
    • December 2009
    • November 2009
    • October 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • August 2007
    • June 2007
  • Misc

    • Create account
    • Log in
    • WordPress.org
    • Create a free website or blog at WordPress.com.
  • Comment
  • Reblog
  • Subscribe Subscribed
    • Angels fall first
    • Join 35 other subscribers Sign me up
    • Already have a WordPress.com account? Log in now.
    • Angels fall first
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • View post in Reader
    • Manage subscriptions
    • Collapse this bar
%d Design a site like this with WordPress.comGet started

Từ khóa » Class Số Phức C++