rooq37

WiadroSinus

Dec 13th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. void initialize(double & variabilityOfX, int & numberOfPoints, int & precision) {
  5. std::cout << "Podaj liczbe punktow: " << std::endl;
  6. std::cin >> numberOfPoints;
  7. std::cout << "Podaj zmiennosc x: " << std::endl;
  8. std::cin >> variabilityOfX;
  9. std::cout << "Podaj dokladnosc: " << std::endl;
  10. std::cin >> precision;
  11. }
  12.  
  13.  
  14. void printHeader(int precision) {
  15. int prec = 7;
  16. if (precision > prec) {
  17. prec = precision;
  18. }
  19. printf("|%-3s", "i");
  20. printf("|%*s",(-1)*(precision+2), "x");
  21. printf("|%*s", (-1)*(precision + 2), "sin");
  22. printf("|%*s", (-1)*(precision + 2), "cos");
  23. printf("|%*s", (-1)*(precision + 2), "tg");
  24. printf("|%*s", (-1)*(precision + 2), "ctg");
  25. printf("|%*s", (-1)*(precision + 2), "asin");
  26. printf("|%*s", (-1)*(precision + 2), "acos");
  27. printf("|%*s", (-1)*(precision + 2), "atg");
  28. printf("|%*s|", (-1)*(precision + 2), "actg");
  29. printf("%\n");
  30. }
  31.  
  32. void print(int precision, int numberOfPoints, double **table) {
  33. for (int i = 0; i < numberOfPoints; i++) {
  34. printf("|%*d", -3, (int)table[i][0]);
  35. for (int j = 1; j < 10; j++) {
  36. int num = (int)(table[i][j]);
  37. int c = 0;
  38. while ((num /= 10) != 0)
  39. c++;
  40. if (std::isnan(table[i][j])) {
  41. printf("|%*s", precision+ 2, "chuj");
  42. }
  43. else if (std::isinf(table[i][j])) {
  44. printf("|%*s", precision + 2, "inf");
  45. }
  46. else if (table[i][j] < 0) {
  47. printf("|%.*f",precision-1-c, table[i][j]);
  48. }else
  49. printf("|%.*f",precision-c, table[i][j]);
  50. }
  51. printf("|%\n");
  52. }
  53. }
  54.  
  55. void compute(int numberOfPoints, double **table) {
  56. for (int i = 0; i < numberOfPoints; i++) {
  57. table[i][2] = sin(table[i][1]);
  58. table[i][3] = cos(table[i][1]);
  59. table[i][4] = tan(table[i][1]);
  60. table[i][5] = 1.0/(tan(table[i][1]));
  61. table[i][6] = asin(table[i][1]);
  62. table[i][7] = acos(table[i][1]);
  63. table[i][8] = atan(table[i][1]);
  64. table[i][9] = 1.0/(atan(table[i][1]));
  65. }
  66. }
  67.  
  68.  
  69. int main() {
  70. double variabilityOfX;
  71. int numberOfPoints;
  72. int precision;
  73. double **table;
  74.  
  75.  
  76. initialize(variabilityOfX, numberOfPoints, precision);
  77.  
  78. table = new double*[numberOfPoints];
  79.  
  80. for (int i = 0; i < numberOfPoints; i++) {
  81. table[i] = new double[10];
  82. table[i][0] = i;
  83. table[i][1] = i*variabilityOfX;
  84. }
  85. printHeader(precision);
  86. compute(numberOfPoints, table);
  87. print(precision,numberOfPoints,table);
  88.  
  89. getchar();
  90. getchar();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment