Advertisement
heroys6

Lab 1

Oct 9th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     float xmin, xmax, x, xch, step, Y;
  8.  
  9.     int chs, N=1, i, dot, x_prov=0, chs_prov, color, skin, bg, ch_skin, n, txt_color_chs, prov=0, N_next;
  10.  
  11.     printf(".:: Table builder v1.0 ::.\n\n");
  12.  
  13.     do {
  14.     prov++;
  15.     if (prov>1) printf("Only digits! And only 1 or 2! \n");
  16.     printf("Do you want to select color skin?(1-yes, 2-no): ");
  17.     fflush(stdin);
  18.     }
  19.     while (!scanf("%d", &color) || color != 1 && color != 2);
  20.     prov=0;
  21.  
  22.     if (color==1)
  23.         {
  24.         do {
  25.         prov++;
  26.         if (prov>1) printf("Only digits! And only from 1 to 5! \n");
  27.         printf("\nDo you want make skin yourself(enter 1) or select done skin(enter 2)?\nEnter variant number: ");
  28.         fflush(stdin);
  29.         }
  30.         while (!scanf("%d", &ch_skin) || ch_skin != 1 && ch_skin != 2 && ch_skin != 3 && ch_skin != 4 && ch_skin != 5);
  31.         prov=0;
  32.         if (ch_skin==1) {
  33.                 printf("\nWellcome to Color Wizard!\n\nFirst step. Select background color:\n1.Black\n2.White\n3.Blue\n4.Bright Grey\n5.Bright Blue\nYour choice: ");
  34.                 scanf("%d", &bg);
  35.                 switch (bg)
  36.                 {
  37.                 case 1: system("color 07"); n=1; break;
  38.                 case 2: system("color FF"); n=2; break;
  39.                 case 3: system("color 17"); n=3; break;
  40.                 case 4: system("color 7F"); n=4; break;
  41.                 case 5: system("color BF"); n=5; break;
  42.                 default: system("color 07"); n=6; printf("Uncorrect answer. Default seted BLACK color"); break;
  43.             }
  44.                 printf("\nSecond step. Select text color:\n1.Black\n2.Green\n3.Red\nYour choice: ");
  45.                 scanf("%d", &txt_color_chs);
  46.  
  47.                     if (n==1)
  48.                     {
  49.                         switch (txt_color_chs)
  50.                         {
  51.                         case 1: system("color 00"); break;
  52.                         case 2: system("color 0A"); break;
  53.                         case 3: system("color 0C"); break;
  54.                         default: system("color 07"); printf("Uncorrect answer. Ddefault seted WHITE color\n"); break;
  55.                         }
  56.                     }
  57.                     else {
  58.                         if (n==2)
  59.                         {
  60.                             switch (txt_color_chs)
  61.                         {
  62.                         case 1: system("color F0"); break;
  63.                         case 2: system("color FA"); break;
  64.                         case 3: system("color FC"); break;
  65.                         default: system("color F7"); printf("Uncorrect answer. Ddefault seted WHITE color"); break;
  66.                         }
  67.                         }
  68.                         else {
  69.                             if (n==3)
  70.                             {
  71.                                 switch (txt_color_chs)
  72.                         {
  73.                         case 1: system("color 10"); break;
  74.                         case 2: system("color 1A"); break;
  75.                         case 3: system("color 1C"); break;
  76.                         default: system("color 17"); printf("Uncorrect answer. Ddefault seted WHITE color"); break;
  77.                         }
  78.                             }
  79.                             else {
  80.                                 if (n==4)
  81.                                 {
  82.                                     switch (txt_color_chs)
  83.                         {
  84.                         case 1: system("color 70"); break;
  85.                         case 2: system("color 7A"); break;
  86.                         case 3: system("color 7C"); break;
  87.                         default: system("color 77"); printf("Uncorrect answer. Ddefault seted WHITE color"); break;
  88.                         }
  89.                                 }
  90.                                 else {
  91.                                     if (n==5) {
  92.                                     switch (txt_color_chs)
  93.                         {
  94.                         case 1: system("color B0"); break;
  95.                         case 2: system("color BA"); break;
  96.                         case 3: system("color BC"); break;
  97.                         default: system("color B7"); printf("Uncorrect answer. Ddefault seted WHITE color"); break;
  98.                         }
  99.                                     }
  100.                                     else {
  101.                                         if (n==6) {
  102.                                             switch (txt_color_chs)
  103.                         {
  104.                         case 1: system("color 00"); break;
  105.                         case 2: system("color 0A"); break;
  106.                         case 3: system("color 0C"); break;
  107.                         default: system("color 07"); printf("Uncorrect answer. Ddefault seted WHITE color"); break;
  108.                         }
  109.                                         }
  110.                                     }
  111.                                 }
  112.                             }
  113.                         }
  114.                     }
  115.         }
  116.         else {
  117.             if (ch_skin==2)
  118.             {
  119.             printf("Select skin:\n\n1.Light grey\n2.Dark red\n3.Like a paper\n\nYour choice: ");
  120.             scanf("%d", &skin);
  121.                 switch (skin)
  122.                     {
  123.                 case 1: system("color 70"); break;
  124.                 case 2: system("color 0C"); break;
  125.                 case 3: system("color F0"); break;
  126.                 default: printf("None of the proposal was not selected.\nWell, program will set default author skin\n");
  127.                 system("color 1D"); break;
  128.                 }
  129.         }
  130.       }
  131.     }
  132.  
  133.     do {
  134.     x_prov=0;
  135.         do {
  136.         prov++;
  137.         if (prov>1) printf("Only digits! Try again\n");
  138.         printf("\nEnter Xmin: ");
  139.         fflush(stdin);
  140.         }
  141.         while (!scanf("%f", &xmin));
  142.         prov=0;
  143.  
  144.         do {
  145.         prov++;
  146.         if (prov>1) printf("Only digits! Try again\n");
  147.         printf("Enter Xmax: ");
  148.         fflush(stdin);
  149.         }
  150.         while (!scanf("%f", &xmax));
  151.         prov=0;
  152.  
  153.     if (!(xmin<xmax))
  154.         { printf("Xmax must be bigger then Xmin!\n");
  155.           if (xmin>xmax) {
  156.           printf("So program will swaps Xmin & Xmax...");
  157.                  xch=xmin;
  158.                  xmin=xmax;
  159.                  xmax=xch;
  160.                  printf("\n Xmin = %.1f\t\n", xmin);
  161.                  printf(" Xmax = %.1f\t", xmax);
  162.  
  163.           }
  164.           else {
  165.                 if (xmax==xmin) {
  166.                    printf("Enter again plz\n");
  167.                    x_prov++;
  168.                             }
  169.             }
  170.         }
  171.     }
  172.         while(x_prov>0);
  173.  
  174.     do {
  175.     prov++;
  176.     if (prov>1) printf("Enter only 1 or 2!");
  177.     printf("\nWhat do you prefer? Dots = 1, Steps = 2\nEnter your choice: ");
  178.     fflush(stdin);
  179.     }
  180.     while (!scanf("%d", &chs) || chs != 1 && chs != 2);
  181.     prov=0;
  182.  
  183.     if(chs==1)
  184.     {
  185.         do {
  186.             chs_prov=0;
  187.                 do {    prov++;
  188.                         if (prov>1) printf("Only digits! Try again\n");
  189.                         printf("Enter dots value: ");
  190.                         fflush(stdin);
  191.                 }
  192.                         while (!scanf("%d", &dot));
  193.                         prov=0;
  194.             if (dot==1) { printf("Table with one dot is incorrect! Try again\n"); chs_prov++; } //Work but strange: step=(xmax-xmin)/dot; }
  195.             else {
  196.                 if (dot>1) { step=(xmax-xmin)/(dot-1); }
  197.                 else {
  198.                     if (dot==0) { printf("Table without dots will be empty! Try again\n"); chs_prov++;}
  199.             }
  200.           }
  201.         }
  202.     while (chs_prov>0);
  203.     }
  204.     else
  205.     {
  206.         if(chs==2) {
  207.                     do {
  208.                     prov++;
  209.                     if (prov>1) printf("Only digits!\n");
  210.                     printf("\nEnter step value: ");
  211.                     fflush(stdin);
  212.                     }
  213.                     while (!scanf("%f", &step));
  214.                     prov=0;
  215.         }
  216.     }
  217.  
  218.                         printf(" %c",201); for (i=0; i<7; i++) {printf("%c", 205);} printf("%c", 203);     //High border
  219.                         for (i=0; i<=20; i++) {printf("%c", 205);} printf("%c", 203);
  220.                         for (i=0; i<=21; i++) {printf("%c", 205);} printf("%c\n", 187);
  221.  
  222.                         printf(" %c",186);
  223.                         printf("%6s ", "Xmin:"); printf("%c",186);   // nazv xmin
  224.                         printf("%20s ", "Xmax:"); printf("%c",186);   // nazv Xmax
  225.                         printf("%21s ", "Step:"); printf("%c\n",186); // nazv step
  226.  
  227.                         printf(" %c",204); for (i=0; i<7; i++) {printf("%c", 205);} printf("%c", 206); //First underline string
  228.                         for (i=0; i<=20; i++) {printf("%c", 205);} printf("%c", 206);
  229.                         for (i=0; i<=21; i++) {printf("%c", 205);} printf("%c\n", 185);
  230.  
  231.                         printf(" %c",186);
  232.                         printf("%6.2f ", xmin); printf("%c",186);   // xmin
  233.                         printf("%20.2f ", xmax); printf("%c",186);   // xmax
  234.                         printf("%21.2f ", step); printf("%c\n",186); // step
  235.  
  236.                         printf(" %c",204); for (i=0; i<7; i++) {printf("%c", 205);} printf("%c", 206); //Second underline string
  237.                         for (i=0; i<=20; i++) {printf("%c", 205);} printf("%c", 206);
  238.                         for (i=0; i<=21; i++) {printf("%c", 205);} printf("%c\n", 185);
  239.  
  240.                         printf(" %c",186);
  241.                         printf("%6s ", "N:"); printf("%c",186);   // N
  242.                         printf("%20s ", "X:"); printf("%c",186);   // X
  243.                         printf("%21s ", "Y:"); printf("%c\n",186); // Y
  244.  
  245.                         printf(" %c",204); for (i=0; i<7; i++) {printf("%c", 205);} printf("%c", 206); //Third underline string
  246.                         for (i=0; i<=20; i++) {printf("%c", 205);} printf("%c", 206);
  247.                         for (i=0; i<=21; i++) {printf("%c", 205);} printf("%c\n", 185);
  248.  
  249.  
  250.                         for(x=xmin; x<=xmax; x=x+step)     // MAIN CYCLE
  251.                         {
  252.                         printf(" %c",186); printf("%6i ", N);
  253.                         N++;
  254.                         printf("%c",186);                                                       // val N
  255.                         printf("%20.2f ", x); printf("%c",186);                               // val X
  256. Y=pow(x,2)-5*x+3;       printf("%21.2f ", Y); printf("%c\n",186);                           // val Y
  257.  
  258.                         printf(" %c",204); for (i=0; i<7; i++) {printf("%c", 205);} printf("%c", 206);
  259.                         for (i=0; i<=20; i++) {printf("%c", 205);} printf("%c", 206);
  260.                         for (i=0; i<=21; i++) {printf("%c", 205);} printf("%c\n", 185);// Underline string
  261.  
  262.                             if (x==xmax) {
  263.                             printf(" %c",200); for (i=0; i<7; i++) {printf("%c", 205);} printf("%c", 202);
  264.                             for (i=0; i<=20; i++) {printf("%c", 205);} printf("%c", 202);                //Last underline string
  265.                             for (i=0; i<=21; i++) {printf("%c", 205);} printf("%c\n", 188);
  266.                             }
  267.  
  268.                             if (x>xmax-step)
  269.                             {
  270.                                     if (xmax>x)
  271.                                     {
  272.                                     printf(" %c",200); for (i=0; i<7; i++) {printf("%c", 205);} printf("%c", 202);
  273.                                     for (i=0; i<=20; i++) {printf("%c", 205);} printf("%c", 202);                //Last undr prov
  274.                                     for (i=0; i<=21; i++) {printf("%c", 205);} printf("%c\n", 188);
  275.                                     }
  276.                             }
  277.  
  278.                                     if (N==10)
  279.                                     {
  280.                                         N_next=0;
  281.                                     }
  282.  
  283.                                             if (N_next%12==0)
  284.                                             {
  285.                                                 system("PAUSE"); system("cls");
  286.                                             }
  287.                                             N_next++;
  288.                         }
  289. return 0;
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement