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. ~Equal(){}
  29.  
  30. };
  31. //int Triangle::count=0;
  32. int main(){
  33. Triangle t(10,1,1),t1(1,2,3),t2(5,6,7);
  34. Isosceles is(2,5),is1(1,2);
  35. Equal eq(3);
  36. is.print();
  37. is1.print(',','g');
  38. // cout<<" "<<is.count<<" "<<t1.count<<endl;
  39. t.perim();
  40. cout<<is.perim()<<endl;
  41. eq.print();
  42. eq.print(',');
  43. cout<<eq.perim() << endl;
  44. // cout<<Triangle::count;
  45.  
  46. }
  47.  
  48. ///Показати статичні поля int Triangle::count=0;
  49.  
  50. //Завдання 1. Створити клас рівносторонній трикутник Equal спдкоємець класу рівнобедрений трикутник
  51. //з відповідним конструктором. Перегрузити метод print() без параметрів.
  52. //Завдання 2. Створити три трикутники різних типів, викликати для них методи print з параметрами та без.
  53. // Задвання 3. Створити метод пошуку периметра, чи потрібно його перегружати в доірніх класах?
  54. //Викликати метод для об'єктів
  55. //Завдання 4. Викоритовуючи клас Equal зробити відправку задачі контесту на eolymp Рівносторонній трикутник
  56.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
a=2 b=c=5
a=1, b=2, c=2
12
a=3 b=c=3
a=3, b=3, c=3
9