Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.25 KB | None | 0 0
  1. #include "functions.h"
  2.  
  3. const int T = 2;
  4. int N = 0;
  5. const double U1 = 12., U2 = 20., V1 = 32., V2 = 60.;
  6.  
  7. int main(int argc, char** argv){
  8.     print_zast();
  9.     int input=0, exit=0;
  10.     while(exit != 1){
  11.         printf("1. Контрольный расчет для N точек\n");
  12.         printf("2. Расчет параметра с заданной точностью\n");
  13.         printf("3. Чтение данных из файлов\n");
  14.         printf("4. Выход\n");
  15.         printf("Selection: ");
  16.         scanf("%d",&input);
  17.    
  18.         switch (input)
  19.         {
  20.             case 1: {
  21.                 printf("Input number of points:\n");
  22.                 scanf("%d", &N);
  23.                 double array_time[N], array_u_in[N], array_u_out[N];
  24.                 int i = 0;
  25.                 form_time(N, array_time, T);
  26.                 form_u_in(N, array_u_in, array_time);
  27.                 form_u_out(N, array_u_out, array_u_in, U1, U2, V1, V2);
  28.                 form_tbl(N, array_time, array_u_in, array_u_out);
  29.                 FILE *f1, *f2, *f3;
  30.                 f1=fopen("massiv_time.txt","w");
  31.                 f2=fopen("massiv_U_in.txt", "w");
  32.                 f3=fopen("massiv_U_out.txt", "w");
  33.                 for (i=0;i<N;i++){
  34.                     fprintf(f1,"%6.3f\n", array_time[i]);
  35.                     fprintf(f2,"%6.3f\n", array_u_in[i]);        
  36.                     fprintf(f3,"%6.3f\n", array_u_out[i]);
  37.                 }
  38.                 fclose(f1);
  39.                 fclose(f2);                                      
  40.                 fclose(f3);
  41.                 break;
  42.             }
  43.  
  44.             case 2: {
  45.                 printf("Calculating U in minimum\n");
  46.                 parametr_u_in_min(T);
  47.                 printf("Calculating U out minimum\n");
  48.                 parametr_u_out_min(U1, U2, V1, V2, T);
  49.                 break;
  50.             }
  51.             case 3: {
  52.                 FILE *f1, *f2, *f3;
  53.                 int i=0;
  54.                 f1=fopen("massiv_time.txt","r");
  55.                 if(f1 == NULL){
  56.                     printf("There is no massiv_time.txt file");
  57.                     break;
  58.                 }
  59.                 f2=fopen("massiv_U_in.txt", "r");
  60.                 if(f2 == NULL){
  61.                     printf("There is no massiv_U_in.txt file");
  62.                     break;
  63.                 }
  64.                 f3=fopen("massiv_U_out.txt", "r");
  65.                 if(f3 == NULL){
  66.                     printf("There is no massiv_U_out.txt file");
  67.                     break;
  68.                 }
  69.                 char tmp_time[80], tmp_u_in[80], tmp_u_out[80];
  70.                 printf("№\ttime\tU in\tU out\n");
  71.                 while(!feof(f1) && !feof(f2) && !feof(f3)){
  72.                     fgets(tmp_time, 80, f1);
  73.                     fgets(tmp_u_in, 80, f2);
  74.                     fgets(tmp_u_out, 80, f3);
  75.                     printf("%3d\t%s\t%s\t%s\n", i, strtok(tmp_time, "\n"),strtok(tmp_u_in, "\n"), strtok(tmp_u_out, "\n"));
  76.                     i++;
  77.                 }
  78.                 fclose(f1);
  79.                 fclose(f2);
  80.                 fclose(f3);
  81.                 break;
  82.             }
  83.             case 4: {
  84.                 exit = 1;
  85.                 break;
  86.             }
  87.         }
  88.     }
  89.  
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement