NIKOLAY_TETUS

Birukov

Jun 24th, 2022
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <math.h>
  4. #include <string>
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <locale.h>
  9.  
  10. using namespace std;
  11.  
  12. void print_file (char* file)
  13. {
  14.     char buff[50];
  15.     FILE *fp=fopen(file, "r");
  16.     std::string line;
  17.     while(!feof(fp))
  18.     {
  19.         fgets(buff,50,fp);
  20.         cout << buff << endl;
  21.     }
  22.     fclose(fp);
  23.  
  24. }
  25. int main(int argc, char* argv[])
  26. {
  27.     setlocale(LC_ALL,"Rus");
  28.     FILE *f1, *f2;
  29.     char file[20], str[20],file2[20];
  30.     double x,sin,cos,tg,ctg;
  31.  
  32.     if (argc > 1)
  33.         strcpy(file, argv[1]);
  34.     else
  35.     {
  36.         cout << "Введите имя файла: ";
  37.         cin >> file;
  38.     }
  39.  
  40.     if (argc > 2)
  41.         strcpy(file2, argv[2]);
  42.     else
  43.     {
  44.         printf("Введите имя конечного файла: ");
  45.         cin >> file2;
  46.     }
  47.  
  48.     cout << file << endl << file2 << endl;
  49.     return 0;
  50.  
  51.  
  52.     f1 = fopen(file, "r");
  53.     print_file(file);
  54.  
  55.     f2 = fopen(file2, "w");
  56.     fprintf(f2,"x\tsinx\tcosx\ttgx\tctgx\n");
  57.     fseek(f1,12,SEEK_SET);
  58.     while(!feof(f1))
  59.     {
  60.             fscanf(f1, "%d\t%lf\t%lf\n",&x,&sin,&cos);
  61.             fprintf(f2, "%d\t%.4lf\t%.4lf\t",x, sin,cos);
  62.             if((sin == 1 && cos == 0) || (sin == (-1) && cos == 0))
  63.             fprintf (f2,"-\t");
  64.             else fprintf(f2,"%.4lf\t",sin/cos);
  65.             if((cos == 1 && sin == 0) || (cos == (-1) && sin == 0))
  66.              fprintf (f2,"-\n");
  67.             else fprintf(f2,"%.4lf\n",cos/sin);
  68.  
  69.     }
  70.     fclose(f1);
  71.     fclose(f2);
  72.     print_file(file2);
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment