C++ dai hoc cong nghe[bookbooming.com]

Page 265

Chương 8. Hàm bạn, định nghĩa phép toán cho lớp

// Hàm bạn với cả 2 lớp MT và VT dùng để nhân ma trận với véc tơ friend VT tich(const MT &a, const VT &x);

Nội dung chương trình là nhập một ma trận vuông cấp n và một véc tơ cấp n, sau đó thực hiện phép nhân ma trận với véc tơ vừa nhập. #include <conio.h> #include <iostream.h> #include <math.h> class VT; class MT; class VT { private: int n; double x[20]; // Toa do cua diem public: void nhapsl(); friend void in(const VT &x); friend VT tich(const MT &a, const VT &x) ; }; class MT { private: int n; double a[20][20]; public: friend VT tich(const MT &a, const VT &x); friend void in(const MT &a); void nhapsl(); }; void VT::nhapsl() { cout << "\n Cap vec to = ";

263


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.