Chào các pro, xin giúp em với:
Code:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
class PTBN{
private:
float a,b,c;
public:
PTBN();
PTBN(float a1, float b1,float c1);
friend istream& operator>>( istream& is, PTBN pt1);
friend ostream& operator<<( ostream& os, PTBN pt1);
PTBN operator+(PTBN pt2);
PTBN operator-(PTBN pt2);
};
PTBN::PTBN(){
a=0;b=0;c=0;
}
PTBN::PTBN(float a1, float b1, float c1){
a=a1;b=b1;c=c1;
}
istream& operator>>(istream& is,PTBN pt1){
cout<<"\n Nhap gia tri a= ";is>>pt1.a;
cout<<"\n Nhap gia tri b= ";is>>pt1.b;
cout<<"\n Nhap gia tri c= ";is>>pt1.c;
return is;
}
ostream& operator<< (ostream& os,PTBN pt1){
os<<pt1.a<<"x + ("<<pt1.b<<"y) + ("<<pt1.c<<")"<<endl;
return os;
}
PTBN PTBN::operator+(PTBN pt2){
PTBN pt;
pt.a=this->a+pt2.a;
pt.b=this->b+pt2.b;
pt.c=this->c+pt2.c;
return pt;
}
PTBN PTBN::operator-(PTBN pt2){
PTBN pt;
pt.a=this->a-pt2.a;
pt.b=this->b-pt2.b;
pt.c=this->c-pt2.c;
return pt;
}
void main(){
PTBN a,b,Tong,Hieu;
clrscr();
cin>>a;
cin>>b;
cout<<"\n"<<a<<endl;
cout<<"\n"<<b<<endl;
Tong=a+b;
cout<<"\n Tong "<<Tong<<endl;
Hieu=a-b;
cout<<"\n Hieu "<<Hieu<<endl;
getch();
}
chạy chương trình thì kết quả như sau:

Không biết sai ở đâu, xin các pro giúp ( em nghĩ chắc là ở chỗ xuất ra, nhưng ko biết lỗi ở đâu).