fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class tamgiac{
  4. float a,b,c;
  5. public:
  6. tamgiac(){
  7. a=b=c=0;
  8. }
  9. tamgiac(float x,float y,float z){
  10. a=x;
  11. b=y;
  12. c=z;
  13. }
  14. friend istream&operator>>(istream&x,tamgiac & y);
  15. friend ostream&operator<<(ostream&x,tamgiac y);
  16. bool operator*();
  17. bool operator==(tamgiac y);
  18. };
  19. istream&operator>>(istream&x,tamgiac & y){
  20. cout<<"canh a="; x>>y.a;
  21. cout<<"canh b="; x>>y.b;
  22. cout<<"canh c="; x>>y.c;
  23. return x;
  24. }
  25. ostream&operator<<(ostream&x,tamgiac y){
  26. cout<<"canh a="<<y.a<<endl;
  27. cout<<"canh b="<<y.b<<endl;
  28. cout<<"canh c="<<y.c<<endl;
  29. return x;
  30. }
  31. bool tamgiac::operator*(){
  32. return(a==b&&a==c&&b==c);
  33. }
  34. bool tamgiac::operator==(tamgiac y){
  35. float p1=(a+b+c)/2;
  36. float p2=(y.a+y.b+y.c)/2;
  37. float S1=sqrt(p1*(p1-a)*(p1-b)*(p1-c));
  38. float S2=sqrt(p2*(p2-y.a)*(p2-y.b)*(p2-y.c));
  39. return (S1==S2);
  40. }
  41. int main(){
  42. tamgiac A,B;
  43. cout<<"nhap thong tin tam giac A: "<<endl;
  44. cin>>A;
  45. cout<<"nhap thong tin tam giac B: "<<endl;
  46. cin>>B;
  47. cout<<"thong tin tam giac A: "<<endl;
  48. cout<<A;
  49. cout<<"thong tin tam giac B: "<<endl;
  50. cout<<B;
  51. ofstream f("tamgiacdeu.txt");
  52. if(*A){
  53. cout<<"tam giac A la tam giac deu"<<endl;
  54. f<<"tam giac A la tam giac deu"<<endl;
  55. }
  56. else{
  57. cout<<"tam giac A la tam giac thuong"<<endl;
  58. f<<"tam giac A la tam giac thuong"<<endl;
  59. }
  60. if(*B){
  61. cout<<"tam giac B la tam giac deu"<<endl;
  62. f<<"tam giac B la tam giac deu"<<endl;
  63. }
  64. else{
  65. cout<<"tam giac B la tam giac thuong"<<endl;
  66. f<<"tam giac B la tam giac thuong"<<endl;
  67. }
  68. if(A==B){
  69. cout<<"2 tam giac co dien tich bang nhau!"<<endl;
  70. f<<"2 tam giac co dien tich bang nhau!"<<endl;
  71. }
  72. else{
  73. cout<<"2 tam giac ko co dien tich bang nhau!"<<endl;
  74. f<<"2 tam giac ko co dien tich bang nhau!"<<endl;
  75. }
  76. f.close();
  77. return 0;
  78. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
nhap thong tin tam giac A: 
canh a=canh b=canh c=nhap thong tin tam giac B: 
canh a=canh b=canh c=thong tin tam giac A: 
canh a=0
canh b=0
canh c=0
thong tin tam giac B: 
canh a=0
canh b=0
canh c=0
tam giac A la tam giac deu
tam giac B la tam giac deu
2 tam giac co dien tich bang nhau!