Advertisement
simov

ООП Вежби

Mar 11th, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. /* Класи - Пример */
  2.  
  3. #include <iostream>
  4. using namespace std ;
  5. class Square {
  6.     private:
  7.         int a , b , c;
  8.     public:
  9.         Square (int aa , int bb , int cc ) {
  10.             a = aa ;
  11.             b = bb ;
  12.             c = cc ;
  13.         }
  14.     ~Square() {
  15.     }
  16.     int area () {
  17.         return 2 * (a * b + a * c + b * c );
  18.     }
  19.     int volume () {
  20.         return a * b * c ;
  21.     }
  22. };
  23. int main () {
  24.     Square object(10 , 15 , 20) ;
  25.     cout << "Area is: " << object.area () << endl ;
  26.     cout << "Volumenot e: " << object.volume () << endl ;
  27.     return 0;
  28. }
  29.  
  30. /* Класи - Задача 1 */
  31.  
  32. #include <iostream>
  33. #include <cmath>
  34. using namespace std ;
  35. class Tri {
  36.     private:
  37.         int a , b , c;
  38.     public:
  39.         Tri(int aa , int bb , int cc ) {
  40.             a = aa ;
  41.             b = bb ;
  42.             c = cc ;
  43.         }
  44.         ~Tri() {
  45.     }
  46.  
  47.     int perimetar() {
  48.         return a+b+c;
  49.     }
  50.     int ploshtina() {
  51.         float s = ( a + b + c) / 2;
  52.         return sqrt(s * ( s - a) * (s - b) * (s - c));
  53.     }
  54. };
  55. int main () {
  56.     int x,y,z;
  57.     cin >> x >> y >> z;
  58.     Tri object(x,y,z);
  59.     cout << "Perimetarot is: " << object.perimetar() << endl ;
  60.     cout << "Ploshtinata is: " << object.ploshtina() << endl ;
  61.     return 0;
  62. }
  63.  
  64. /* Класи - Задача 2 */
  65.  
  66.  
  67.  
  68. /* Класи - Задача 3 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement