fork download
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <math.h>
  4. using namespace std;
  5. struct Vector{
  6. short *x;
  7. int n; //numarul de elemente
  8. };
  9.  
  10. int getN (Vector *v){
  11. return v->n;
  12. }
  13.  
  14. void setN (Vector *v, int nr){
  15. if (nr<1) v->n=1;
  16. else v->n=nr;
  17. }
  18.  
  19. short getX (Vector *v, int pos){
  20. if ((pos>=0)&&(pos<getN(v)))
  21. return v->x[pos];
  22. cout << "Position Error" << endl;
  23. return 0;
  24. }
  25.  
  26. void setX (Vector *v, int pos, short value){
  27. if ((pos>=0)&&(pos<getN(v)))
  28. v->x[pos]=value;
  29. else cout << "Position Error" << endl;
  30. }
  31.  
  32. void initVector(Vector *v,int max){
  33. setN(v,max);
  34. short *ptr=new short[v->n];
  35. v->x=ptr;
  36. for (int i=0; i<v->n; i++)
  37. v->x[i]=0;
  38. }
  39.  
  40. void deleteVector (Vector *v){
  41. delete[] v->x;
  42. v->n=NULL;
  43. }
  44.  
  45. short SumPar (Vector *v){
  46. short sum=0;
  47. for (int i=1; i<getN(v); i+=2)
  48. sum+=getX(v,i);
  49. return sum;
  50. }
  51.  
  52. double Norma (Vector *v){
  53. short sum=0;
  54. for (int i=0; i<getN(v); i++)
  55. sum+=getX(v,i)*getX(v,i);
  56. return sqrtf(sum);
  57. }
  58.  
  59. void main(){
  60. Vector *tab;
  61. int N,num;
  62. short val;
  63.  
  64.  
  65. cout << "Dati numarul de vectori: ";
  66. cin >> N;
  67. if (N==0) return;
  68. tab = new Vector[N];
  69. for (int i=0; i<N; i++){
  70. cout << "dati numarul de elemente a vectorului " << (i+1) << ": ";
  71. cin >> num;
  72. initVector(&tab[i], num);
  73. cout << "dati elementele: ";
  74. for (int j=0; j<getN(&tab[i]); j++){
  75. cin >> val;
  76. setX(&tab[i],j,val);
  77. }
  78. }
  79.  
  80. //Afisarea vectorilor
  81. for (int i=0; i<N; i++){
  82. cout << "v" << (i+1) << ": ";
  83. for (int j=0; j<getN(&tab[i]); j++)
  84. cout << getX(&tab[i],j) << " ";
  85. cout << endl;
  86. }
  87.  
  88. //Afisarea sumelor
  89. for (int i=0; i<N; i++)
  90. cout << "\ns" << (i+1) << "=" << SumPar(&tab[i]);
  91.  
  92.  
  93. //Compararea vectorilor
  94. cout << "\ncare 2 vectori doriti sa comparati?" << endl;
  95. int v1,v2;
  96. double n1,n2;
  97. cin >> v1 >> v2;
  98. if (v1<=0||v1>N||v2<=0||v2>N)
  99. cout << "\nEroare. Nu exista astfel de vectori\n";
  100. else {
  101. n1=Norma(&tab[v1-1]);
  102. n2=Norma(&tab[v2-1]);
  103. if (n1>n2) {
  104. cout << "v" << v1 << " > v" << v2 << endl;
  105. cout << n1 << " > " << n2 << endl;
  106. }
  107. else if (n1==n2){
  108. cout << "v" << v1 << " = v" << v2 << endl;
  109. cout << n1 << " = " << n2 << endl;
  110. }
  111. else {
  112. cout << "v" << v1 << " < v" << v2 << endl;
  113. cout << n1 << " < " << n2 << endl;
  114. }
  115. }
  116.  
  117. //Stergerea tuturor vectorilor
  118. for (int i=0; i<N; i++)
  119. deleteVector(&tab[i]);
  120. getch();
  121. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
stdout
Standard output is empty