Advertisement
Guest User

OOP_4 FriendFunctions

a guest
Aug 27th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. /*
  2. შექმენით ორი კლასი Cube და Cylinder პარამეტრიანი კონსტრუქტორებით.
  3. პირველ მათგანს ჰქონდეს
  4. ერთი ველი edge, მეორეს ჰქონდეს ორივე ველი radius და height.
  5.  
  6. დაწერეთ ფუნქცია compare, რომელსაც გადავცემთ Cube და Cylinder კლასების ობიექტებს
  7. და დაბეჭდავს ინფორმაციას იმ ფიგურის შესახებ, რომელსაც აქვს მეტი
  8. მოცულობა.
  9.  
  10. შენიშვნა: აღნიშნულ ფუნქციას უნდა შეეძლოს Cube და Cylinder კლასების დახურულ
  11. ველებზე წვდომა დამხმარე ფუნქციების გარეშე
  12. */
  13.  
  14. #include<iostream>
  15. using namespace std;
  16.  
  17. class Cylinder;
  18. class Cube{
  19.     friend void compare(Cube cube, Cylinder cylinder);
  20. private:
  21.     double edge;
  22. public:
  23.     Cube(double edge);
  24.  
  25. };
  26.  
  27. class Cylinder{
  28.     friend void compare(Cube cube, Cylinder cylinder);
  29. private:
  30.     double height;
  31.     double radius;
  32. public:
  33.     Cylinder(double height, double radius);
  34.    
  35. };
  36.  
  37. Cube::Cube(double e){
  38.     edge = e;
  39. }
  40.  
  41. Cylinder::Cylinder(double h, double r){
  42.     height = h;
  43.     radius = r;
  44. }
  45.  
  46. void compare(Cube cube, Cylinder cylinder){
  47.     double volCube = cube.edge*cube.edge;
  48.     double volCyl = 3.14*cylinder.radius*cylinder.radius*cylinder.height;
  49.  
  50.     if (volCube > volCyl){
  51.         cout << "Kubis moculobaa meti" << endl;
  52.         return;
  53.     }
  54.  
  55.     if (volCube < volCyl){
  56.         cout << "Cilindis moculobaa meti" << endl;
  57.         return;
  58.     }
  59.  
  60.     cout << "Moculobebi tolia" << endl;
  61. }
  62.  
  63. int main(){
  64.  
  65.     Cube c1(8);
  66.     Cylinder cyl1(2,2);
  67.  
  68.     compare(c1, cyl1);
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement