Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. using namespace std;
  6. const int n = 3;
  7.  
  8. class Vector
  9. {
  10. public:
  11. int a[n];
  12. int b[n];
  13. Vector() {
  14. a[0] = 1;
  15. a[1] = 2;
  16. a[2] = 3;
  17. b[0] = 1;
  18. b[1] = 2;
  19. b[2] = 3;
  20. }
  21.  
  22. virtual void cmp() = 0;
  23.  
  24. };
  25.  
  26. class mc1: public virtual Vector
  27. {
  28. public:
  29. mc1() : Vector() {};
  30. void cmp()
  31. {
  32. int s = 0,s1=0;
  33. for (register int i = 0; i < n; i++)
  34. {
  35. s += this->a[i];
  36. s1 += this->b[i];
  37. }
  38. if (s>s1) cout << s;
  39. else cout << s1;
  40.  
  41. }
  42.  
  43. };
  44.  
  45. class mc2 : public virtual Vector
  46. {
  47. public:
  48. mc2() : Vector() {};
  49. void cmp()
  50. {
  51.  
  52. int s = 0, s1 = 0;
  53. for (register int i = 0; i < n; i++)
  54. {
  55. s += this->a[i];
  56. s1 += this->b[i];
  57. }
  58. if (abs(s)>abs(s1)) cout << s;
  59. else cout << s1;
  60.  
  61. }
  62.  
  63. };
  64.  
  65.  
  66.  
  67.  
  68.  
  69. int main()
  70. {
  71. mc1 a;
  72. mc2 c;
  73. a.cmp();
  74. system("pause");
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement