Guest User

Untitled

a guest
Dec 5th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <windows.h>
  5. using namespace std;
  6. class trojkat
  7. {
  8. float a;
  9. public:
  10. trojkat(float bok_a) //konstruktor nr 1
  11. {
  12. a = bok_a;
  13. }
  14. trojkat() //konstruktor nr 2
  15. {
  16. a = 5;
  17. }
  18. //funkcje
  19. void zapisz(float wart_a)
  20. {
  21. a = wart_a;
  22. }
  23. void drukuj()
  24. {
  25. cout << "<a=" << a << ">";
  26. }
  27. float obwod()
  28. {
  29. return 3.0*a;
  30. }
  31. float pole();
  32. float wys();
  33. };
  34. float trojkat::pole()
  35. {
  36. return a*a*sqrt(3.0)/4.0;
  37. }
  38. float trojkat::wys()
  39. {
  40. return a*sqrt(3.0)/2.0;
  41. }
  42. int main()
  43. {
  44. trojkat t1;
  45. cout << "trojkat rownoboczny - podaj wymiary\n";
  46. float wart_a;
  47. cout << "Dlugosc boku: "; cin >> wart_a;
  48. if(wart_a<=0)
  49. {
  50. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12);
  51. cout<<"wroc do podstawowki, trojkat musi istniec!"<<endl;
  52. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
  53. exit(-1);
  54. }
  55. t1.zapisz(wart_a);
  56. cout<<" ";
  57. t1.drukuj();
  58. cout << endl;
  59. cout << "Pole: " << setprecision(7) <<t1.pole() << endl;
  60. cout << "Obwod: " << setprecision(7) << t1.obwod() << endl;
  61. cout << "Wysokosc: " << setprecision(7) << t1.wys() << endl;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment