Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3. #include <ctime>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. struct sMatrix
  8. {
  9. int matrix[20][20];
  10. int s;
  11. int o;
  12. sMatrix(int so,int osz)
  13. {
  14. s=so;
  15. o=osz;
  16. for(int i=0;i<s;i++)
  17. for(int k=0;k<o;k++)
  18. matrix[i][k]=0;
  19. }
  20. virtual void feltolt(int a,int b);
  21. };
  22. void sMatrix::feltolt(int s,int o)
  23. {
  24. for(int i=0;i<s;i++)
  25. {
  26.  
  27.  
  28. for(int k=0;k<o;k++)
  29. {
  30. int l=rand()%8+1;
  31. matrix[i][k]=l;
  32. }
  33. }
  34.  
  35.  
  36. }
  37. void kiir(sMatrix *k)
  38. {
  39. for(int i=0;i<k->o;i++)
  40. {cout<<endl;
  41. for(int j=0;j<k->s;j++)
  42. cout<<k->matrix[i][j]<<" ";
  43. }
  44.  
  45. cout<<endl;
  46. cout<<endl;
  47. }
  48. void sum(sMatrix *a,sMatrix *b)
  49. {
  50. for(int i=0;i<a->o;i++)
  51. {cout<<endl;
  52. for(int k=0;k<a->s;k++)
  53. cout<<a->matrix[i][k]+b->matrix[i][k]<<" ";
  54. }
  55. cout<<endl<<endl;
  56. }
  57. void szorzat(sMatrix *a, sMatrix *b)
  58. {
  59. sMatrix *c;
  60. c=new sMatrix(3,3);
  61. c->feltolt(3,3);
  62.  
  63. for(int i=0;i<a->s;i++)
  64. for(int j=0;j<b->o;j++)
  65. for(int k=0;k<b->s;k++)
  66. c->matrix[i][j]=c->matrix[i][j]+a->matrix[i][k]*b->matrix[k][j];
  67. for(int i=0;i<c->s;i++)
  68. {
  69. cout<<endl;
  70. for(int k=0;k<c->o;k++)
  71. cout<<c->matrix[i][k]<<" ";
  72. }
  73.  
  74. cout<<endl;
  75. }
  76. void kivonas(sMatrix *a,sMatrix *b)
  77. {
  78. for(int i=0;i<a->o;i++)
  79. {cout<<endl;
  80. for(int k=0;k<a->s;k++)
  81. cout<<a->matrix[i][k]-b->matrix[i][k]<<" ";
  82. }
  83. cout<<endl<<endl;
  84. }
  85. void szorazataval(int x,sMatrix *a)
  86. {
  87. for(int i=0;i<a->o;i++)
  88. {cout<<endl;
  89. for(int k=0;k<a->s;k++)
  90. {
  91.  
  92. a->matrix[i][k]*=x;
  93. cout<<a->matrix[i][k]<<" ";
  94. }
  95. }
  96.  
  97. cout<<endl;
  98. }
  99. int main()
  100. {
  101. srand(time(NULL));
  102. sMatrix *a;
  103.  
  104. a=new sMatrix(3,3);
  105. a->feltolt(3,3);
  106. sMatrix *b;
  107. b=new sMatrix(3,3);
  108. b->feltolt(3,3);
  109. cout<<"A:";
  110. kiir(a);
  111. cout<<"B:";
  112. kiir(b);
  113. cout<<"A + B =";
  114.  
  115. sum(a,b);
  116. cout<<"A - B =";
  117. kivonas(a,b);
  118. cout<<"A * B =";
  119. szorzat(a,b);
  120.  
  121. cout<<endl<<"A * x ="<<endl;
  122. int tx;cout<<"x= ";cin>>tx;
  123. szorazataval(tx,a);
  124. cout<<"B * x ="<<endl;
  125. cout<<"x= ";cin>>tx;
  126. szorazataval(tx,b);
  127.  
  128.  
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement