Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- void initialize(double & variabilityOfX, int & numberOfPoints, int & precision) {
- std::cout << "Podaj liczbe punktow: " << std::endl;
- std::cin >> numberOfPoints;
- std::cout << "Podaj zmiennosc x: " << std::endl;
- std::cin >> variabilityOfX;
- std::cout << "Podaj dokladnosc: " << std::endl;
- std::cin >> precision;
- }
- void printHeader(int precision) {
- int prec = 7;
- if (precision > prec) {
- prec = precision;
- }
- printf("|%-3s", "i");
- printf("|%*s",(-1)*(precision+2), "x");
- printf("|%*s", (-1)*(precision + 2), "sin");
- printf("|%*s", (-1)*(precision + 2), "cos");
- printf("|%*s", (-1)*(precision + 2), "tg");
- printf("|%*s", (-1)*(precision + 2), "ctg");
- printf("|%*s", (-1)*(precision + 2), "asin");
- printf("|%*s", (-1)*(precision + 2), "acos");
- printf("|%*s", (-1)*(precision + 2), "atg");
- printf("|%*s|", (-1)*(precision + 2), "actg");
- printf("%\n");
- }
- void print(int precision, int numberOfPoints, double **table) {
- for (int i = 0; i < numberOfPoints; i++) {
- printf("|%*d", -3, (int)table[i][0]);
- for (int j = 1; j < 10; j++) {
- int num = (int)(table[i][j]);
- int c = 0;
- while ((num /= 10) != 0)
- c++;
- if (std::isnan(table[i][j])) {
- printf("|%*s", precision+ 2, "chuj");
- }
- else if (std::isinf(table[i][j])) {
- printf("|%*s", precision + 2, "inf");
- }
- else if (table[i][j] < 0) {
- printf("|%.*f",precision-1-c, table[i][j]);
- }else
- printf("|%.*f",precision-c, table[i][j]);
- }
- printf("|%\n");
- }
- }
- void compute(int numberOfPoints, double **table) {
- for (int i = 0; i < numberOfPoints; i++) {
- table[i][2] = sin(table[i][1]);
- table[i][3] = cos(table[i][1]);
- table[i][4] = tan(table[i][1]);
- table[i][5] = 1.0/(tan(table[i][1]));
- table[i][6] = asin(table[i][1]);
- table[i][7] = acos(table[i][1]);
- table[i][8] = atan(table[i][1]);
- table[i][9] = 1.0/(atan(table[i][1]));
- }
- }
- int main() {
- double variabilityOfX;
- int numberOfPoints;
- int precision;
- double **table;
- initialize(variabilityOfX, numberOfPoints, precision);
- table = new double*[numberOfPoints];
- for (int i = 0; i < numberOfPoints; i++) {
- table[i] = new double[10];
- table[i][0] = i;
- table[i][1] = i*variabilityOfX;
- }
- printHeader(precision);
- compute(numberOfPoints, table);
- print(precision,numberOfPoints,table);
- getchar();
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment