Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <math.h>
- #include <string>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- using namespace std;
- void print_file (char* file)
- {
- char buff[50];
- FILE *fp=fopen(file, "r");
- std::string line;
- while(!feof(fp))
- {
- fgets(buff,50,fp);
- cout << buff << endl;
- }
- fclose(fp);
- }
- int main(int argc, char* argv[])
- {
- setlocale(LC_ALL,"Rus");
- FILE *f1, *f2;
- char file[20], str[20],file2[20];
- double x,sin,cos,tg,ctg;
- if (argc > 1)
- strcpy(file, argv[1]);
- else
- {
- cout << "Введите имя файла: ";
- cin >> file;
- }
- if (argc > 2)
- strcpy(file2, argv[2]);
- else
- {
- printf("Введите имя конечного файла: ");
- cin >> file2;
- }
- cout << file << endl << file2 << endl;
- return 0;
- f1 = fopen(file, "r");
- print_file(file);
- f2 = fopen(file2, "w");
- fprintf(f2,"x\tsinx\tcosx\ttgx\tctgx\n");
- fseek(f1,12,SEEK_SET);
- while(!feof(f1))
- {
- fscanf(f1, "%d\t%lf\t%lf\n",&x,&sin,&cos);
- fprintf(f2, "%d\t%.4lf\t%.4lf\t",x, sin,cos);
- if((sin == 1 && cos == 0) || (sin == (-1) && cos == 0))
- fprintf (f2,"-\t");
- else fprintf(f2,"%.4lf\t",sin/cos);
- if((cos == 1 && sin == 0) || (cos == (-1) && sin == 0))
- fprintf (f2,"-\n");
- else fprintf(f2,"%.4lf\n",cos/sin);
- }
- fclose(f1);
- fclose(f2);
- print_file(file2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment