fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class Triangle{
  5. protected:
  6. double a,b,c;
  7. public:
  8. // static int count;
  9. Triangle(double x,double y,double z):a(x),b(y),c(z){
  10. // count++;
  11. }//cout<<"constructor Triangle"<<endl;}
  12. double perim(){return a+b+c;}
  13. void print(){cout<<"a="<<a<<" b="<<b<<" c="<<c<<endl;}
  14. void print(char ch){cout<<"a="<<a<<ch<<" b="<<b<<ch<<" c="<<c<<endl;}
  15. void print(char ch,char ch1){cout<<"a="<<a<<ch<<" b="<<b<<ch<<" c="<<c<<endl;}
  16. ~Triangle(){}//cout<<"destructor Triangle"<<endl; }
  17. };
  18. class Isosceles:public Triangle{
  19. public:
  20. Isosceles(double x,double y):Triangle(x,y,y){ }//cout<<"constructor Iso"<<endl; }
  21. using Triangle::print;
  22. void print(){cout<<"a="<<a<<" b=c="<<c<<endl; }
  23. ~Isosceles(){}//cout<<"destructor Iso"<<endl;}
  24. };
  25. class Equal: public Isosceles{
  26. public:
  27. Equal (double x): Isosceles(x,x){}
  28. using Isosceles::print;
  29. void print(){cout << "a=b=c=" << a << endl;}
  30. ~Equal(){} //destructor
  31. };
  32. //int Triangle::count=0;
  33. int main(){
  34. Triangle t(10,1,1),t1(1,2,3),t2(5,6,7);
  35. Isosceles is(2,5),is1(1,2);
  36. Equal eq(3);
  37. is.print();
  38.  
  39. eq.print();
  40. eq.print(',');
  41. cout << eq.perim() << endl;
  42. // cout<<" "<<is.count<<" "<<t1.count<<endl;
  43. t.perim();
  44. cout<<is.perim()<<endl;
  45. // cout<<Triangle::count;
  46.  
  47. }
  48.  
  49. ///Показати статичні поля int Triangle::count=0;
  50.  
  51. //Завдання 1. Створити клас рівносторонній трикутник Equal спдкоємець класу рівнобедрений трикутник
  52. //з відповідним конструктором. Перегрузити метод print() без параметрів.
  53. //Завдання 2. Створити три трикутники різних типів, викликати для них методи print з параметрами та без.
  54. // Задвання 3. Створити метод пошуку периметра, чи потрібно його перегружати в доірніх класах?
  55. //Викликати метод для об'єктів
  56. //Завдання 4. Викоритовуючи клас Equal зробити відправку задачі контесту на eolymp Рівносторонній трикутник
  57.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
a=2 b=c=5
a=b=c=3
a=3, b=3, c=3
9
12